diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/generators')
298 files changed, 16564 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-fn.js b/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-fn.js new file mode 100644 index 0000000000..c6c0f9dd19 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-fn.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +es6id: 9.2.12 +description: > + Arguments object is created even when the body contains a lexically-scoped + binding named "arguments" +info: | + [...] + 19. Else if "arguments" is an element of parameterNames, then + a. Let argumentsObjectNeeded be false. + 20. Else if hasParameterExpressions is false, then + a. If "arguments" is an element of functionNames or if "arguments" is an + element of lexicalNames, then + i. Let argumentsObjectNeeded be false. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var args; + +var g = function* (x = args = arguments) { + function arguments() {} +}; + +g().next(); + +assert.sameValue(typeof args, 'object'); +assert.sameValue(args.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-lex.js b/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-lex.js new file mode 100644 index 0000000000..79117a7bae --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/arguments-with-arguments-lex.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +es6id: 9.2.12 +description: > + Arguments object is created even when the body contains a function named + "arguments" +info: | + [...] + 19. Else if "arguments" is an element of parameterNames, then + a. Let argumentsObjectNeeded be false. + 20. Else if hasParameterExpressions is false, then + a. If "arguments" is an element of functionNames or if "arguments" is an + element of lexicalNames, then + i. Let argumentsObjectNeeded be false. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var args; + +var g = function* (x = args = arguments) { + let arguments; +}; + +g().next(); + +assert.sameValue(typeof args, 'object'); +assert.sameValue(args.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/array-destructuring-param-strict-body.js b/js/src/tests/test262/language/expressions/generators/array-destructuring-param-strict-body.js new file mode 100644 index 0000000000..799d648141 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/array-destructuring-param-strict-body.js @@ -0,0 +1,134 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/array-destructuring-param-strict-body.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: ArrayBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 13.3.3.4 Static Semantics: IsSimpleParameterList + + BindingElement : BindingPattern + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + +0, function*([element]) { + "use strict"; +}; diff --git a/js/src/tests/test262/language/expressions/generators/browser.js b/js/src/tests/test262/language/expressions/generators/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/browser.js diff --git a/js/src/tests/test262/language/expressions/generators/default-proto.js b/js/src/tests/test262/language/expressions/generators/default-proto.js new file mode 100644 index 0000000000..328ac12d44 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/default-proto.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluatebody +es6id: 14.4.11 +description: Intrinsic default prototype of GeneratorFunctions +info: | + 1. Let G be ? OrdinaryCreateFromConstructor(functionObject, + "%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]] »). + [...] + + 9.1.13 OrdinaryCreateFromConstructor + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [generators] +---*/ + +var g = function*() {}; +var GeneratorPrototype = Object.getPrototypeOf(g).prototype; +g.prototype = null; + +assert.sameValue(Object.getPrototypeOf(g()), GeneratorPrototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-abrupt.js b/js/src/tests/test262/language/expressions/generators/dflt-params-abrupt.js new file mode 100644 index 0000000000..0325685823 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-abrupt.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-abrupt.case +// - src/function-forms/error/gen-func-expr.template +/*--- +description: Abrupt completion returned by evaluation of initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ + +var callCount = 0; +var f; +f = function*(_ = (function() { throw new Test262Error(); }())) { + + callCount = callCount + 1; +}; + +assert.throws(Test262Error, function() { + f(); +}); +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-not-undefined.js b/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-not-undefined.js new file mode 100644 index 0000000000..034a1e1aed --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-not-undefined.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-not-undefined.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: Use of initializer when argument value is not `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + [...] + 23. Let iteratorRecord be Record {[[Iterator]]: + CreateListIterator(argumentsList), [[Done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + a. Perform ? IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + +---*/ +var obj = {}; +var falseCount = 0; +var stringCount = 0; +var nanCount = 0; +var zeroCount = 0; +var nullCount = 0; +var objCount = 0; + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(aFalse = falseCount +=1, aString = stringCount += 1, aNaN = nanCount += 1, a0 = zeroCount += 1, aNull = nullCount += 1, aObj = objCount +=1) { + assert.sameValue(aFalse, false); + assert.sameValue(aString, ''); + assert.sameValue(aNaN, NaN); + assert.sameValue(a0, 0); + assert.sameValue(aNull, null); + assert.sameValue(aObj, obj); + callCount = callCount + 1; +}; + +ref(false, '', NaN, 0, null, obj).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +assert.sameValue(falseCount, 0, 'initializer not evaluated: false'); +assert.sameValue(stringCount, 0, 'initializer not evaluated: string'); +assert.sameValue(nanCount, 0, 'initializer not evaluated: NaN'); +assert.sameValue(zeroCount, 0, 'initializer not evaluated: 0'); +assert.sameValue(nullCount, 0, 'initializer not evaluated: null'); +assert.sameValue(objCount, 0, 'initializer not evaluated: object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-undefined.js b/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-undefined.js new file mode 100644 index 0000000000..0176a8f6dd --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-arg-val-undefined.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-undefined.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: Use of initializer when argument value is `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + [...] + 23. Let iteratorRecord be Record {[[Iterator]]: + CreateListIterator(argumentsList), [[Done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + a. Perform ? IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + +---*/ + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(fromLiteral = 23, fromExpr = 45, fromHole = 99) { + assert.sameValue(fromLiteral, 23); + assert.sameValue(fromExpr, 45); + assert.sameValue(fromHole, 99); + callCount = callCount + 1; +}; + +ref(undefined, void 0).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-duplicates.js b/js/src/tests/test262/language/expressions/generators/dflt-params-duplicates.js new file mode 100644 index 0000000000..9077978234 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-duplicates.js @@ -0,0 +1,63 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-duplicates.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: It is a Syntax Error if BoundNames of FormalParameters contains any duplicate elements. (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.2 Static Semantics: Early Errors + + StrictFormalParameters : FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. + + FormalParameters : FormalParameterList + + - It is a Syntax Error if IsSimpleParameterList of FormalParameterList is + false and BoundNames of FormalParameterList contains any duplicate + elements. + +---*/ +$DONOTEVALUATE(); + +0, function*(x = 0, x) { + +}; diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-ref-later.js b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-later.js new file mode 100644 index 0000000000..eec15fb5fc --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-later.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-later.case +// - src/function-forms/error/gen-func-expr.template +/*--- +description: Referencing a parameter that occurs later in the ParameterList (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + +var callCount = 0; +var f; +f = function*(x = y, y) { + + callCount = callCount + 1; +}; + +assert.throws(ReferenceError, function() { + f(); +}); +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-ref-prior.js b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-prior.js new file mode 100644 index 0000000000..95d580d6ed --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-prior.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-prior.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: Referencing a parameter that occurs earlier in the ParameterList (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(x, y = x, z = y) { + assert.sameValue(x, 3, 'first argument value'); + assert.sameValue(y, 3, 'second argument value'); + assert.sameValue(z, 3, 'third argument value'); + callCount = callCount + 1; +}; + +ref(3).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-ref-self.js b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-self.js new file mode 100644 index 0000000000..c424952c24 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-ref-self.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-self.case +// - src/function-forms/error/gen-func-expr.template +/*--- +description: Referencing a parameter from within its own initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + +var callCount = 0; +var f; +f = function*(x = x) { + + callCount = callCount + 1; +}; + +assert.throws(ReferenceError, function() { + f(); +}); +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-rest.js b/js/src/tests/test262/language/expressions/generators/dflt-params-rest.js new file mode 100644 index 0000000000..5e27383608 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-rest.js @@ -0,0 +1,67 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-rest.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: RestParameter does not support an initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1 Function Definitions + + Syntax + + FunctionRestParameter[Yield] : + + BindingRestElement[?Yield] + + 13.3.3 Destructuring Binding Patterns + + Syntax + + BindingRestElement[Yield] : + + ...BindingIdentifier[?Yield] + ...BindingPattern[?Yield] + +---*/ +$DONOTEVALUATE(); + +0, function*(...x = []) { + +}; diff --git a/js/src/tests/test262/language/expressions/generators/dflt-params-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dflt-params-trailing-comma.js new file mode 100644 index 0000000000..82d4011377 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dflt-params-trailing-comma.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-trailing-comma.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: A trailing comma should not increase the respective length, using default parameters (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(a, b = 39,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; +}; + +ref(42, undefined, 1).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +assert.sameValue(ref.length, 1, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-close.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-close.js new file mode 100644 index 0000000000..84935e454a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-close.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var callCount = 0; +var f; +f = function*([x]) { + assert.sameValue(doneCallCount, 1); + callCount = callCount + 1; +}; + +f(iter).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..9fe0a54eea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Abrupt completion returned by GetIterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +var f = function*([x, y, z]) {}; + +assert.throws(TypeError, function() { + f([1, 2, 3]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err.js new file mode 100644 index 0000000000..7824df798e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-get-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Abrupt completion returned by GetIterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +var f = function*([x]) {}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-no-close.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-no-close.js new file mode 100644 index 0000000000..17c0a276db --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-init-iter-no-close.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var callCount = 0; +var f; +f = function*([x]) { + assert.sameValue(doneCallCount, 0); + callCount = callCount + 1; +}; + +f(iter).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-name-iter-val.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-name-iter-val.js new file mode 100644 index 0000000000..1b20ed6efa --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-name-iter-val.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding with normal value iteration (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..b9740b89e9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([[x, y, z] = [4, 5, 6]]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..889d7b46e9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([[x, y, z] = [4, 5, 6]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + callCount = callCount + 1; +}; + +f([[7, 8, 9]]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..55b0585736 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([[,] = g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..19ace65312 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var callCount = 0; +var f; +f = function*([[,] = g()]) { + assert.sameValue(callCount, 0); + callCount = callCount + 1; +}; + +f([[]]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..5df1a5271e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var callCount = 0; +var f; +f = function*([[] = function() { initCount += 1; return iter; }()]) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..16e5262256 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var callCount = 0; +var f; +f = function*([[] = function() { initCount += 1; }()]) { + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f([[23]]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..345b88f168 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var callCount = 0; +var f; +f = function*([[...x] = values]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..66d6596ac0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var callCount = 0; +var f; +f = function*([[...x] = function() { initCount += 1; }()]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f([values]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..766da8ebd2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Nested array destructuring with a null value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +var f = function*([[x]]) {}; + +assert.throws(TypeError, function() { + f([null]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..dfb7c3fd28 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer with an exhausted iterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..44ee74995c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding does assign name to arrow functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([arrow = () => {}]) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..faa542cff8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..627430ebba --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([cover = (function () {}), xCover = (0, function() {})]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..875dd85cdf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([fn = function () {}, xFn = function x() {}]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..268b3c6a68 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var callCount = 0; +var f; +f = function*([gen = function* () {}, xGen = function* x() {}]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..323cff1c8d --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer with a "hole" (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23]) { + assert.sameValue(x, 23); + // another statement + callCount = callCount + 1; +}; + +f([,]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..464148a6e0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*([w = counter(), x = counter(), y = counter(), z = counter()]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f([null, 0, false, '']).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..3d87005376 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Destructuring initializer returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +var f = function*([x = (function() { throw new Test262Error(); })()]) {}; + +assert.throws(Test262Error, function() { + f([undefined]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..a9fa217ef7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer with an undefined value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f([undefined]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..14e8881b67 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*([ x = unresolvableReference ]) {}; + +assert.throws(ReferenceError, function() { + f([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..0f780ae96f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding when value iteration completes (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x]) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..e73c151da6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding when value iteration was completed previously (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([_, x]) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..d39e870af6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +var f = function*([x]) {}; + +assert.throws(Test262Error, function() { + f(g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..9e6cfc4f60 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,83 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var callCount = 0; +var f; +f = function*([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..5d7925bb9c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +var f = function*([x]) {}; + +assert.throws(Test262Error, function() { + f(g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..ab8de5eba5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding when value iteration was completed previously (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..f021625b24 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with object binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ x, y, z } = { x: 44, y: 55, z: 66 }]) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..805f7b8089 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-id.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ x, y, z } = { x: 44, y: 55, z: 66 }]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + callCount = callCount + 1; +}; + +f([{ x: 11, y: 22, z: 33 }]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..b4cb42679c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with object binding pattern and initializer is used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..821fb6781b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f([{ u: 777, w: 888, y: 999 }]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..d05feeefbd --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Nested object destructuring with a null value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +var f = function*([{ x }]) {}; + +assert.throws(TypeError, function() { + f([null]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..c10cbdfc7b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Nested object destructuring with a value of `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +var f = function*([{ x }]) {}; + +assert.throws(TypeError, function() { + f([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..d9649650d4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-exhausted.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Elision accepts exhausted iterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var callCount = 0; +var f; +f = function*([,]) { + + callCount = callCount + 1; +}; + +f(iter).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..f4a4b1682b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision-step-err.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Elision advances iterator and forwards abrupt completions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +var f = function*([,]) {}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision.js new file mode 100644 index 0000000000..78dc86d0d5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-elision.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Elision advances iterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([,]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; + +f(g()).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-empty.js new file mode 100644 index 0000000000..e2aef6fdd4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-empty.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var callCount = 0; +var f; +f = function*([]) { + assert.sameValue(iterations, 0); + callCount = callCount + 1; +}; + +f(iter).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..7515d5fbf2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elem.js @@ -0,0 +1,86 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing an array BindingElementList pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([...[x, y, z]]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + callCount = callCount + 1; +}; + +f([3, 4, 5]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..b358ee1683 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-elision.js @@ -0,0 +1,92 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing an elision (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([...[,]]) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + callCount = callCount + 1; +}; + +f(g()).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..a661695c71 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-empty.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing an "empty" array pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var callCount = 0; +var f; +f = function*([...[]]) { + assert.sameValue(iterations, 1); + callCount = callCount + 1; +}; + +f(iter).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..8b9733f5ce --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-ary-rest.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing a rest element (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var callCount = 0; +var f; +f = function*([...[...x]]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + callCount = callCount + 1; +}; + +f(values).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..6b6f41f1da --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-direct.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Lone rest element (direct binding) (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var callCount = 0; +var f; +f = function*([...x]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + callCount = callCount + 1; +}; + +f([1]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..8be1666b72 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Rest element following elision elements (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +var f = function*([, ...x]) {}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..4d96462e9d --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-elision.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element following elision elements (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var callCount = 0; +var f; +f = function*([ , , ...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f(values).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..892df853e2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: RestElement applied to an exhausted iterator (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var callCount = 0; +var f; +f = function*([, , ...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + callCount = callCount + 1; +}; + +f([1, 2]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..7c8a355cb5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +var f = function*([...x]) {}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..1142c23c30 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +var f = function*([...x]) {}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id.js new file mode 100644 index 0000000000..6034f2a4b7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-id.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Lone rest element (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var callCount = 0; +var f; +f = function*([...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f(values).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..393bd2d279 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-ary.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (nested array pattern) does not support initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...[ x ] = []]) { + + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..601ba93dcf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-id.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (identifier) does not support initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...x = []]) { + + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..356f750d5c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-init-obj.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (nested object pattern) does not support initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...{ x } = []]) { + + callCount = callCount + 1; +}; + +f([]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..b53f0d33d0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...[x], y]) { + + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..e3d4dd7fdb --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-id.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (identifier) may not be followed by any element (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...x, y]) { + + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..6786a31042 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...{ x }, y]) { + + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..8e37860adf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-id.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing an object binding pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var callCount = 0; +var f; +f = function*([...{ length }]) { + assert.sameValue(length, 3); + callCount = callCount + 1; +}; + +f([1, 2, 3]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..b02ec61a0a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest element containing an object binding pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var callCount = 0; +var f; +f = function*([...{ 0: v, 1: w, 2: x, 3: y, length: z }]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + callCount = callCount + 1; +}; + +f([7, 8, 9]).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/browser.js b/js/src/tests/test262/language/expressions/generators/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/browser.js diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-close.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-close.js new file mode 100644 index 0000000000..2ccce3e053 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-close.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var callCount = 0; +var f; +f = function*([x] = iter) { + assert.sameValue(doneCallCount, 1); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..b8d8769a2d --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Abrupt completion returned by GetIterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +var f = function*([x, y, z] = [1, 2, 3]) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err.js new file mode 100644 index 0000000000..c527319ec5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-get-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Abrupt completion returned by GetIterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +var f = function*([x] = iter) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-no-close.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-no-close.js new file mode 100644 index 0000000000..7a3ada5d8f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-init-iter-no-close.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var callCount = 0; +var f; +f = function*([x] = iter) { + assert.sameValue(doneCallCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-name-iter-val.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-name-iter-val.js new file mode 100644 index 0000000000..1e74aed08c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-name-iter-val.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding with normal value iteration (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..cea02dc600 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([[x, y, z] = [4, 5, 6]] = []) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..7a39ed0ed9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..4297851c91 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([[,] = g()] = []) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..a2311af339 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var callCount = 0; +var f; +f = function*([[,] = g()] = [[]]) { + assert.sameValue(callCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..1e5e4c803f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var callCount = 0; +var f; +f = function*([[] = function() { initCount += 1; return iter; }()] = []) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..425307056e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var callCount = 0; +var f; +f = function*([[] = function() { initCount += 1; }()] = [[23]]) { + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..1d7491924f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var callCount = 0; +var f; +f = function*([[...x] = values] = []) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..a6a561fe24 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var callCount = 0; +var f; +f = function*([[...x] = function() { initCount += 1; }()] = [values]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..8a556b8cea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Nested array destructuring with a null value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +var f = function*([[x]] = [null]) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..a29b30e2d0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer with an exhausted iterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23] = []) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..bcef720169 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding does assign name to arrow functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([arrow = () => {}] = []) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..85f8a07e66 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..6dc1130fff --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([cover = (function () {}), xCover = (0, function() {})] = []) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..6104e9a415 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([fn = function () {}, xFn = function x() {}] = []) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..b1bd69fde8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var callCount = 0; +var f; +f = function*([gen = function* () {}, xGen = function* x() {}] = []) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..e9c254fb02 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer with a "hole" (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23] = [,]) { + assert.sameValue(x, 23); + // another statement + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..3c0ad59d48 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*([w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..cf4a74d084 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +var f = function*([x = (function() { throw new Test262Error(); })()] = [undefined]) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..1be4893f5f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer with an undefined value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x = 23] = [undefined]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..3d58aecc22 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*([ x = unresolvableReference ] = []) {}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..0f3565e347 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding when value iteration completes (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x] = []) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..b49d433935 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([_, x] = []) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..93c21035f6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +var f = function*([x] = g) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..8bb35763b7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,83 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var callCount = 0; +var f; +f = function*([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..692cc5c125 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +var f = function*([x] = g) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..1eaf8632d2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..8dc6ff5bc3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ x, y, z } = { x: 44, y: 55, z: 66 }] = []) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..28abb97ce4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-id.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..ff88ea5eb1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..37ac85f989 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..ff766738d8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Nested object destructuring with a null value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +var f = function*([{ x }] = [null]) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..08feed0d0c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Nested object destructuring with a value of `undefined` (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +var f = function*([{ x }] = []) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..7c645da262 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-exhausted.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Elision accepts exhausted iterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var callCount = 0; +var f; +f = function*([,] = iter) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..fa6ca1957a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision-step-err.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Elision advances iterator and forwards abrupt completions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +var f = function*([,] = iter) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision.js new file mode 100644 index 0000000000..b31ed21753 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-elision.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Elision advances iterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([,] = g()) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-empty.js new file mode 100644 index 0000000000..408096060f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-empty.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var callCount = 0; +var f; +f = function*([] = iter) { + assert.sameValue(iterations, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..6b0095c7f6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,86 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing an array BindingElementList pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*([...[x, y, z]] = [3, 4, 5]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..e9660265cc --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,92 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing an elision (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var callCount = 0; +var f; +f = function*([...[,]] = g()) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..36fe8ae212 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing an "empty" array pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var callCount = 0; +var f; +f = function*([...[]] = iter) { + assert.sameValue(iterations, 1); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..0e0dac6449 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing a rest element (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var callCount = 0; +var f; +f = function*([...[...x]] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..7d79be7121 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-direct.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Lone rest element (direct binding) (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +includes: [compareArray.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var callCount = 0; +var f; +f = function*([...x] = [1]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..764bff470b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Rest element following elision elements (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +var f = function*([, ...x] = iter) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..a5b2d80bb3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-elision.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element following elision elements (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var callCount = 0; +var f; +f = function*([ , , ...x] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..034b002d5b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: RestElement applied to an exhausted iterator (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var callCount = 0; +var f; +f = function*([, , ...x] = [1, 2]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..75de7fd5f1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +var f = function*([...x] = iter) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..c5ba5d9ab9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +var f = function*([...x] = iter) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..0442095310 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-id.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Lone rest element (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var callCount = 0; +var f; +f = function*([...x] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..7a882a4720 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-ary.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (nested array pattern) does not support initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...[ x ] = []] = []) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..62ca6e97d4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-id.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (identifier) does not support initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...x = []] = []) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..20d7982d79 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-init-obj.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (nested object pattern) does not support initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...{ x } = []] = []) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..ffd62054e4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...[x], y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..3d1c7aa00e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (identifier) may not be followed by any element (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...x, y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..b658b9a00e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var callCount = 0; +var f; +f = function*([...{ x }, y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..43457a06e8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-id.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing an object binding pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var callCount = 0; +var f; +f = function*([...{ length }] = [1, 2, 3]) { + assert.sameValue(length, 3); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..accb2c9cff --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest element containing an object binding pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var callCount = 0; +var f; +f = function*([...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-null.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-null.js new file mode 100644 index 0000000000..570fcd431f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +var f = function*({} = null) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-undefined.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-undefined.js new file mode 100644 index 0000000000..494e1878f4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-init-undefined.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +var f = function*({} = undefined) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-empty.js new file mode 100644 index 0000000000..97107e817c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-empty.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: No property access occurs for an "empty" object binding pattern (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var callCount = 0; +var f; +f = function*({} = obj) { + assert.sameValue(accessCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..709dd397d4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-get-value-err.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +var f = function*({ poisoned } = poisonedProperty) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..6b94ba3533 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ arrow = () => {} } = {}) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..9d4ce74644 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..c1ae517224 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ cover = (function () {}), xCover = (0, function() {}) } = {}) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..b3a7997d94 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ fn = function () {}, xFn = function x() {} } = {}) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..e8de63f3b1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var callCount = 0; +var f; +f = function*({ gen = function* () {}, xGen = function* x() {} } = {}) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..a87bc1a951 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-skipped.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*({ w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..3dcc295d5b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-throws.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error thrown when evaluating the initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ x = thrower() } = {}) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..420e08e639 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*({ x = unresolvableReference } = {}) {}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..43dba09066 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x, } = { x: 23 }) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-list-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-list-err.js new file mode 100644 index 0000000000..f3df1261e8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-list-err.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +var f = function*({ a, b = thrower(), c = ++initCount } = {}) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..a02b554adb --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: [x, y, z] = [4, 5, 6] } = {}) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..c69f41186f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x: [y], } = { x: [45] }) { + assert.sameValue(y,45); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..6678efefa4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: [x, y, z] = [4, 5, 6] } = { w: null }) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..ee7adce8c6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-ary.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..ee6c3cdecb --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-eval-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Evaluation of property name returns an abrupt completion (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ [thrower()]: x } = {}) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..213b984e3b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +var f = function*({ poisoned: x = ++initEvalCount } = poisonedProperty) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..a33ba9b8fe --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*({ s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..18c5056fd3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Error thrown when evaluating the initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ x: y = thrower() } = {}) {}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..fd95739abc --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*({ x: y = unresolvableReference } = {}) {}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..178aa432df --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-init.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Binding as specified via property name, identifier, and initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*({ x: y = 33 } = { }) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..79b9c9d3ee --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x: y, } = { x: 23 }) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..99bb26e199 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-id.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Binding as specified via property name and identifier (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*({ x: y } = { x: 23 }) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..a9e5b695d6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..0d1889c49c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..baa20d2dea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: { x, y, z } = undefined } = { }) {}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..1143ce5e3c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-prop-obj.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding, default-parameters] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..fe63881835 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-getter.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding, default-parameters] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ +var count = 0; + +var callCount = 0; +var f; +f = function*({...x} = { get v() { count++; return 2; } }) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..816af84005 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest object doesn't contain non-enumerable properties (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding, default-parameters] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var callCount = 0; +var f; +f = function*({...rest} = o) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..5b24c2735a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/dflt-obj-ptrn-rest-val-obj.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/gen-func-expr-dflt.template +/*--- +description: Rest object contains just unextracted data (generator function expression (default parameter)) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding, default-parameters] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var callCount = 0; +var f; +f = function*({a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-init-null.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-init-null.js new file mode 100644 index 0000000000..883f6927c4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-init-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +var f = function*({}) {}; + +assert.throws(TypeError, function() { + f(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-init-undefined.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-init-undefined.js new file mode 100644 index 0000000000..072239e98c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-init-undefined.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +var f = function*({}) {}; + +assert.throws(TypeError, function() { + f(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-empty.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-empty.js new file mode 100644 index 0000000000..df0223322e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-empty.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: No property access occurs for an "empty" object binding pattern (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var callCount = 0; +var f; +f = function*({}) { + assert.sameValue(accessCount, 0); + callCount = callCount + 1; +}; + +f(obj).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..858e0ab3e2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-get-value-err.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +var f = function*({ poisoned }) {}; + +assert.throws(Test262Error, function() { + f(poisonedProperty); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..cfe3625846 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ arrow = () => {} }) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..d80d863a1e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } }) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..a2cdba1fb1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ cover = (function () {}), xCover = (0, function() {}) }) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..1293ed3a05 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var callCount = 0; +var f; +f = function*({ fn = function () {}, xFn = function x() {} }) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..b6977e4c47 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var callCount = 0; +var f; +f = function*({ gen = function* () {}, xGen = function* x() {} }) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..0223524e4f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-skipped.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*({ w = counter(), x = counter(), y = counter(), z = counter() }) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; + +f({ w: null, x: 0, y: false, z: '' }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..c12a1d6156 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-throws.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error thrown when evaluating the initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ x = thrower() }) {}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..7a852e6d96 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*({ x = unresolvableReference }) {}; + +assert.throws(ReferenceError, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..b575ec7bf0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-id-trailing-comma.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x, }) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; + +f({ x: 23 }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-list-err.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-list-err.js new file mode 100644 index 0000000000..fe21f2843f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-list-err.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +var f = function*({ a, b = thrower(), c = ++initCount }) {}; + +assert.throws(Test262Error, function() { + f({}); +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..075b5266f9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: [x, y, z] = [4, 5, 6] }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f({}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..a6cf18c731 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x: [y], }) { + assert.sameValue(y,45); + callCount = callCount + 1; +}; + +f({ x: [45] }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..d9a65aa1af --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: [x, y, z] = [4, 5, 6] }) {}; + +assert.throws(TypeError, function() { + f({ w: null }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..f2102e670a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-ary.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: [x, y, z] = [4, 5, 6] }) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f({ w: [7, undefined, ] }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..4d8fd6516e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-eval-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Evaluation of property name returns an abrupt completion (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ [thrower()]: x }) {}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..9d07da7e87 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +var f = function*({ poisoned: x = ++initEvalCount }) {}; + +assert.throws(Test262Error, function() { + f(poisonedProperty); +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..f93fd8041a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var callCount = 0; +var f; +f = function*({ s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() }) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; + +f({ s: null, u: 0, w: false, y: '' }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..4f3d0b71be --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Error thrown when evaluating the initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +var f = function*({ x: y = thrower() }) {}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..4be3836c1e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Destructuring initializer is an unresolvable reference (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +var f = function*({ x: y = unresolvableReference }) {}; + +assert.throws(ReferenceError, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..c4afd6d6bc --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-init.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Binding as specified via property name, identifier, and initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*({ x: y = 33 }) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f({ }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..eb9d159993 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var callCount = 0; +var f; +f = function*({ x: y, }) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f({ x: 23 }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id.js new file mode 100644 index 0000000000..7d73216285 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-id.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Binding as specified via property name and identifier (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var callCount = 0; +var f; +f = function*({ x: y }) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; + +f({ x: 23 }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..7bf9c55b39 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f({ w: undefined }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..92a0021c6f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) {}; + +assert.throws(TypeError, function() { + f({ w: null }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..9016d033ca --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var f = function*({ w: { x, y, z } = undefined }) {}; + +assert.throws(TypeError, function() { + f({ }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..51ebd5d87e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-prop-obj.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var callCount = 0; +var f; +f = function*({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; + +f({ w: { x: undefined, z: 7 } }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-getter.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..d89d1fb25c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-getter.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ +var count = 0; + +var callCount = 0; +var f; +f = function*({...x}) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; + +f({ get v() { count++; return 2; } }).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..c35499afe6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest object doesn't contain non-enumerable properties (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var callCount = 0; +var f; +f = function*({...rest}) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount = callCount + 1; +}; + +f(o).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..1c76f7c863 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/obj-ptrn-rest-val-obj.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/gen-func-expr.template +/*--- +description: Rest object contains just unextracted data (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [object-rest, generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var callCount = 0; +var f; +f = function*({a, b, ...rest}) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; + +f({x: 1, y: 2, a: 5, b: 3}).next(); +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/dstr/shell.js b/js/src/tests/test262/language/expressions/generators/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/dstr/shell.js diff --git a/js/src/tests/test262/language/expressions/generators/eval-body-proto-realm.js b/js/src/tests/test262/language/expressions/generators/eval-body-proto-realm.js new file mode 100644 index 0000000000..7162532e50 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/eval-body-proto-realm.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluatebody +es6id: 14.4.11 +description: > + Default [[Prototype]] value derived from realm of the generator function +info: | + 1. Let G be ? OrdinaryCreateFromConstructor(functionObject, + "%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [generators, cross-realm] +---*/ + +var other = $262.createRealm().global; +var g = other.eval('(0, function*() {})'); +var GeneratorPrototype = Object.getPrototypeOf(g.prototype); +g.prototype = null; +var instance; + +instance = g(); + +assert.sameValue(Object.getPrototypeOf(instance), GeneratorPrototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/eval-var-scope-syntax-err.js b/js/src/tests/test262/language/expressions/generators/eval-var-scope-syntax-err.js new file mode 100644 index 0000000000..5b8969e979 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/eval-var-scope-syntax-err.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/eval-var-scope-syntax-err.case +// - src/function-forms/error-no-strict/gen-func-expr.template +/*--- +description: sloppy direct eval in params introduces var (generator function expression in sloppy code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + + Runtime Semantics: IteratorBindingInitialization + FormalParameter : BindingElement + + 1. Return the result of performing IteratorBindingInitialization for BindingElement with arguments iteratorRecord and environment. + +---*/ + +var callCount = 0; +var f; +f = function*(a = eval("var a = 42")) { + + callCount = callCount + 1; +}; + +assert.throws(SyntaxError, function() { + f(); +}); +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/browser.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/browser.js diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-arguments.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-arguments.js new file mode 100644 index 0000000000..e0198fb5c8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-arguments.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-direct-access-prop-arguments.case +// - src/function-forms/forbidden-extensions/bullet-one/gen-func-expr.template +/*--- +description: Forbidden extension, f.arguments (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + + ECMAScript function objects defined using syntactic constructors in strict mode code must + not be created with own properties named "caller" or "arguments". Such own properties also + must not be created for function objects defined using an ArrowFunction, MethodDefinition, + GeneratorDeclaration, GeneratorExpression, AsyncGeneratorDeclaration, AsyncGeneratorExpression, + ClassDeclaration, ClassExpression, AsyncFunctionDeclaration, AsyncFunctionExpression, or + AsyncArrowFunction regardless of whether the definition is contained in strict mode code. + Built-in functions, strict functions created using the Function constructor, generator functions + created using the Generator constructor, async functions created using the AsyncFunction + constructor, and functions created using the bind method also must not be created with such own + properties. + +---*/ + +var callCount = 0; +var f; +f = function*() { + assert.sameValue(f.hasOwnProperty("arguments"), false); + callCount++; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function body evaluated'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-caller.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-caller.js new file mode 100644 index 0000000000..feb896f644 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/gen-func-expr-forbidden-ext-direct-access-prop-caller.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-direct-access-prop-caller.case +// - src/function-forms/forbidden-extensions/bullet-one/gen-func-expr.template +/*--- +description: Forbidden extension, o.caller (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + + ECMAScript function objects defined using syntactic constructors in strict mode code must + not be created with own properties named "caller" or "arguments". Such own properties also + must not be created for function objects defined using an ArrowFunction, MethodDefinition, + GeneratorDeclaration, GeneratorExpression, AsyncGeneratorDeclaration, AsyncGeneratorExpression, + ClassDeclaration, ClassExpression, AsyncFunctionDeclaration, AsyncFunctionExpression, or + AsyncArrowFunction regardless of whether the definition is contained in strict mode code. + Built-in functions, strict functions created using the Function constructor, generator functions + created using the Generator constructor, async functions created using the AsyncFunction + constructor, and functions created using the bind method also must not be created with such own + properties. + +---*/ + +var callCount = 0; +var f; +f = function*() { + assert.sameValue(f.hasOwnProperty("caller"), false); + callCount++; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function body evaluated'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/shell.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b1/shell.js diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/browser.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/browser.js diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-get.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-get.js new file mode 100644 index 0000000000..e141522a1a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-get.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-own-prop-caller-get.case +// - src/function-forms/forbidden-extensions/bullet-two/gen-func-expr.template +/*--- +description: Forbidden extension, o.caller (generator function expression) +esid: sec-generator-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + +var callCount = 0; +var f; +f = function*() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && true) { + Object.defineProperty(inner, "caller", {get(){return 1}}); + } + var result = inner(); + if (descriptor && descriptor.configurable && true) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + + callCount++; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-value.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-value.js new file mode 100644 index 0000000000..2c7935b7a2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-own-prop-caller-value.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-own-prop-caller-value.case +// - src/function-forms/forbidden-extensions/bullet-two/gen-func-expr.template +/*--- +description: Forbidden extension, o.caller (generator function expression) +esid: sec-generator-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + +var callCount = 0; +var f; +f = function*() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && true) { + Object.defineProperty(inner, "caller", {value: 1}); + } + var result = inner(); + if (descriptor && descriptor.configurable && true) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + + callCount++; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-prop-caller.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-prop-caller.js new file mode 100644 index 0000000000..de24aa5f8a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/gen-func-expr-forbidden-ext-indirect-access-prop-caller.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-prop-caller.case +// - src/function-forms/forbidden-extensions/bullet-two/gen-func-expr.template +/*--- +description: Forbidden extension, o.caller (generator function expression) +esid: sec-generator-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + +var callCount = 0; +var f; +f = function*() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && false) { + Object.defineProperty(inner, "caller", {}); + } + var result = inner(); + if (descriptor && descriptor.configurable && false) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + + callCount++; +}; + +f().next(); +assert.sameValue(callCount, 1, 'generator function body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/shell.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/b2/shell.js diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/browser.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/browser.js diff --git a/js/src/tests/test262/language/expressions/generators/forbidden-ext/shell.js b/js/src/tests/test262/language/expressions/generators/forbidden-ext/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/forbidden-ext/shell.js diff --git a/js/src/tests/test262/language/expressions/generators/generator-created-after-decl-inst.js b/js/src/tests/test262/language/expressions/generators/generator-created-after-decl-inst.js new file mode 100644 index 0000000000..740eb2d243 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/generator-created-after-decl-inst.js @@ -0,0 +1,26 @@ +// Copyright (C) 2018 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluatebody +description: > + The generator object is created after FunctionDeclarationInstantiation. +info: | + 14.4.10 Runtime Semantics: EvaluateBody + + 1. Perform ? FunctionDeclarationInstantiation(functionObject, argumentsList). + 2. Let G be ? OrdinaryCreateFromConstructor(functionObject, "%GeneratorPrototype%", + « [[GeneratorState]], [[GeneratorContext]] »). + 3. Perform GeneratorStart(G, FunctionBody). + ... + +features: [generators] +---*/ + +var g = function*(a = (g.prototype = null)) {} +var oldPrototype = g.prototype; +var it = g(); + +assert.notSameValue(Object.getPrototypeOf(it), oldPrototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/has-instance.js b/js/src/tests/test262/language/expressions/generators/has-instance.js new file mode 100644 index 0000000000..3167c59026 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/has-instance.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + A Generator object is an instance of a generator function. +es6id: 25.3 +features: [generators] +---*/ + +var g = function*() {}; + +assert(g() instanceof g, 'Instance created via function invocation'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/implicit-name.js b/js/src/tests/test262/language/expressions/generators/implicit-name.js new file mode 100644 index 0000000000..d7c3752b1a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/implicit-name.js @@ -0,0 +1,22 @@ +// Copyright 2015 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Generator can be declared with GeneratorExpression syntax +es6id: 14.4 +author: Sam Mikes +description: can create generator function expressions (no name) +features: [generators] +---*/ + +var f = function *(a) { yield a+1; return; }; + +assert.sameValue(f.name, 'f'); + +var g = f(3); + +assert.sameValue(g.next().value, 4); +assert.sameValue(g.next().done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/invoke-as-constructor.js b/js/src/tests/test262/language/expressions/generators/invoke-as-constructor.js new file mode 100644 index 0000000000..d1f7f24879 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/invoke-as-constructor.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Generator expressions cannot be used as constructors. +es6id: 14.4 +features: [generators] +---*/ + +var g = function*(){}; + +assert.throws(TypeError, function() { + var instance = new g(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/length-dflt.js b/js/src/tests/test262/language/expressions/generators/length-dflt.js new file mode 100644 index 0000000000..3d574f62c9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/length-dflt.js @@ -0,0 +1,62 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.1.6 +description: > + Default parameters' effect on function length +info: | + Function length is counted by the non initialized parameters in the left. + + 9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope) + + [...] + 2. Let len be the ExpectedArgumentCount of ParameterList. + 3. Perform ! DefinePropertyOrThrow(F, "length", PropertyDescriptor{[[Value]]: + len, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}). + [...] + + FormalsList : FormalParameter + + 1. If HasInitializer of FormalParameter is true return 0 + 2. Return 1. + + FormalsList : FormalsList , FormalParameter + + 1. Let count be the ExpectedArgumentCount of FormalsList. + 2. If HasInitializer of FormalsList is true or HasInitializer of + FormalParameter is true, return count. + 3. Return count+1. +features: [generators, default-parameters] +includes: [propertyHelper.js] +---*/ + + +var f1 = function* (x = 42) {}; + +assert.sameValue(f1.length, 0, 'FormalsList: x = 42'); +verifyNotEnumerable(f1, 'length'); +verifyNotWritable(f1, 'length'); +verifyConfigurable(f1, 'length'); + +var f2 = function* (x = 42, y) {}; + +assert.sameValue(f2.length, 0, 'FormalsList: x = 42, y'); +verifyNotEnumerable(f2, 'length'); +verifyNotWritable(f2, 'length'); +verifyConfigurable(f2, 'length'); + +var f3 = function* (x, y = 42) {}; + +assert.sameValue(f3.length, 1, 'FormalsList: x, y = 42'); +verifyNotEnumerable(f3, 'length'); +verifyNotWritable(f3, 'length'); +verifyConfigurable(f3, 'length'); + +var f4 = function* (x, y = 42, z) {}; + +assert.sameValue(f4.length, 1, 'FormalsList: x, y = 42, z'); +verifyNotEnumerable(f4, 'length'); +verifyNotWritable(f4, 'length'); +verifyConfigurable(f4, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/length-property-descriptor.js b/js/src/tests/test262/language/expressions/generators/length-property-descriptor.js new file mode 100644 index 0000000000..dd1817d5ac --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/length-property-descriptor.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Generator objects should define a `length` property. +includes: [propertyHelper.js] +es6id: 25.2.4 +features: [generators] +---*/ + +var g = function*() {}; + +assert.sameValue(g.length, 0); +verifyNotEnumerable(g, 'length'); +verifyNotWritable(g, 'length'); +verifyConfigurable(g, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/name.js b/js/src/tests/test262/language/expressions/generators/name.js new file mode 100644 index 0000000000..72e5c44be3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/name.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. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: Assignment of function `name` attribute +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + 1. Let scope be the LexicalEnvironment of the running execution context. + 2. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, ""). + ... + 6. Return closure. + + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + 1. Let scope be the running execution context's LexicalEnvironment. + 2. Let funcEnv be NewDeclarativeEnvironment(scope). + 3. Let envRec be funcEnv's EnvironmentRecord. + 4. Let name be StringValue of BindingIdentifier. + 5. Perform envRec.CreateImmutableBinding(name, false). + 6. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, funcEnv, name). + ... + 11. Return closure. +includes: [propertyHelper.js] +features: [generators] +---*/ + +verifyProperty(function*() {}, "name", { + value: "", writable: false, enumerable: false, configurable: true +}); + +verifyProperty(function* func() {}, "name", { + value: "func", writable: false, enumerable: false, configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-arrow.js b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-arrow.js new file mode 100644 index 0000000000..912d2ed2c1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-arrow.js @@ -0,0 +1,27 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body-in-arrow.case +// - src/function-forms/expr-named/gen-func-expr-named-no-strict.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in non-strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + (() => { + BindingIdentifier = 1; + })(); + return BindingIdentifier; +}; + +assert.sameValue(ref().next().value, ref); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-eval.js b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-eval.js new file mode 100644 index 0000000000..8d60446726 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body-in-eval.js @@ -0,0 +1,25 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body-in-eval.case +// - src/function-forms/expr-named/gen-func-expr-named-no-strict.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in non-strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + eval("BindingIdentifier = 1"); + return BindingIdentifier; +}; + +assert.sameValue(ref().next().value, ref); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body.js b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body.js new file mode 100644 index 0000000000..98abcb882f --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-no-strict-reassign-fn-name-in-body.js @@ -0,0 +1,25 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body.case +// - src/function-forms/expr-named/gen-func-expr-named-no-strict.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in non-strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + BindingIdentifier = 1; + return BindingIdentifier; +}; + +assert.sameValue(ref().next().value, ref); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-arrow-strict.js b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-arrow-strict.js new file mode 100644 index 0000000000..93b8ae9297 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-arrow-strict.js @@ -0,0 +1,30 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body-in-arrow.case +// - src/function-forms/expr-named/gen-func-expr-named-strict-error.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, onlyStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + (() => { + BindingIdentifier = 1; + })(); + return BindingIdentifier; +}; + +assert.throws(TypeError, () => { + ref().next(); +}); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-eval-strict.js b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-eval-strict.js new file mode 100644 index 0000000000..9d20bb6237 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-in-eval-strict.js @@ -0,0 +1,28 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body-in-eval.case +// - src/function-forms/expr-named/gen-func-expr-named-strict-error.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, onlyStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + eval("BindingIdentifier = 1"); + return BindingIdentifier; +}; + +assert.throws(TypeError, () => { + ref().next(); +}); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-strict.js b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-strict.js new file mode 100644 index 0000000000..bf12ac88ca --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-strict-error-reassign-fn-name-in-body-strict.js @@ -0,0 +1,28 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/function-forms/reassign-fn-name-in-body.case +// - src/function-forms/expr-named/gen-func-expr-named-strict-error.template +/*--- +description: Reassignment of function name is silently ignored in non-strict mode code. (named generator function expression in strict mode code) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated, onlyStrict] +info: | + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + +---*/ + +// increment callCount in case "body" +let callCount = 0; +let ref = function * BindingIdentifier() { + callCount++; + BindingIdentifier = 1; + return BindingIdentifier; +}; + +assert.throws(TypeError, () => { + ref().next(); +}); +assert.sameValue(callCount, 1, 'function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier-escaped.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier-escaped.js new file mode 100644 index 0000000000..87c9871b1c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier-escaped.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + var yi\u0065ld; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier.js new file mode 100644 index 0000000000..86de56e8b1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-binding-identifier.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + var yield; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference-escaped.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference-escaped.js new file mode 100644 index 0000000000..010032dad4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference-escaped.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + void yi\u0065ld; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference.js new file mode 100644 index 0000000000..186df1cc8a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-identifier-reference.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + void yield; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier-escaped.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier-escaped.js new file mode 100644 index 0000000000..eab9d8a034 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier-escaped.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + yi\u0065ld: ; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier.js b/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier.js new file mode 100644 index 0000000000..f0d1001d49 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-as-label-identifier.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier.case +// - src/generators/syntax/expression-named.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *g() { + yield: ; +}; diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-identifier-non-strict.js b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-non-strict.js new file mode 100644 index 0000000000..a19f04a13a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-non-strict.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-non-strict.case +// - src/generators/non-strict/expression-named.template +/*--- +description: Use of yield as a valid identifier in a function body inside a generator body in non strict mode (Generator named expression - valid for non-strict only cases) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated, noStrict] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + +---*/ + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + return (function(arg) { + var yield = arg + 1; + return yield; + }(yield)) +}; + +var iter = gen(); + +var item = iter.next(); + +assert.sameValue(item.done, false); +assert.sameValue(item.value, undefined); + +item = iter.next(42); + +assert.sameValue(item.done, true); +assert.sameValue(item.value, 43); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-non-strict.js b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-non-strict.js new file mode 100644 index 0000000000..46f9050486 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-non-strict.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-spread-non-strict.case +// - src/generators/non-strict/expression-named.template +/*--- +description: Mixed use of object spread and yield as a valid identifier in a function body inside a generator body in non strict mode (Generator named expression - valid for non-strict only cases) +esid: prod-GeneratorExpression +features: [Symbol, object-spread, generators] +flags: [generated, noStrict] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +var s = Symbol('s'); + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + yield { + ...yield yield, + ...(function(arg) { + var yield = arg; + return {...yield}; + }(yield)), + ...yield, + } +}; + +var iter = gen(); + +var iter = gen(); + +iter.next(); +iter.next(); +iter.next({ x: 10, a: 0, b: 0, [s]: 1 }); +iter.next({ y: 20, a: 1, b: 1, [s]: 42 }); +var item = iter.next({ z: 30, b: 2 }); + +var value = item.value; + +assert.sameValue(item.done, false); +assert.sameValue(value.x, 10); +assert.sameValue(value.y, 20); +assert.sameValue(value.z, 30); +assert.sameValue(value.a, 1); +assert.sameValue(value.b, 2); +assert.sameValue(value[s], 42); +assert(Object.hasOwnProperty.call(value, s)); +assert.sameValue(Object.keys(value).length, 5); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-strict-strict.js b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-strict-strict.js new file mode 100644 index 0000000000..c3177446bf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-spread-strict-strict.js @@ -0,0 +1,46 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-spread-strict.case +// - src/generators/default/expression-named.template +/*--- +description: It's an early error if the AssignmentExpression is a function body with yield as an identifier in strict mode. (Named generator expression) +esid: prod-GeneratorExpression +features: [object-spread, generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + return { + ...(function() { + var yield; + throw new Test262Error(); + }()), + } +}; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-identifier-strict-strict.js b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-strict-strict.js new file mode 100644 index 0000000000..3317d213da --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-identifier-strict-strict.js @@ -0,0 +1,37 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-strict.case +// - src/generators/default/expression-named.template +/*--- +description: It's an early error if the generator body has another function body with yield as an identifier in strict mode. (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + (function() { + var yield; + throw new Test262Error(); + }()) +}; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-multiple.js b/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-multiple.js new file mode 100644 index 0000000000..3f2b0a44ea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-multiple.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-multiple.case +// - src/generators/default/expression-named.template +/*--- +description: Use yield value in a array spread position (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +includes: [compareArray.js] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] + +---*/ +var arr = ['a', 'b', 'c']; +var item; + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + yield [...yield yield]; +}; + +var iter = gen(); + +iter.next(false); +item = iter.next(['a', 'b', 'c']); +item = iter.next(item.value); + +assert(compareArray(item.value, arr)); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-single.js b/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-single.js new file mode 100644 index 0000000000..6009116c72 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-spread-arr-single.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-single.case +// - src/generators/default/expression-named.template +/*--- +description: Use yield value in a array spread position (Named generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] +---*/ +var arr = ['a', 'b', 'c']; + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + yield [...yield]; +}; + +var iter = gen(); + +iter.next(false); +var item = iter.next(arr); +var value = item.value; + +assert.notSameValue(value, arr, 'value is a new array'); +assert(Array.isArray(value), 'value is an Array exotic object'); +assert.sameValue(value.length, 3) +assert.sameValue(value[0], 'a'); +assert.sameValue(value[1], 'b'); +assert.sameValue(value[2], 'c'); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/named-yield-spread-obj.js b/js/src/tests/test262/language/expressions/generators/named-yield-spread-obj.js new file mode 100644 index 0000000000..aa58d44a2a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/named-yield-spread-obj.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-obj.case +// - src/generators/default/expression-named.template +/*--- +description: Use yield value in a object spread position (Named generator expression) +esid: prod-GeneratorExpression +features: [object-spread, generators] +flags: [generated] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ + +var callCount = 0; + +var gen = function *g() { + callCount += 1; + yield { + ...yield, + y: 1, + ...yield yield, + }; +}; + +var iter = gen(); + +iter.next(); +iter.next({ x: 42 }); +iter.next({ x: 'lol' }); +var item = iter.next({ y: 39 }); + +assert.sameValue(item.value.x, 42); +assert.sameValue(item.value.y, 39); +assert.sameValue(Object.keys(item.value).length, 2); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/no-name.js b/js/src/tests/test262/language/expressions/generators/no-name.js new file mode 100644 index 0000000000..34d7e0b10e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/no-name.js @@ -0,0 +1,23 @@ +// Copyright 2015 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Generator can be declared with GeneratorExpression syntax +es6id: 14.4 +author: Sam Mikes +description: can create generator function expressions (no name) +features: [generators] +---*/ + +var a = [function *(a) { yield a+1; return; }]; +var f = a[0]; + +assert.sameValue(f.name, ''); + +var g = f(3); + +assert.sameValue(g.next().value, 4); +assert.sameValue(g.next().done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/no-yield.js b/js/src/tests/test262/language/expressions/generators/no-yield.js new file mode 100644 index 0000000000..ec30a1501e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/no-yield.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: > + Generators declared with GeneratorExpression syntax do not require a + `yield` expression. +es6id: 14.4 +features: [generators] +---*/ + +var result; +var foo = function*(a) {}; + +result = foo(3).next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/object-destructuring-param-strict-body.js b/js/src/tests/test262/language/expressions/generators/object-destructuring-param-strict-body.js new file mode 100644 index 0000000000..5c24fda861 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/object-destructuring-param-strict-body.js @@ -0,0 +1,134 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/object-destructuring-param-strict-body.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: ObjectBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 13.3.3.4 Static Semantics: IsSimpleParameterList + + BindingElement : BindingPattern + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + +0, function*({property}) { + "use strict"; +}; diff --git a/js/src/tests/test262/language/expressions/generators/param-dflt-yield.js b/js/src/tests/test262/language/expressions/generators/param-dflt-yield.js new file mode 100644 index 0000000000..5e3dc67642 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/param-dflt-yield.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions +es6id: 14.4 +description: > + YieldExpression cannot be used within the FormalParameters of a generator + function +info: | + GeneratorExpression : + + function * BindingIdentifier[Yield]opt ( FormalParameters[Yield] ) { GeneratorBody } + + YieldExpression cannot be used within the FormalParameters of a generator + function because any expressions that are part of FormalParameters are + evaluated before the resulting generator object is in a resumable state. +features: [generators, default-parameters] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +0, function*(x = yield) {}; diff --git a/js/src/tests/test262/language/expressions/generators/params-dflt-args-unmapped.js b/js/src/tests/test262/language/expressions/generators/params-dflt-args-unmapped.js new file mode 100644 index 0000000000..9a76cfbe30 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/params-dflt-args-unmapped.js @@ -0,0 +1,84 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Referencing the arguments object from a default parameter (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +es6id: 14.4.14 +features: [generators, default-parameters] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*(x, _ = 0) { + assert.sameValue(x, undefined, 'parameter binding value (initial)'); + assert.sameValue( + arguments[0], undefined, 'arguments property value (initial)' + ); + + arguments[0] = 1; + + assert.sameValue( + x, undefined, 'parameter binding value (after arguments modification)' + ); + assert.sameValue( + arguments[0], 1, 'arguments property value (after arguments modification)' + ); + + x = 2; + + assert.sameValue( + x, 2, 'parameter binding value (after parameter binding modification)' + ); + assert.sameValue( + arguments[0], + 1, + 'arguments property value (after parameter binding modification)' + ); + callCount = callCount + 1; +}; + +f().next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/params-dflt-ref-arguments.js b/js/src/tests/test262/language/expressions/generators/params-dflt-ref-arguments.js new file mode 100644 index 0000000000..cb0ddf5507 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/params-dflt-ref-arguments.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Referencing the arguments object from a default parameter (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +es6id: 14.4.14 +features: [generators, default-parameters] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. +---*/ + +var callCount = 0; +var f; +f = function*(x = arguments[2], y = arguments[3], z) { + assert.sameValue(x, 'third', 'first parameter'); + assert.sameValue(y, 'fourth', 'second parameter'); + assert.sameValue(z, 'third', 'third parameter'); + callCount = callCount + 1; +}; + +f(undefined, undefined, 'third', 'fourth').next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/params-trailing-comma-multiple.js b/js/src/tests/test262/language/expressions/generators/params-trailing-comma-multiple.js new file mode 100644 index 0000000000..85216d808a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/params-trailing-comma-multiple.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-multiple.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: A trailing comma should not increase the respective length, using multiple parameters (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(a, b,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; +}; + +ref(42, 39, 1).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +assert.sameValue(ref.length, 2, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/params-trailing-comma-single.js b/js/src/tests/test262/language/expressions/generators/params-trailing-comma-single.js new file mode 100644 index 0000000000..e8cd6ca25a --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/params-trailing-comma-single.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-single.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: A trailing comma should not increase the respective length, using a single parameter (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(a,) { + assert.sameValue(a, 42); + callCount = callCount + 1; +}; + +ref(42, 39).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + +assert.sameValue(ref.length, 1, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-own-properties.js b/js/src/tests/test262/language/expressions/generators/prototype-own-properties.js new file mode 100644 index 0000000000..f3a3c0f4c8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-own-properties.js @@ -0,0 +1,14 @@ +// 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.2.4.2 +description: > + The `prototype` property of GeneratorFunction instances are created as + plain objects with no "own" properties. +features: [generators] +---*/ + +var ownProperties = Object.getOwnPropertyNames(function*() {}.prototype); +assert.sameValue(ownProperties.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-property-descriptor.js b/js/src/tests/test262/language/expressions/generators/prototype-property-descriptor.js new file mode 100644 index 0000000000..c55c68cdcf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-property-descriptor.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. + +/*--- +description: > + Generator objects should define a `prototype` property. +includes: [propertyHelper.js] +es6id: 25.2.4 +features: [generators] +---*/ + +var g = function*() {}; + +verifyNotEnumerable(g, 'prototype'); +verifyWritable(g, 'prototype'); +verifyNotConfigurable(g, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-relation-to-function.js b/js/src/tests/test262/language/expressions/generators/prototype-relation-to-function.js new file mode 100644 index 0000000000..3ff93f60ab --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-relation-to-function.js @@ -0,0 +1,20 @@ +// 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 value of the [[Prototype]] internal slot of the GeneratorFunction + prototype object is the FunctionPrototype intrinsic object. +es6id: 25.2.2.2 +features: [generators] +---*/ + +function f() {} +var g = function*() {}; + +assert.sameValue( + Object.getPrototypeOf(Object.getPrototypeOf(g)), + Object.getPrototypeOf(f) +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-typeof.js b/js/src/tests/test262/language/expressions/generators/prototype-typeof.js new file mode 100644 index 0000000000..6cb56f61d4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-typeof.js @@ -0,0 +1,14 @@ +// 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.2.4.2 +description: > + Whenever a GeneratorFunction instance is created another ordinary object is + also created and is the initial value of the generator function’s prototype + property. +features: [generators] +---*/ + +assert.sameValue(typeof function*() {}.prototype, 'object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-uniqueness.js b/js/src/tests/test262/language/expressions/generators/prototype-uniqueness.js new file mode 100644 index 0000000000..4a1b8c3c4b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-uniqueness.js @@ -0,0 +1,16 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + GeneratorFunction instances are created with a unique prototype object. +es6id: 25.2.1 +features: [generators] +---*/ + +var g1 = function*() {}; +var g2 = function*() {}; + +assert(g1.prototype !== g2.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/prototype-value.js b/js/src/tests/test262/language/expressions/generators/prototype-value.js new file mode 100644 index 0000000000..2add152eb0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/prototype-value.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Generator instances directly inherit properties from the object that is the + value of the prototype property of the Generator function that created the + instance. +es6id: 25.3 +features: [generators] +---*/ + +var g = function*() {}; + +assert.sameValue( + Object.getPrototypeOf(g()), + g.prototype, + 'Instance created via function invocation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/rest-param-strict-body.js b/js/src/tests/test262/language/expressions/generators/rest-param-strict-body.js new file mode 100644 index 0000000000..55f0858baa --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/rest-param-strict-body.js @@ -0,0 +1,134 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/rest-param-strict-body.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: RestParameter and Use Strict Directive are not allowed to coexist for the same function. (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + 14.1.13 Static Semantics: IsSimpleParameterList + + FormalParameters : FormalParameterList , FunctionRestParameter + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + +0, function*(a,...rest) { + "use strict"; +}; diff --git a/js/src/tests/test262/language/expressions/generators/rest-params-trailing-comma-early-error.js b/js/src/tests/test262/language/expressions/generators/rest-params-trailing-comma-early-error.js new file mode 100644 index 0000000000..c63f696307 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/rest-params-trailing-comma-early-error.js @@ -0,0 +1,60 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/rest-params-trailing-comma-early-error.case +// - src/function-forms/syntax/gen-func-expr.template +/*--- +description: It's a syntax error if a FunctionRestParameter is followed by a trailing comma (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : + [empty] + FunctionRestParameter[?Yield, ?Await] + FormalParameterList[?Yield, ?Await] + FormalParameterList[?Yield, ?Await] , + FormalParameterList[?Yield, ?Await] , FunctionRestParameter[?Yield, ?Await] +---*/ +$DONOTEVALUATE(); + +0, function*(...a,) { + +}; diff --git a/js/src/tests/test262/language/expressions/generators/return.js b/js/src/tests/test262/language/expressions/generators/return.js new file mode 100644 index 0000000000..f16a9cf1cf --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/return.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `return` is a valid statement within generator function bodies. +es6id: 14.4 +features: [generators] +---*/ + +var result; +var g1 = function*() { return; }; +var g2 = function*() { return 1; }; + +result = g1().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +result = g2().next(); +assert.sameValue(result.value, 1); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-body-lex-distinct.js b/js/src/tests/test262/language/expressions/generators/scope-body-lex-distinct.js new file mode 100644 index 0000000000..92242f65d5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-body-lex-distinct.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + Creation of new lexical environment (distinct from the variable + environment) for the function body outside of strict mode +info: | + [...] + 29. If strict is false, then + a. Let lexEnv be NewDeclarativeEnvironment(varEnv). + b. NOTE: Non-strict functions use a separate lexical Environment Record + for top-level lexical declarations so that a direct eval can + determine whether any var scoped declarations introduced by the eval + code conflict with pre-existing top-level lexically scoped + declarations. This is not needed for strict functions because a + strict direct eval always places all declarations into a new + Environment Record. + [...] + + 18.2.1.3 Runtime Semantics: EvalDeclarationInstantiation + + [...] + 5. If strict is false, then + [...] + b. Let thisLex be lexEnv. + c. Assert: The following loop will terminate. + d. Repeat while thisLex is not the same as varEnv, + i. Let thisEnvRec be thisLex's EnvironmentRecord. + ii. If thisEnvRec is not an object Environment Record, then + 1. NOTE: The environment of with statements cannot contain any + lexical declaration so it doesn't need to be checked for + var/let hoisting conflicts. + 2. For each name in varNames, do + a. If thisEnvRec.HasBinding(name) is true, then + i. Throw a SyntaxError exception. + ii. NOTE: Annex B.3.5 defines alternate semantics for the + above step. + b. NOTE: A direct eval will not hoist var declaration over a + like-named lexical declaration. + iii. Let thisLex be thisLex's outer environment reference. +flags: [noStrict] +features: [generators, let] +---*/ + +var g = function*() { + let x; + eval('var x;'); +}; +var iter = g(); + +assert.throws(SyntaxError, function() { + iter.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-name-var-close.js b/js/src/tests/test262/language/expressions/generators/scope-name-var-close.js new file mode 100644 index 0000000000..de11e23dbe --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-name-var-close.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: Removal of variable environment for the BindingIdentifier +info: | + [...] + 2. Let scope be the running execution context's LexicalEnvironment. + 3. Let funcEnv be NewDeclarativeEnvironment(scope). + 4. Let envRec be funcEnv's EnvironmentRecord. + 5. Let name be StringValue of BindingIdentifier. + 6. Perform envRec.CreateImmutableBinding(name, false). + 7. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, funcEnv, strict). + [...] +features: [generators] +---*/ + +var probe; + +var func = function* g() { + probe = function() { return g; }; +}; +var g = 'outside'; + +func().next(); + +assert.sameValue(g, 'outside'); +assert.sameValue(probe(), func); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-name-var-open-non-strict.js b/js/src/tests/test262/language/expressions/generators/scope-name-var-open-non-strict.js new file mode 100644 index 0000000000..2f3e320953 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-name-var-open-non-strict.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Creation of new variable environment for the BindingIdentifier + parameter +info: | + [...] + 2. Let scope be the running execution context's LexicalEnvironment. + 3. Let funcEnv be NewDeclarativeEnvironment(scope). + 4. Let envRec be funcEnv's EnvironmentRecord. + 5. Let name be StringValue of BindingIdentifier. + 6. Perform envRec.CreateImmutableBinding(name, false). + 7. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, funcEnv, strict). + [...] +flags: [noStrict] +features: [generators] +---*/ + +var g = 'outside'; +var probeBefore = function() { return g; }; +var setBefore = function() { g = null; }; +var probeParams, setParams, probeBody, setBody; + +var func = function* g( + _ = ( + probeParams = function() { return g; }, + setParams = function() { g = null; } + ) + ) { + probeBody = function() { return g; }; + setBody = function() { g = null; }; +}; + +func().next(); + +assert.sameValue(probeBefore(), 'outside'); +setBefore(); +assert.sameValue(probeBefore(), null); + +assert.sameValue(probeParams(), func, 'inner binding value (from parameters)'); +setParams(); +assert.sameValue( + probeParams(), func, 'inner binding is immutable (from parameters)' +); + +assert.sameValue(probeBody(), func, 'inner binding value (from body)'); +setBody(); +assert.sameValue(probeBody(), func, 'inner binding is immutable (from body)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-name-var-open-strict-strict.js b/js/src/tests/test262/language/expressions/generators/scope-name-var-open-strict-strict.js new file mode 100644 index 0000000000..53bdbd04d0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-name-var-open-strict-strict.js @@ -0,0 +1,58 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Creation of new variable environment for the BindingIdentifier + parameter +info: | + [...] + 2. Let scope be the running execution context's LexicalEnvironment. + 3. Let funcEnv be NewDeclarativeEnvironment(scope). + 4. Let envRec be funcEnv's EnvironmentRecord. + 5. Let name be StringValue of BindingIdentifier. + 6. Perform envRec.CreateImmutableBinding(name, false). + 7. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, funcEnv, strict). + [...] +flags: [onlyStrict] +features: [generators] +---*/ + +var g = 'outside'; +var probeBefore = function() { return g; }; +var setBefore = function() { g = null; }; +var probeParams, setParams, probeBody, setBody; + +var func = function* g( + _ = ( + probeParams = function() { return g; }, + setParams = function() { g = null; } + ) + ) { + probeBody = function() { return g; }; + setBody = function() { g = null; }; +}; + +func().next(); + +assert.sameValue(probeBefore(), 'outside'); +setBefore(); +assert.sameValue(probeBefore(), null); + +assert.sameValue(probeParams(), func, 'inner binding value (from parameters)'); +assert.throws( + TypeError, setParams, 'inner binding rejects modification (from parameters)' +); +assert.sameValue( + probeParams(), func, 'inner binding is immutable (from parameters)' +); + +assert.sameValue(probeBody(), func, 'inner binding value (from body)'); +assert.throws( + TypeError, setBody, 'inner binding rejects modification (from body)' +); +assert.sameValue(probeBody(), func, 'inner binding is immutable (from body)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-close.js b/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-close.js new file mode 100644 index 0000000000..a1efd3aeec --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-close.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + sloppy direct evals in params introduce vars +info: | + [...] + 20. Else, + a. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared. + b. Let calleeEnv be the LexicalEnvironment of calleeContext. + c. Let env be NewDeclarativeEnvironment(calleeEnv). + d. Let envRec be env's EnvironmentRecord. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var x = 'outside'; +var probe1, probe2, probeBody; + +(function*( + _ = (eval('var x = "inside";'), probe1 = function() { return x; }), + __ = probe2 = function() { return x; } + ) { + probeBody = function() { return x; }; +}()).next(); + +assert.sameValue(probe1(), 'inside'); +assert.sameValue(probe2(), 'inside'); +assert.sameValue(probeBody(), 'inside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-open.js b/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-open.js new file mode 100644 index 0000000000..c37ce004f5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-param-elem-var-open.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + sloppy direct evals in params introduce vars +info: | + [...] + 20. Else, + a. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared. + b. Let calleeEnv be the LexicalEnvironment of calleeContext. + c. Let env be NewDeclarativeEnvironment(calleeEnv). + d. Let envRec be env's EnvironmentRecord. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var x = 'outside'; +var probe1, probe2; + +(function*( + _ = probe1 = function() { return x; }, + __ = (eval('var x = "inside";'), probe2 = function() { return x; }) + ) { +}().next()); + +assert.sameValue(probe1(), 'inside'); +assert.sameValue(probe2(), 'inside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-close.js b/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-close.js new file mode 100644 index 0000000000..0575cb1130 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-close.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + sloppy direct evals in params introduce vars +info: | + [...] + 20. Else, + a. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared. + b. Let calleeEnv be the LexicalEnvironment of calleeContext. + c. Let env be NewDeclarativeEnvironment(calleeEnv). + d. Let envRec be env's EnvironmentRecord. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var x = 'outside'; +var probeParam, probeBody; + +(function*( + ...[_ = (eval('var x = "inside";'), probeParam = function() { return x; })] + ) { + probeBody = function() { return x; } +}().next()); + +assert.sameValue(probeParam(), 'inside'); +assert.sameValue(probeBody(), 'inside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-open.js b/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-open.js new file mode 100644 index 0000000000..b7bf3a932b --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-param-rest-elem-var-open.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + sloppy direct evals in params introduce vars +info: | + [...] + 20. Else, + a. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared. + b. Let calleeEnv be the LexicalEnvironment of calleeContext. + c. Let env be NewDeclarativeEnvironment(calleeEnv). + d. Let envRec be env's EnvironmentRecord. + [...] +flags: [noStrict] +features: [generators] +---*/ + +var x = 'outside'; +var probe1, probe2; + +(function*( + _ = probe1 = function() { return x; }, + ...[__ = (eval('var x = "inside";'), probe2 = function() { return x; })] + ) { +}().next()); + +assert.sameValue(probe1(), 'inside'); +assert.sameValue(probe2(), 'inside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-close.js b/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-close.js new file mode 100644 index 0000000000..483dbff6aa --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-close.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + Disposal of variable environment for the function body +info: | + [...] + 26. If hasParameterExpressions is false, then + [...] + 27. Else, + a. NOTE A separate Environment Record is needed to ensure that closures + created by expressions in the formal parameter list do not have + visibility of declarations in the function body. + b. Let varEnv be NewDeclarativeEnvironment(env). + c. Let varEnvRec be varEnv's EnvironmentRecord. + d. Set the VariableEnvironment of calleeContext to varEnv. + e. Let instantiatedVarNames be a new empty List. + [...] +features: [generators] +---*/ + +var probe; + +// A parameter expression is necessary to trigger the creation of the scope +// under test. +(function*(_ = null) { + var x = 'inside'; + probe = function() { return x; }; +}().next()); + +var x = 'outside'; + +assert.sameValue(probe(), 'inside'); +assert.sameValue(x, 'outside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-open.js b/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-open.js new file mode 100644 index 0000000000..ed694dbcc8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/scope-paramsbody-var-open.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-functiondeclarationinstantiation +description: > + Creation of new variable environment for the function body (as distinct from + that for the function's parameters) +info: | + [...] + 26. If hasParameterExpressions is false, then + [...] + 27. Else, + a. NOTE A separate Environment Record is needed to ensure that closures + created by expressions in the formal parameter list do not have + visibility of declarations in the function body. + b. Let varEnv be NewDeclarativeEnvironment(env). + c. Let varEnvRec be varEnv's EnvironmentRecord. + d. Set the VariableEnvironment of calleeContext to varEnv. + e. Let instantiatedVarNames be a new empty List. + [...] +features: [generators] +---*/ + +var x = 'outside'; +var probeParams, probeBody; + +(function*(_ = probeParams = function() { return x; }) { + var x = 'inside'; + probeBody = function() { return x; }; +}().next()); + +assert.sameValue(probeParams(), 'outside'); +assert.sameValue(probeBody(), 'inside'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/shell.js b/js/src/tests/test262/language/expressions/generators/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/shell.js diff --git a/js/src/tests/test262/language/expressions/generators/unscopables-with-in-nested-fn.js b/js/src/tests/test262/language/expressions/generators/unscopables-with-in-nested-fn.js new file mode 100644 index 0000000000..32bb4ec495 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/unscopables-with-in-nested-fn.js @@ -0,0 +1,105 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/unscopables-with-in-nested-fn.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: Symbol.unscopables behavior across scope boundaries (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [globalThis, Symbol.unscopables, generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + ... + Let envRec be lex's EnvironmentRecord. + Let exists be ? envRec.HasBinding(name). + + HasBinding + + ... + If the withEnvironment flag of envRec is false, return true. + Let unscopables be ? Get(bindings, @@unscopables). + If Type(unscopables) is Object, then + Let blocked be ToBoolean(? Get(unscopables, N)). + If blocked is true, return false. + + (The `with` Statement) Runtime Semantics: Evaluation + + ... + Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + ... + +---*/ +let count = 0; +var v = 1; +globalThis[Symbol.unscopables] = { + v: true, +}; + +{ + count++; + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(x) { + (function() { + count++; + with (globalThis) { + count++; + assert.sameValue(v, 1, 'The value of `v` is 1'); + } + })(); + (function() { + count++; + var v = x; + with (globalThis) { + count++; + assert.sameValue(v, 10, 'The value of `v` is 10'); + v = 20; + } + assert.sameValue(v, 20, 'The value of `v` is 20'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + })(); + assert.sameValue(v, 1, 'The value of `v` is 1'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + callCount = callCount + 1; +}; + +ref(10).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + + count++; +} +assert.sameValue(count, 6, 'The value of `count` is 6'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/unscopables-with.js b/js/src/tests/test262/language/expressions/generators/unscopables-with.js new file mode 100644 index 0000000000..8a2fc94bba --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/unscopables-with.js @@ -0,0 +1,99 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/unscopables-with.case +// - src/function-forms/default/gen-func-expr.template +/*--- +description: Symbol.unscopables behavior across scope boundaries (generator function expression) +esid: sec-generator-function-definitions-runtime-semantics-evaluation +features: [globalThis, Symbol.unscopables, generators] +flags: [generated, noStrict] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + + ... + Let envRec be lex's EnvironmentRecord. + Let exists be ? envRec.HasBinding(name). + + HasBinding + + ... + If the withEnvironment flag of envRec is false, return true. + Let unscopables be ? Get(bindings, @@unscopables). + If Type(unscopables) is Object, then + Let blocked be ToBoolean(? Get(unscopables, N)). + If blocked is true, return false. + + (The `with` Statement) Runtime Semantics: Evaluation + + ... + Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + ... + +---*/ +let count = 0; +var v = 1; +globalThis[Symbol.unscopables] = { + v: true, +}; + +{ + count++; + +var callCount = 0; +// Stores a reference `ref` for case evaluation +var ref; +ref = function*(x) { + count++; + with (globalThis) { + count++; + assert.sameValue(v, undefined, 'The value of `v` is expected to equal `undefined`'); + } + count++; + var v = x; + with (globalThis) { + count++; + assert.sameValue(v, 10, 'The value of `v` is 10'); + v = 20; + } + assert.sameValue(v, 20, 'The value of `v` is 20'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + callCount = callCount + 1; +}; + +ref(10).next(); + +assert.sameValue(callCount, 1, 'generator function invoked exactly once'); + + count++; +} +assert.sameValue(count, 6, 'The value of `count` is 6'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/use-strict-with-non-simple-param.js b/js/src/tests/test262/language/expressions/generators/use-strict-with-non-simple-param.js new file mode 100644 index 0000000000..cc050aa63e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/use-strict-with-non-simple-param.js @@ -0,0 +1,23 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-static-semantics-early-errors +description: > + A SyntaxError is thrown if a generator contains a non-simple parameter list and a UseStrict directive. +info: | + Static Semantics: Early Errors + + It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and IsSimpleParameterList of FormalParameters is false. +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +var f = function*(a = 0) { + "use strict"; +} diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier-escaped.js b/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier-escaped.js new file mode 100644 index 0000000000..549138e659 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier-escaped.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + var yi\u0065ld; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier.js b/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier.js new file mode 100644 index 0000000000..a8bc34bbf7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-binding-identifier.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + var yield; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-function-expression-binding-identifier.js b/js/src/tests/test262/language/expressions/generators/yield-as-function-expression-binding-identifier.js new file mode 100644 index 0000000000..298f5807e4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-function-expression-binding-identifier.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` may be used as the binding identifier of a function expression + within generator bodies. +es6id: 14.1 +flags: [noStrict] +features: [generators] +---*/ + +var result; +var g = function*() { + (function yield() {}); +}; + +result = g().next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-generator-expression-binding-identifier.js b/js/src/tests/test262/language/expressions/generators/yield-as-generator-expression-binding-identifier.js new file mode 100644 index 0000000000..4145deb828 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-generator-expression-binding-identifier.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` is not a valid BindingIdentifier for GeneratorExpressions. +es6id: 12.1.1 +flags: [noStrict] +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +var g = function* yield() {}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-identifier-in-nested-function.js b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-in-nested-function.js new file mode 100644 index 0000000000..e7c621de11 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-in-nested-function.js @@ -0,0 +1,24 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` is not a reserved keyword within normal function bodies declared + within generator function bodies. +es6id: 12.1.1 +flags: [noStrict] +features: [generators] +---*/ + +var result; +var g = function*() { + function h() { + yield = 1; + } +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference-escaped.js b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference-escaped.js new file mode 100644 index 0000000000..9ad170619d --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference-escaped.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + void yi\u0065ld; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference.js b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference.js new file mode 100644 index 0000000000..37e9a13963 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-identifier-reference.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + void yield; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier-escaped.js b/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier-escaped.js new file mode 100644 index 0000000000..5c25acd7fa --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier-escaped.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier-escaped.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + yi\u0065ld: ; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier.js b/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier.js new file mode 100644 index 0000000000..430da1cdd2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-label-identifier.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier.case +// - src/generators/syntax/expression.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +var gen = function *() { + yield: ; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-literal-property-name.js b/js/src/tests/test262/language/expressions/generators/yield-as-literal-property-name.js new file mode 100644 index 0000000000..7f196e9413 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-literal-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. +es6id: 12.1.1 +features: [generators] +---*/ + +var result; +var g = function*() { + ({ get yield() { return 1 } }); +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-logical-or-expression.js b/js/src/tests/test262/language/expressions/generators/yield-as-logical-or-expression.js new file mode 100644 index 0000000000..4612254f39 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-logical-or-expression.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` expressions are not LogicalOrExpressions. +es6id: 12.1.1 +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + + +var g = function*() { + yield ? yield : yield; +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-parameter.js b/js/src/tests/test262/language/expressions/generators/yield-as-parameter.js new file mode 100644 index 0000000000..354507852c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-parameter.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as the binding identifier of a parameter. +es6id: 12.1.1 +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +var g = function*(yield) {}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-property-name.js b/js/src/tests/test262/language/expressions/generators/yield-as-property-name.js new file mode 100644 index 0000000000..b5a33bd0d2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. +es6id: 12.1.1 +features: [generators] +---*/ + +var result; +var g = function*() { + ({ yield: 1 }); +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-statement.js b/js/src/tests/test262/language/expressions/generators/yield-as-statement.js new file mode 100644 index 0000000000..84c918dd39 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-statement.js @@ -0,0 +1,47 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` is a valid statement within generator function bodies. +es6id: 14.4 +features: [generators] +---*/ + +var iter, result; +var g1 = function*() { yield; }; +var g2 = function*() { yield 1; }; + +iter = g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'Without right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'Without right-hand-eside: second result `done` flag' +); + +iter = g2(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'With right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'With right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'With right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'With right-hand-eside: second result `done` flag' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-as-yield-operand.js b/js/src/tests/test262/language/expressions/generators/yield-as-yield-operand.js new file mode 100644 index 0000000000..373ea81f6c --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-as-yield-operand.js @@ -0,0 +1,31 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` expressions may be used as the right-hand-side of other `yield` + expressions. +es6id: 14.4 +features: [generators] +---*/ + +var iter, result; +var g = function*() { + yield yield 1; +}; + +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, undefined, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Thid result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-identifier-non-strict.js b/js/src/tests/test262/language/expressions/generators/yield-identifier-non-strict.js new file mode 100644 index 0000000000..cb9b776051 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-identifier-non-strict.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-non-strict.case +// - src/generators/non-strict/expression.template +/*--- +description: Use of yield as a valid identifier in a function body inside a generator body in non strict mode (Generator expression - valid for non-strict only cases) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated, noStrict] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + +---*/ + +var callCount = 0; + +var gen = function *() { + callCount += 1; + return (function(arg) { + var yield = arg + 1; + return yield; + }(yield)) +}; + +var iter = gen(); + +var item = iter.next(); + +assert.sameValue(item.done, false); +assert.sameValue(item.value, undefined); + +item = iter.next(42); + +assert.sameValue(item.done, true); +assert.sameValue(item.value, 43); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-non-strict.js b/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-non-strict.js new file mode 100644 index 0000000000..c2b707c5a3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-non-strict.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-spread-non-strict.case +// - src/generators/non-strict/expression.template +/*--- +description: Mixed use of object spread and yield as a valid identifier in a function body inside a generator body in non strict mode (Generator expression - valid for non-strict only cases) +esid: prod-GeneratorExpression +features: [Symbol, object-spread, generators] +flags: [generated, noStrict] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +var s = Symbol('s'); + +var callCount = 0; + +var gen = function *() { + callCount += 1; + yield { + ...yield yield, + ...(function(arg) { + var yield = arg; + return {...yield}; + }(yield)), + ...yield, + } +}; + +var iter = gen(); + +var iter = gen(); + +iter.next(); +iter.next(); +iter.next({ x: 10, a: 0, b: 0, [s]: 1 }); +iter.next({ y: 20, a: 1, b: 1, [s]: 42 }); +var item = iter.next({ z: 30, b: 2 }); + +var value = item.value; + +assert.sameValue(item.done, false); +assert.sameValue(value.x, 10); +assert.sameValue(value.y, 20); +assert.sameValue(value.z, 30); +assert.sameValue(value.a, 1); +assert.sameValue(value.b, 2); +assert.sameValue(value[s], 42); +assert(Object.hasOwnProperty.call(value, s)); +assert.sameValue(Object.keys(value).length, 5); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-strict-strict.js b/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-strict-strict.js new file mode 100644 index 0000000000..5b37b6248e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-identifier-spread-strict-strict.js @@ -0,0 +1,46 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-spread-strict.case +// - src/generators/default/expression.template +/*--- +description: It's an early error if the AssignmentExpression is a function body with yield as an identifier in strict mode. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [object-spread, generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +var gen = function *() { + callCount += 1; + return { + ...(function() { + var yield; + throw new Test262Error(); + }()), + } +}; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/expressions/generators/yield-identifier-strict-strict.js b/js/src/tests/test262/language/expressions/generators/yield-identifier-strict-strict.js new file mode 100644 index 0000000000..6193f0d815 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-identifier-strict-strict.js @@ -0,0 +1,37 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-strict.case +// - src/generators/default/expression.template +/*--- +description: It's an early error if the generator body has another function body with yield as an identifier in strict mode. (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +var gen = function *() { + callCount += 1; + (function() { + var yield; + throw new Test262Error(); + }()) +}; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/expressions/generators/yield-newline.js b/js/src/tests/test262/language/expressions/generators/yield-newline.js new file mode 100644 index 0000000000..c257a1c54e --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-newline.js @@ -0,0 +1,27 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Newlines terminate `yield` expressions. +es6id: 14.4 +features: [generators] +---*/ + +var iter, result; +var g = function*() { + yield + 1 +}; + +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-spread-arr-multiple.js b/js/src/tests/test262/language/expressions/generators/yield-spread-arr-multiple.js new file mode 100644 index 0000000000..48c60690ea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-spread-arr-multiple.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-multiple.case +// - src/generators/default/expression.template +/*--- +description: Use yield value in a array spread position (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +includes: [compareArray.js] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] + +---*/ +var arr = ['a', 'b', 'c']; +var item; + +var callCount = 0; + +var gen = function *() { + callCount += 1; + yield [...yield yield]; +}; + +var iter = gen(); + +iter.next(false); +item = iter.next(['a', 'b', 'c']); +item = iter.next(item.value); + +assert(compareArray(item.value, arr)); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-spread-arr-single.js b/js/src/tests/test262/language/expressions/generators/yield-spread-arr-single.js new file mode 100644 index 0000000000..41bcc723ec --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-spread-arr-single.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-single.case +// - src/generators/default/expression.template +/*--- +description: Use yield value in a array spread position (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [generators] +flags: [generated] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] +---*/ +var arr = ['a', 'b', 'c']; + +var callCount = 0; + +var gen = function *() { + callCount += 1; + yield [...yield]; +}; + +var iter = gen(); + +iter.next(false); +var item = iter.next(arr); +var value = item.value; + +assert.notSameValue(value, arr, 'value is a new array'); +assert(Array.isArray(value), 'value is an Array exotic object'); +assert.sameValue(value.length, 3) +assert.sameValue(value[0], 'a'); +assert.sameValue(value[1], 'b'); +assert.sameValue(value[2], 'c'); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-spread-obj.js b/js/src/tests/test262/language/expressions/generators/yield-spread-obj.js new file mode 100644 index 0000000000..dec87332ea --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-spread-obj.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-obj.case +// - src/generators/default/expression.template +/*--- +description: Use yield value in a object spread position (Unnamed generator expression) +esid: prod-GeneratorExpression +features: [object-spread, generators] +flags: [generated] +info: | + 14.4 Generator Function Definitions + + GeneratorExpression: + function * BindingIdentifier opt ( FormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ + +var callCount = 0; + +var gen = function *() { + callCount += 1; + yield { + ...yield, + y: 1, + ...yield yield, + }; +}; + +var iter = gen(); + +iter.next(); +iter.next({ x: 42 }); +iter.next({ x: 'lol' }); +var item = iter.next({ y: 39 }); + +assert.sameValue(item.value.x, 42); +assert.sameValue(item.value.y, 39); +assert.sameValue(Object.keys(item.value).length, 2); +assert.sameValue(item.done, false); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-star-after-newline.js b/js/src/tests/test262/language/expressions/generators/yield-star-after-newline.js new file mode 100644 index 0000000000..a6556ee700 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-star-after-newline.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + A newline may not precede the `*` token in a `yield` expression. +es6id: 14.4 +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +var g = function*() { + yield + * 1 +}; diff --git a/js/src/tests/test262/language/expressions/generators/yield-star-before-newline.js b/js/src/tests/test262/language/expressions/generators/yield-star-before-newline.js new file mode 100644 index 0000000000..abed9e0c90 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-star-before-newline.js @@ -0,0 +1,22 @@ +// 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 right-hand side of a `yield *` expression may appear on a new line. +es6id: 14.4 +features: [generators] +---*/ + +var result; +var g = function*() { + yield * + g2(); +}; +var g2 = function*() {}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/generators/yield-weak-binding.js b/js/src/tests/test262/language/expressions/generators/yield-weak-binding.js new file mode 100644 index 0000000000..9a32e8d234 --- /dev/null +++ b/js/src/tests/test262/language/expressions/generators/yield-weak-binding.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `yield` expressions bind weakly +es6id: 14.4 +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +var g = function*() { yield 3 + yield 4; }; |