diff --git a/test/built-ins/GeneratorFunction/property-descriptor.js b/test/built-ins/GeneratorPrototype/constructor.js similarity index 100% rename from test/built-ins/GeneratorFunction/property-descriptor.js rename to test/built-ins/GeneratorPrototype/constructor.js diff --git a/test/built-ins/GeneratorPrototype/return/from-state-completed.js b/test/built-ins/GeneratorPrototype/return/from-state-completed.js new file mode 100644 index 0000000000000000000000000000000000000000..8497c954fa944161ce717300092834e70c23f3aa --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/from-state-completed.js @@ -0,0 +1,21 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + Resuming abruptly from a generator in the 'completed' state should honor the + abrupt completion and remain in the 'completed' state. +---*/ + +function* G() {} +var iter, result; + +iter = G(); +iter.next(); + +iter.return(33); + +result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); diff --git a/test/built-ins/GeneratorPrototype/return/from-state-executing.js b/test/built-ins/GeneratorPrototype/return/from-state-executing.js new file mode 100644 index 0000000000000000000000000000000000000000..be2517fcd6059931fec95d89e4edb5d24571e6c6 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/from-state-executing.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.3.2 +description: > + A TypeError should be thrown if the generator is resumed abruptly while + running. +---*/ + +var iter; +function* g() { + iter.return(42); +} + +iter = g(); +assert.throws(TypeError, function() { + iter.next(); +}); diff --git a/test/built-ins/GeneratorPrototype/return/from-state-suspended-start.js b/test/built-ins/GeneratorPrototype/return/from-state-suspended-start.js new file mode 100644 index 0000000000000000000000000000000000000000..8011b82c88750df3081b2b833d5ea0f04b00d973 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/from-state-suspended-start.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + Resuming abruptly from a generator in the 'suspendedStart' state should + honor the abrupt completion and trigger a transition into the 'completed' + state. +---*/ + +function* G() { + yield 1; +} +var iter = G(); +var result; + +result = iter.return(56); + +assert.sameValue(result.value, 56); +assert.sameValue(result.done, true); + +result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); diff --git a/test/built-ins/GeneratorPrototype/return/incorrect-context.js b/test/built-ins/GeneratorPrototype/return/incorrect-context.js new file mode 100644 index 0000000000000000000000000000000000000000..17328db8a216970d0115dbcfa293f1ada19e1a4b --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/incorrect-context.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the + context of `return` does not defined the [[GeneratorState]] internal slot. +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +assert.throws(TypeError, function() { GeneratorPrototype.return.call(1); }); +assert.throws(TypeError, function() { GeneratorPrototype.return.call({}); }); +assert.throws(TypeError, function() { GeneratorPrototype.return.call(function() {}); }); +assert.throws(TypeError, function() { GeneratorPrototype.return.call(g); }); +assert.throws(TypeError, function() { GeneratorPrototype.return.call(g.prototype); }); diff --git a/test/built-ins/GeneratorPrototype/return/property-descriptor.js b/test/built-ins/GeneratorPrototype/return/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..3ed7e2823a8221b4f9ee86b457a9506413727b6a --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/property-descriptor.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The GeneratorPrototype intrinsic should define a `return` property that is + non-enumerable, writable, and configurable (as per section 17). +includes: [propertyHelper.js] +es6id: 25.3.1 +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +verifyNotEnumerable(GeneratorPrototype, 'return'); +verifyWritable(GeneratorPrototype, 'return'); +verifyConfigurable(GeneratorPrototype, 'return'); diff --git a/test/built-ins/GeneratorPrototype/return/try-catch-before-try.js b/test/built-ins/GeneratorPrototype/return/try-catch-before-try.js new file mode 100644 index 0000000000000000000000000000000000000000..34a494d19964bfda519d52829fd02e99d65fbf37 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-catch-before-try.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused before a `try..catch` statement, `return` should + interrupt control flow as if a `return` statement had appeared at that + location in the function body. +---*/ + +function* g() { + yield; + try { + $ERROR('This code is unreachable (within `try` block)'); + } catch (e) { + throw e; + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +iter.next(); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue(result.value, + undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-catch-following-catch.js b/test/built-ins/GeneratorPrototype/return/try-catch-following-catch.js new file mode 100644 index 0000000000000000000000000000000000000000..2e00f0398987d2593ca5bca531510676f606dd9d --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-catch-following-catch.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused after a `try..catch` statement, `return` should + interrupt control flow as if a `return` statement had appeared at that + location in the function body. +---*/ + +var afterCatch = false; +function* g() { + try { + throw new Error(); + } catch (e) {} + afterCatch = true; + yield; + $ERROR('This code is unreachable'); +} +var iter = g(); +var result; + +result = iter.next(); + +assert.sameValue(afterCatch, true); + +result = iter.return(45); +assert.sameValue( + result.value, 45, 'Result `value` following `return`' +); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-catch-within-catch.js b/test/built-ins/GeneratorPrototype/return/try-catch-within-catch.js new file mode 100644 index 0000000000000000000000000000000000000000..4c3648a5eea6b0d8cdddc0329d277036b9505b6e --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-catch-within-catch.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within the `catch` block of a `try..catch` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. +---*/ + +var inCatch = false; +function* g() { + try { + throw new Error(); + } catch (e) { + inCatch = true; + yield; + $ERROR('This code is unreachable (within `catch` block)'); + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +result = iter.next(); + +assert.sameValue(inCatch, true); + +result = iter.return(45); +assert.sameValue( + result.value, 45, 'Result `value` following `return`' +); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-catch-within-try.js b/test/built-ins/GeneratorPrototype/return/try-catch-within-try.js new file mode 100644 index 0000000000000000000000000000000000000000..646785ee9764ed0874192d21a61f6e5d6dd4e903 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-catch-within-try.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within the `try` block of a `try..catch` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. +---*/ + +var inTry = false; +function* g() { + try { + inTry = true; + yield; + $ERROR('This code is unreachable (within `try` block)'); + } catch (e) { + throw e; + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +result = iter.next(); + +assert.sameValue(inTry, true); + +result = iter.return(44); +assert.sameValue(result.value, 44, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-before-try.js b/test/built-ins/GeneratorPrototype/return/try-finally-before-try.js new file mode 100644 index 0000000000000000000000000000000000000000..9da2b4a1d4c836e597c60cdc8e7744f17dda21fc --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-before-try.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused before a `try..finally` statement, `return` + should interrupt control flow as if a `return` statement had appeared at + that location in the function body. +---*/ + +function* g() { + yield; + try { + $ERROR('This code is unreachable (within `try` block)'); + } finally { + $ERROR('This code is unreachable (within `finally` block)'); + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +iter.next(); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-following-finally.js b/test/built-ins/GeneratorPrototype/return/try-finally-following-finally.js new file mode 100644 index 0000000000000000000000000000000000000000..253fc14ef27e8da2c7b45ebb0194c7e5dbbcc1cd --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-following-finally.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused after a `try..finally` statement, `return` + should interrupt control flow as if a `return` statement had appeared at + that location in the function body. +---*/ + +var afterFinally = false; +function* g() { + try { + } finally {} + afterFinally = true; + yield; +} +var iter = g(); +var result; + +iter.next(); + +assert.sameValue(afterFinally, true); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when done' +); +assert.sameValue(result.done, true, 'Result `done` flag is `true` when done'); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-catch.js b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-catch.js new file mode 100644 index 0000000000000000000000000000000000000000..96baefa61668b6fc165bc4b1673d075f7ed242fd --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-catch.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `catch` block that is declared within a + `try` block of a `try..catch` statement, `return` should interrupt control + flow as if a `return` statement had appeared at that location in the + function body. +---*/ + +var inCatch = false; +var inFinally = false; +function* g() { + try { + try { + throw new Error(); + } catch (e) { + inCatch = true; + yield; + $ERROR('This code is unreachable (within `catch` block)'); + } + $ERROR('This code is unreachable (following nested `try` statement)'); + } finally { + inFinally = true; + } + $ERROR('This code is unreachable (following outer `try` statement)'); +} +var iter = g(); +var result; + +result = iter.next(); + +assert.sameValue(inCatch, true, '`catch` code patch executed'); +assert.sameValue(inFinally, false, '`finally` code path not executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when compelete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-finally.js b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-finally.js new file mode 100644 index 0000000000000000000000000000000000000000..b145c8b70a731025af7d868071b5ebdfcafcf7d1 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-finally.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `finally` block of a `try..catch` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. +---*/ + +var inFinally = false; +function* g() { + try { + throw new Error(); + try { + } catch (e) {} + } finally { + inFinally = true; + yield; + $ERROR('This code is unreachable (within `finally` block)'); + } + $ERROR('This code is unreachable (following outer `try` statement)'); +} +var iter = g(); +var result; + +result = iter.next(); + +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-inner-try.js b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-inner-try.js new file mode 100644 index 0000000000000000000000000000000000000000..99a3e5ab370c4be553d5412b66e07d85a7ddcb0b --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-inner-try.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `try` block that is declared within a + `try` block of a `try..catch` statement, `return` should interrupt control + flow as if a `return` statement had appeared at that location in the + function body. +---*/ + +var inTry = false; +var inFinally = false; +function* g() { + try { + try { + inTry = true; + yield; + $ERROR('This code is unreachable (within nested `try` block)'); + } catch (e) { + throw e; + } + $ERROR('This code is unreachable (following nested `try` statement)'); + } finally { + inFinally = true; + } + $ERROR('This code is unreachable (following outer `try` statement)'); +} +var iter = g(); +var exception = new Error(); +var result; + +iter.next(); + +assert.sameValue(inTry, true, 'Nested `try` code patch executed'); +assert.sameValue(inFinally, false, '`finally` code path not executed'); + +result = iter.return(45); + +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-after-nested.js b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-after-nested.js new file mode 100644 index 0000000000000000000000000000000000000000..15d4fa1f240670c0de63034fa05d523ad1f2fd1c --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-after-nested.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `try` block of a `try..catch` statement + and following a nested `try..catch` statment, `return` should interrupt + control flow as if a `return` statement had appeared at that location in + the function body. +---*/ + +var inCatch = false; +var inFinally = false; +function* g() { + try { + try { + throw new Error(); + } catch (e) { + inCatch = true; + } + } finally { + inFinally = true; + } + yield; + $ERROR('This code is unreachable'); +} +var iter = g(); +var result; + + iter.next(); + +assert.sameValue(inCatch, true, '`catch` code path executed'); +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested.js b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested.js new file mode 100644 index 0000000000000000000000000000000000000000..5e4b87999c859a286440b0e1c8707697dbb738b1 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-nested-try-catch-within-outer-try-before-nested.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `try` block of a `try..catch` statement + and before a nested `try..catch` statement, `return` should interrupt + control flow as if a `return` statement had appeared at that location in + the function body. +---*/ + +var inTry = false; +var inFinally = false; +function* g() { + try { + inTry = true; + yield; + try { + $ERROR('This code is unreachable (within nested `try` block)'); + } catch (e) { + throw e; + } + $ERROR('This code is unreacahable (following nested `try` statement)'); + } finally { + inFinally = true; + } + $ERROR('This codeis unreachable (following outer `try` statement)'); +} +var iter = g(); +var result; + +iter.next(); + +assert.sameValue(inTry, true, '`try` code path executed'); +assert.sameValue(inFinally, false, '`finally` code path not executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-within-finally.js b/test/built-ins/GeneratorPrototype/return/try-finally-within-finally.js new file mode 100644 index 0000000000000000000000000000000000000000..ae0b022c58d9dcbd00b3e83c2f32794da9de9b8f --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-within-finally.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within the `finally` block of a `try..finally` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. +---*/ + +var inFinally = true; +function* g() { + try { + } finally { + inFinally = true; + yield; + $ERROR('This code is unreachable (within `finally` block)'); + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +iter.next(); + +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/return/try-finally-within-try.js b/test/built-ins/GeneratorPrototype/return/try-finally-within-try.js new file mode 100644 index 0000000000000000000000000000000000000000..6a098be79d0c7643ddb723568a509310de012ac5 --- /dev/null +++ b/test/built-ins/GeneratorPrototype/return/try-finally-within-try.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.3 +description: > + When a generator is paused within a `try` block of a `try..finally` + statement, `return` should interrupt control flow as if a `return` + statement had appeared at that location in the function body. +---*/ + +var inTry = false; +var inFinally = false; +function* g() { + try { + inTry = true; + yield; + $ERROR('This code is unreachable (within `try` block)'); + } finally { + inFinally = true; + } + $ERROR('This code is unreachable (following `try` statement)'); +} +var iter = g(); +var result; + +iter.next(); + +assert.sameValue(inTry, true, '`try` block code path executed'); +assert.sameValue(inFinally, false, '`finally` code path not executed'); + +result = iter.return(45); +assert.sameValue(result.value, 45, 'Result `value` following `return`'); +assert.sameValue(result.done, true, 'Result `done` flag following `return`'); +assert.sameValue(inFinally, true, '`finally` code path executed'); + +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Result `value` is undefined when complete' +); +assert.sameValue( + result.done, true, 'Result `done` flag is `true` when complete' +); diff --git a/test/built-ins/GeneratorPrototype/throw/from-state-completed.js b/test/built-ins/GeneratorPrototype/throw/from-state-completed.js index 2054954b4f0840e95e998920db41289984c05a80..b838f9be90fa05b350c65b8a15ea1679449b16eb 100644 --- a/test/built-ins/GeneratorPrototype/throw/from-state-completed.js +++ b/test/built-ins/GeneratorPrototype/throw/from-state-completed.js @@ -3,8 +3,8 @@ /*--- es6id: 25.3.1.4 description: > - Resuming abuptly from a generator in the 'completed' state should honor the - abrupt completion and remain in the 'completed' state. + Resuming abruptly from a generator in the 'completed' state should honor + the abrupt completion and remain in the 'completed' state. ---*/ function E() {} diff --git a/test/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js b/test/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js index 0f42aad8f9f34e84da76f0a7b823ae088b7bf123..336b3b7031fbdb750e883e4eb55d0757251b35c9 100644 --- a/test/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js +++ b/test/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js @@ -3,7 +3,7 @@ /*--- es6id: 25.3.1.4 description: > - Resuming abuptly from a generator in the 'suspendedStart' state should + Resuming abruptly from a generator in the 'suspendedStart' state should honor the abrupt completion and trigger a transition into the 'completed' state. ---*/ diff --git a/test/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js b/test/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js index d000b99b8c8c602de07727124093c98cf26b797e..5da206774c57631bebc313d061ff0c7c5e29aeb0 100644 --- a/test/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js +++ b/test/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js @@ -3,23 +3,24 @@ /*--- es6id: 25.3.1.4 description: > - When a generator is puased after a `try..catch` statement, `throw` should + When a generator is paused after a `try..catch` statement, `throw` should interrupt control flow as if a `throw` statement had appeared at that location in the function body. ---*/ +var obj = {}; function* g() { yield 1; try { yield 2; + throw obj; } catch (e) { yield e; } yield 3; } -var iter, result, exception; +var iter, result; -exception = new Test262Error(); iter = g(); result = iter.next(); assert.sameValue(result.value, 1, 'First result `value`'); @@ -29,9 +30,14 @@ result = iter.next(); assert.sameValue(result.value, 2, 'Second result `value`'); assert.sameValue(result.done, false, 'Second result `done` flag'); -result = iter.throw(exception); -assert.sameValue(result.value, exception, 'Third result `value`'); +result = iter.next(); +assert.sameValue(result.value, obj, 'Third result `value`'); assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 3, 'Fourth result `value`'); +assert.sameValue(result.done, false, 'Fourth result `done` flag'); + assert.throws(Test262Error, function() { iter.throw(new Test262Error()); }); result = iter.next(); diff --git a/test/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js b/test/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js index 7db1bbca3a31aa2f2cc0b5e70069a5bf45a5e31e..0c7c06101943cba69dcd0245145432706bc9aae8 100644 --- a/test/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js +++ b/test/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js @@ -16,6 +16,7 @@ function* g() { yield 3; } yield 4; + $ERROR('This code is unreachable'); } var iter = g(); var result; @@ -28,10 +29,14 @@ result = iter.next(); assert.sameValue(result.value, 2, 'Second result `value`'); assert.sameValue(result.done, false, 'Second result `done` flag'); -result = iter.throw(new Error()); +result = iter.next(); assert.sameValue(result.value, 3, 'Third result `value`'); assert.sameValue(result.done, false, 'Third result `done` flag'); +result = iter.next(); +assert.sameValue(result.value, 4, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + assert.throws(Test262Error, function() { iter.throw(new Test262Error()); }); result = iter.next(); diff --git a/test/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js b/test/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js index d01910e08bd5efa8257a29d698686b3fd95805db..aaee09693052f823b8b36f41f1337b729d1021c8 100644 --- a/test/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js +++ b/test/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js @@ -26,8 +26,6 @@ function* g() { var iter = g(); var result; -iter = g(); - result = iter.next(); assert.sameValue(result.value, 1, 'First result `value`'); assert.sameValue(result.done, false, 'First result `done` flag');