diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/GeneratorPrototype/throw')
24 files changed, 1301 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/browser.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/browser.js diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-completed.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-completed.js new file mode 100644 index 0000000000..1397438454 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-completed.js @@ -0,0 +1,28 @@ +// 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.4 +description: > + Resuming abruptly from a generator in the 'completed' state should honor + the abrupt completion and remain in the 'completed' state. +features: [generators] +---*/ + +function E() {} + +function* G() {} +var iter; + +iter = G(); +iter.next(); + +assert.throws(E, function() { + iter.throw(new E()); +}); + +var result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-executing.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-executing.js new file mode 100644 index 0000000000..ac7685409e --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-executing.js @@ -0,0 +1,54 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generatorvalidate +description: > + A TypeError should be thrown if the generator is in the "executing" state, + and the generator should be marked as "completed" +info: | + 25.3.3.1 GeneratorStart + + [...] + 4. Set the code evaluation state of genContext such that when evaluation is + resumed for that execution context the following steps will be performed: + a. Let result be the result of evaluating generatorBody. + b. Assert: If we return here, the generator either threw an exception or + performed either an implicit or explicit return. + c. Remove genContext from the execution context stack and restore the + execution context that is at the top of the execution context stack as + the running execution context. + d. Set generator.[[GeneratorState]] to "completed". + [...] + + 25.3.3.4 GeneratorResumeAbrupt + + 1. Let state be ? GeneratorValidate(generator). + + 25.3.3.2 GeneratorValidate + + 1. If Type(generator) is not Object, throw a TypeError exception. + 2. If generator does not have a [[GeneratorState]] internal slot, throw a + TypeError exception. + 3. Assert: generator also has a [[GeneratorContext]] internal slot. + 4. Let state be generator.[[GeneratorState]]. + 5. If state is "executing", throw a TypeError exception. +features: [generators] +---*/ + +var iter, result; +function* g() { + iter.throw(42); +} + +iter = g(); +assert.throws(TypeError, function() { + iter.next(); +}); + +result = iter.next(); + +assert.sameValue(typeof result, 'object'); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js new file mode 100644 index 0000000000..cadfc63eaf --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/from-state-suspended-start.js @@ -0,0 +1,30 @@ +// 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.4 +description: > + Resuming abruptly from a generator in the 'suspendedStart' state should + honor the abrupt completion and trigger a transition into the 'completed' + state. +features: [generators] +---*/ + +function E() {} + +function* G() { + yield 1; + yield 2; +} +var iter; + +iter = G(); +assert.throws(E, function() { + iter.throw(new E()); +}); + +var result = iter.next(); + +assert.sameValue(result.value, undefined, 'Result `value`'); +assert.sameValue(result.done, true, 'Result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/length.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/length.js new file mode 100644 index 0000000000..75c2f6b2a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/length.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 25.3.1.4 +description: > + Generator.prototype.throw.length is 1. +info: | + Generator.prototype.throw ( exception ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +assert.sameValue(GeneratorPrototype.throw.length, 1); + +verifyNotEnumerable(GeneratorPrototype.throw, "length"); +verifyNotWritable(GeneratorPrototype.throw, "length"); +verifyConfigurable(GeneratorPrototype.throw, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/name.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/name.js new file mode 100644 index 0000000000..d167bbc1cc --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/name.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 25.3.1.4 +description: > + Generator.prototype.throw.name is "throw". +info: | + Generator.prototype.throw ( exception ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [generators] +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +assert.sameValue(GeneratorPrototype.throw.name, "throw"); + +verifyNotEnumerable(GeneratorPrototype.throw, "name"); +verifyNotWritable(GeneratorPrototype.throw, "name"); +verifyConfigurable(GeneratorPrototype.throw, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/not-a-constructor.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/not-a-constructor.js new file mode 100644 index 0000000000..d8d39a4db5 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Object.getPrototypeOf((function* g() {}).prototype).throw does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, generators, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Object.getPrototypeOf((function* g() {}).prototype).throw), + false, + 'isConstructor(Object.getPrototypeOf((function* g() {}).prototype).throw) must return false' +); + +assert.throws(TypeError, () => { + function* g() {} let expected = new Test262Error(); let iterator = g();try {new iterator.throw(expected);} catch (e) {if (e !== expected) {throw e;}} +}, '`function* g() {} let expected = new Test262Error(); let iterator = g();try {new iterator.throw(expected);} catch (e) {if (e !== expected) {throw e;}}` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/property-descriptor.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/property-descriptor.js new file mode 100644 index 0000000000..e67b04d033 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/property-descriptor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 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 `throw` property that is + non-enumerable, writable, and configurable (as per section 17). +includes: [propertyHelper.js] +es6id: 25.3.1 +features: [generators] +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +verifyNotEnumerable(GeneratorPrototype, 'throw'); +verifyWritable(GeneratorPrototype, 'throw'); +verifyConfigurable(GeneratorPrototype, 'throw'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/shell.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-generator.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-generator.js new file mode 100644 index 0000000000..cf6d223323 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-generator.js @@ -0,0 +1,87 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator.prototype.throw +description: > + A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the + context of `throw` does not define the [[GeneratorState]] internal slot. +info: | + [...] + 3. Return ? GeneratorResumeAbrupt(g, C). + + 25.3.3.4 GeneratorResumeAbrupt + + 1. Let state be ? GeneratorValidate(generator). + + 25.3.3.2 GeneratorValidate + + [...] + 2. If generator does not have a [[GeneratorState]] internal slot, throw a + TypeError exception. +features: [generators] +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call({}); + }, + 'ordinary object (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call({}, 1); + }, + 'ordinary object (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(function() {}); + }, + 'function object (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(function() {}, 1); + }, + 'function object (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(g); + }, + 'generator function object (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(g, 1); + }, + 'generator function object (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(g.prototype); + }, + 'generator function prototype object (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(g.prototype, 1); + }, + 'generator function prototype object (with value)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-object.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-object.js new file mode 100644 index 0000000000..9a460c28f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/this-val-not-object.js @@ -0,0 +1,116 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator.prototype.throw +description: > + A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the "this" + value of `throw` is not an object. +info: | + [...] + 3. Return ? GeneratorResumeAbrupt(g, C). + + 25.3.3.4 GeneratorResumeAbrupt + + 1. Let state be ? GeneratorValidate(generator). + + 25.3.3.2 GeneratorValidate + + 1. If Type(generator) is not Object, throw a TypeError exception. +features: [generators, Symbol] +---*/ + +function* g() {} +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; +var symbol = Symbol(); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(undefined); + }, + 'undefined (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(undefined, 1); + }, + 'undefined (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(null); + }, + 'null (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(null, 1); + }, + 'null (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(true); + }, + 'boolean (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(true, 1); + }, + 'boolean (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call('s'); + }, + 'string (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call('s', 1); + }, + 'string (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(1); + }, + 'number (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(1, 1); + }, + 'number (with value)' +); + +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(symbol); + }, + 'symbol (without value)' +); +assert.throws( + TypeError, + function() { + GeneratorPrototype.throw.call(symbol, 1); + }, + 'symbol (with value)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-before-try.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-before-try.js new file mode 100644 index 0000000000..743e7674da --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-before-try.js @@ -0,0 +1,56 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused before a `try..catch` statement, `throw` should + interrupt control flow as if a `throw` statement had appeared at that + location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + unreachable += 1; + try { + yield 2; + } catch (e) { + yield e; + } + yield 3; +} +var iter, result; + +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (paused at yield)' +); + +assert.throws(Test262Error, function() { + iter.throw(new Test262Error()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js new file mode 100644 index 0000000000..eb28117fbc --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-following-catch.js @@ -0,0 +1,66 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + 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. +features: [generators] +---*/ + +var obj = {}; +var unreachable = 0; + +function* g() { + yield 1; + try { + yield 2; + throw obj; + } catch (e) { + yield e; + } + yield 3; + unreachable += 1; +} +var iter, result; + +iter = g(); +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +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()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-catch.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-catch.js new file mode 100644 index 0000000000..5e862585e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-catch.js @@ -0,0 +1,63 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within the `catch` block of a `try..catch` + statement, `throw` should interrupt control flow as if a `throw` statement + had appeared at that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + try { + yield 2; + throw exception; + } catch (e) { + yield e; + unreachable += 1; + } + yield 3; +} +var iter, result, exception; + +exception = new Test262Error(); +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, exception, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +assert.throws(Test262Error, function() { + iter.throw(new Test262Error()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-try.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-try.js new file mode 100644 index 0000000000..b945ef4893 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-catch-within-try.js @@ -0,0 +1,66 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within the `try` block of a `try..catch` + statement, `throw` should interrupt control flow as if a `throw` statement + had appeared at that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; +function* g() { + yield 1; + try { + yield 2; + unreachable += 1; + } catch (e) { + yield e; + } + yield 3; +} +var iter, result, exception; + +exception = new Test262Error(); +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +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`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +result = iter.next(); +assert.sameValue(result.value, 3, 'Fourth result `done` flag'); +assert.sameValue(result.done, false, 'Fourth result `value`'); +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `catch`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-before-try.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-before-try.js new file mode 100644 index 0000000000..108e7df752 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-before-try.js @@ -0,0 +1,58 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused before a `try..finally` statement, `throw` + should interrupt control flow as if a `throw` statement had appeared at + that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + unreachable += 1; + try { + yield 2; + } finally { + yield 3; + } + yield 4; +} +var iter, result; + +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue( + result.done, false, 'First result `done` flag' +); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (paused at yield)' +); + +assert.throws(Test262Error, function() { + iter.throw(new Test262Error()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js new file mode 100644 index 0000000000..0ef6f1a91b --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-following-finally.js @@ -0,0 +1,64 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused after a `try..finally` statement, `throw` should + interrupt control flow as if a `throw` statement had appeared at that + location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + try { + yield 2; + } finally { + yield 3; + } + yield 4; + unreachable += 1; +} +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +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()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-catch.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-catch.js new file mode 100644 index 0000000000..d091c927f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-catch.js @@ -0,0 +1,72 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `catch` block that is declared within a + `try` block of a `try..catch` statement, `throw` should interrupt control + flow as if a `throw` statement had appeared at that location in the + function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + try { + yield 1; + try { + yield 2; + throw exception; + } catch (e) { + yield e; + unreachable += 1; + } + yield 3; + } finally { + yield 4; + } + yield 5; +} +var exception = new Error(); +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, exception, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iter.throw(new Test262Error()); +assert.sameValue(result.value, 4, 'Fourth result `value`'); +assert.sameValue(result.done, false, 'Fourth result `done` flag'); + +assert.throws(Test262Error, function() { + iter.next(); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-finally.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-finally.js new file mode 100644 index 0000000000..caca477bd3 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-finally.js @@ -0,0 +1,63 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `finally` block of a `try..catch` + statement, `throw` should interrupt control flow as if a `throw` statement + had appeared at that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + try { + yield 1; + throw new Error(); + try { + yield 2; + } catch (e) { + yield e; + } + yield 3; + } finally { + yield 4; + unreachable += 1; + } + unreachable += 1; + yield 5; +} +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 4, 'Second result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +assert.throws(Test262Error, function() { + iter.throw(new Test262Error()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-inner-try.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-inner-try.js new file mode 100644 index 0000000000..e9ed6d31a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-inner-try.js @@ -0,0 +1,74 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `try` block that is declared within a + `try` block of a `try..catch` statement, `throw` should interrupt control + flow as if a `throw` statement had appeared at that location in the + function body. +features: [generators] +---*/ + +var unreachable = 0; +function* g() { + try { + yield 1; + try { + yield 2; + unreachable += 1; + } catch (e) { + yield e; + } + yield 3; + } finally { + yield 4; + } + yield 5; +} +var iter = g(); +var exception = new Error(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result value'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +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`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +result = iter.next(); +assert.sameValue(result.value, 3, 'Fourth result `value'); +assert.sameValue(result.done, false, 'Fourth result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 4, 'Fifth result `value`'); +assert.sameValue(result.done, false, 'Fifth result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 5, 'Sixth result `value`'); +assert.sameValue(result.done, false, 'Sixth result `done` flag'); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-after-nested.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-after-nested.js new file mode 100644 index 0000000000..5427e443d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-after-nested.js @@ -0,0 +1,76 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `try` block of a `try..catch` statement + and following a nested `try..catch` statment, `throw` should interrupt + control flow as if a `throw` statement had appeared at that location in the + function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + try { + yield 1; + try { + yield 2; + throw exception; + } catch (e) { + yield e; + } + yield 3; + unreachable += 1; + } finally { + yield 4; + } + yield 5; +} +var exception = new Error(); +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, exception, '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'); + +result = iter.throw(new Test262Error()); +assert.sameValue(result.value, 4, 'Fifth result `value`'); +assert.sameValue(result.done, false, 'Fifth result `done` flag'); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +assert.throws(Test262Error, function() { + iter.next(); +}); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js new file mode 100644 index 0000000000..9bb560cdd2 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-nested-try-catch-within-outer-try-before-nested.js @@ -0,0 +1,62 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `try` block of a `try..catch` statement + and before a nested `try..catch` statement, `throw` should interrupt + control flow as if a `throw` statement had appeared at that location in the + function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + try { + yield 1; + unreachable += 1; + try { + yield 2; + } catch (e) { + yield e; + } + yield 3; + } finally { + yield 4; + } + yield 5; +} +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.throw(new Test262Error()); +assert.sameValue(result.value, 4, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +assert.throws(Test262Error, function() { + iter.next(); +}); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-finally.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-finally.js new file mode 100644 index 0000000000..88d1f310e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-finally.js @@ -0,0 +1,60 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within the `finally` block of a `try..finally` + statement, `throw` should interrupt control flow as if a `throw` statement + had appeared at that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + try { + yield 2; + } finally { + yield 3; + unreachable += 1; + } + yield 4; +} +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 3, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +assert.throws(Test262Error, function() { + iter.throw(new Test262Error()); +}); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-try.js b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-try.js new file mode 100644 index 0000000000..aeae83a585 --- /dev/null +++ b/js/src/tests/test262/built-ins/GeneratorPrototype/throw/try-finally-within-try.js @@ -0,0 +1,60 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.3.1.4 +description: > + When a generator is paused within a `try` block of a `try..finally` + statement, `throw` should interrupt control flow as if a `throw` statement + had appeared at that location in the function body. +features: [generators] +---*/ + +var unreachable = 0; + +function* g() { + yield 1; + try { + yield 2; + unreachable += 1; + } finally { + yield 3; + } + yield 4; +} +var iter = g(); +var result; + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.throw(new Test262Error()); +assert.sameValue(result.value, 3, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +assert.sameValue( + unreachable, + 0, + 'statement following `yield` not executed (following `throw`)' +); + +assert.throws(Test262Error, function() { + iter.next(); +}); + +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'); +assert.sameValue( + unreachable, 0, 'statement following `yield` not executed (once "completed")' +); + +iter.next(); + +reportCompare(0, 0); |