diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/statements/class/gen-method | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/statements/class/gen-method')
39 files changed, 2293 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/class/gen-method/array-destructuring-param-strict-body.js b/js/src/tests/test262/language/statements/class/gen-method/array-destructuring-param-strict-body.js new file mode 100644 index 0000000000..e6d0cf99a6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/array-destructuring-param-strict-body.js @@ -0,0 +1,157 @@ +// |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/cls-decl-gen-meth.template +/*--- +description: ArrayBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method([element]) { + "use strict"; + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/browser.js b/js/src/tests/test262/language/statements/class/gen-method/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/browser.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-abrupt.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-abrupt.js new file mode 100644 index 0000000000..1b084ac1b8 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-abrupt.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-abrupt.case +// - src/function-forms/error/cls-decl-gen-meth.template +/*--- +description: Abrupt completion returned by evaluation of initializer (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(_ = (function() { throw new Test262Error(); }())) { + + callCount = callCount + 1; + } +} + +assert.throws(Test262Error, function() { + C.prototype.method(); +}); +assert.sameValue(callCount, 0, 'method body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-arg-val-not-undefined.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-arg-val-not-undefined.js new file mode 100644 index 0000000000..c7e02f7c79 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-arg-val-not-undefined.js @@ -0,0 +1,112 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-not-undefined.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: Use of initializer when argument value is not `undefined` (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(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; + } +} + +C.prototype.method(false, '', NaN, 0, null, obj).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method 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/statements/class/gen-method/dflt-params-arg-val-undefined.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-arg-val-undefined.js new file mode 100644 index 0000000000..1b3131ac20 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-arg-val-undefined.js @@ -0,0 +1,95 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-undefined.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: Use of initializer when argument value is `undefined` (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(fromLiteral = 23, fromExpr = 45, fromHole = 99) { + assert.sameValue(fromLiteral, 23); + assert.sameValue(fromExpr, 45); + assert.sameValue(fromHole, 99); + callCount = callCount + 1; + } +} + +C.prototype.method(undefined, void 0).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-duplicates.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-duplicates.js new file mode 100644 index 0000000000..55875096b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-duplicates.js @@ -0,0 +1,86 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-duplicates.case +// - src/function-forms/syntax/cls-decl-gen-meth.template +/*--- +description: It is a Syntax Error if BoundNames of FormalParameters contains any duplicate elements. (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method(x = 0, x) { + + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-later.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-later.js new file mode 100644 index 0000000000..0551964520 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-later.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-later.case +// - src/function-forms/error/cls-decl-gen-meth.template +/*--- +description: Referencing a parameter that occurs later in the ParameterList (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(x = y, y) { + + callCount = callCount + 1; + } +} + +assert.throws(ReferenceError, function() { + C.prototype.method(); +}); +assert.sameValue(callCount, 0, 'method body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-prior.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-prior.js new file mode 100644 index 0000000000..f7dd334fd4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-prior.js @@ -0,0 +1,92 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-prior.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: Referencing a parameter that occurs earlier in the ParameterList (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(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; + } +} + +C.prototype.method(3).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-self.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-self.js new file mode 100644 index 0000000000..aac84e6fa1 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-ref-self.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-self.case +// - src/function-forms/error/cls-decl-gen-meth.template +/*--- +description: Referencing a parameter from within its own initializer (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(x = x) { + + callCount = callCount + 1; + } +} + +assert.throws(ReferenceError, function() { + C.prototype.method(); +}); +assert.sameValue(callCount, 0, 'method body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-rest.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-rest.js new file mode 100644 index 0000000000..1268cbb8d1 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-rest.js @@ -0,0 +1,90 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-rest.case +// - src/function-forms/syntax/cls-decl-gen-meth.template +/*--- +description: RestParameter does not support an initializer (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [default-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method(...x = []) { + + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/dflt-params-trailing-comma.js b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-trailing-comma.js new file mode 100644 index 0000000000..23ce717020 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/dflt-params-trailing-comma.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-trailing-comma.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: A trailing comma should not increase the respective length, using default parameters (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(a, b = 39,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; + } +} + +C.prototype.method(42, undefined, 1).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); + +assert.sameValue(ref.length, 1, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/browser.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/browser.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-forbidden-ext-direct-access-prop-arguments.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-forbidden-ext-direct-access-prop-arguments.js new file mode 100644 index 0000000000..d3eb48a9ba --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-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/cls-decl-gen-meth.template +/*--- +description: Forbidden extension, f.arguments (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [class, generators] +flags: [generated, noStrict] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + + 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; +class C { + *method() { + assert.sameValue(this.method.hasOwnProperty("arguments"), false); + callCount++; + } +} + +C.prototype.method().next(); +assert.sameValue(callCount, 1, 'method body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-forbidden-ext-direct-access-prop-caller.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-forbidden-ext-direct-access-prop-caller.js new file mode 100644 index 0000000000..a9a9fa54f7 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/cls-decl-gen-meth-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/cls-decl-gen-meth.template +/*--- +description: Forbidden extension, o.caller (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [class, generators] +flags: [generated, noStrict] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + + 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; +class C { + *method() { + assert.sameValue(this.method.hasOwnProperty("caller"), false); + callCount++; + } +} + +C.prototype.method().next(); +assert.sameValue(callCount, 1, 'method body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/shell.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b1/shell.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/browser.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/browser.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-get.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-get.js new file mode 100644 index 0000000000..c63b93776a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-get.js @@ -0,0 +1,63 @@ +// 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/cls-decl-gen-meth.template +/*--- +description: Forbidden extension, o.caller (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [class, generators] +flags: [generated, noStrict] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + + 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; +class C { + *method() { + /* implicit 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 + 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, this.method); + } + callCount++; + } +} + +C.prototype.method().next(); +assert.sameValue(callCount, 1, 'method body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-value.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-value.js new file mode 100644 index 0000000000..6998ef9360 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-own-prop-caller-value.js @@ -0,0 +1,63 @@ +// 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/cls-decl-gen-meth.template +/*--- +description: Forbidden extension, o.caller (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [class, generators] +flags: [generated, noStrict] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + + 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; +class C { + *method() { + /* implicit 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 + 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, this.method); + } + callCount++; + } +} + +C.prototype.method().next(); +assert.sameValue(callCount, 1, 'method body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-prop-caller.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-prop-caller.js new file mode 100644 index 0000000000..e6305a593c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/cls-decl-gen-meth-forbidden-ext-indirect-access-prop-caller.js @@ -0,0 +1,63 @@ +// 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/cls-decl-gen-meth.template +/*--- +description: Forbidden extension, o.caller (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [class, generators] +flags: [generated, noStrict] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + + 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; +class C { + *method() { + /* implicit 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 + 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, this.method); + } + callCount++; + } +} + +C.prototype.method().next(); +assert.sameValue(callCount, 1, 'method body evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/shell.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/b2/shell.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/browser.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/browser.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/shell.js b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/forbidden-ext/shell.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/object-destructuring-param-strict-body.js b/js/src/tests/test262/language/statements/class/gen-method/object-destructuring-param-strict-body.js new file mode 100644 index 0000000000..416e2791eb --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/object-destructuring-param-strict-body.js @@ -0,0 +1,157 @@ +// |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/cls-decl-gen-meth.template +/*--- +description: ObjectBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method({property}) { + "use strict"; + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-multiple.js b/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-multiple.js new file mode 100644 index 0000000000..e59b4461f9 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-multiple.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-multiple.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: A trailing comma should not increase the respective length, using multiple parameters (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(a, b,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; + } +} + +C.prototype.method(42, 39, 1).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); + +assert.sameValue(ref.length, 2, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-single.js b/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-single.js new file mode 100644 index 0000000000..0b7c6fddb6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/params-trailing-comma-single.js @@ -0,0 +1,86 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-single.case +// - src/function-forms/default/cls-decl-gen-meth.template +/*--- +description: A trailing comma should not increase the respective length, using a single parameter (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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; +class C { + *method(a,) { + assert.sameValue(a, 42); + callCount = callCount + 1; + } +} + +C.prototype.method(42, 39).next(); + +// Stores a reference `ref` for case evaluation +var ref = C.prototype.method; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); + +assert.sameValue(ref.length, 1, 'length is properly set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/gen-method/rest-param-strict-body.js b/js/src/tests/test262/language/statements/class/gen-method/rest-param-strict-body.js new file mode 100644 index 0000000000..ad3b876fec --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/rest-param-strict-body.js @@ -0,0 +1,157 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/rest-param-strict-body.case +// - src/function-forms/syntax/cls-decl-gen-meth.template +/*--- +description: RestParameter and Use Strict Directive are not allowed to coexist for the same function. (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [rest-parameters, generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method(a,...rest) { + "use strict"; + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/rest-params-trailing-comma-early-error.js b/js/src/tests/test262/language/statements/class/gen-method/rest-params-trailing-comma-early-error.js new file mode 100644 index 0000000000..35fbeeb2f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/rest-params-trailing-comma-early-error.js @@ -0,0 +1,83 @@ +// |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/cls-decl-gen-meth.template +/*--- +description: It's a syntax error if a FunctionRestParameter is followed by a trailing comma (class expression method) +esid: sec-class-definitions-runtime-semantics-evaluation +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, 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(); + +class C { + *method(...a,) { + + } +} diff --git a/js/src/tests/test262/language/statements/class/gen-method/shell.js b/js/src/tests/test262/language/statements/class/gen-method/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/shell.js diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier-escaped.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier-escaped.js new file mode 100644 index 0000000000..17ecc0c5d4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier-escaped.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier-escaped.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + var yi\u0065ld; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier.js new file mode 100644 index 0000000000..76e2b87f32 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-binding-identifier.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-binding-identifier.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + var yield; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference-escaped.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference-escaped.js new file mode 100644 index 0000000000..670dc2e705 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference-escaped.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference-escaped.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + void yi\u0065ld; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference.js new file mode 100644 index 0000000000..b3701c7e7d --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-identifier-reference.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-identifier-reference.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + void yield; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier-escaped.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier-escaped.js new file mode 100644 index 0000000000..f8173bc45f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier-escaped.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier-escaped.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + yi\u0065ld: ; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier.js b/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier.js new file mode 100644 index 0000000000..ef0b7e2ca6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-as-label-identifier.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/generators/yield-as-label-identifier.case +// - src/generators/syntax/class-decl-method.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + +class C { *gen() { + yield: ; +}} diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-spread-strict-strict.js b/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-spread-strict-strict.js new file mode 100644 index 0000000000..66078a5fb6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-spread-strict-strict.js @@ -0,0 +1,54 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-spread-strict.case +// - src/generators/default/class-decl-method.template +/*--- +description: It's an early error if the AssignmentExpression is a function body with yield as an identifier in strict mode. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [object-spread, generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +class C { *gen() { + callCount += 1; + return { + ...(function() { + var yield; + throw new Test262Error(); + }()), + } +}} + +var gen = C.prototype.gen; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-strict-strict.js b/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-strict-strict.js new file mode 100644 index 0000000000..ba5630356b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-identifier-strict-strict.js @@ -0,0 +1,45 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/generators/yield-identifier-strict.case +// - src/generators/default/class-decl-method.template +/*--- +description: It's an early error if the generator body has another function body with yield as an identifier in strict mode. (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + +---*/ +$DONOTEVALUATE(); + +var callCount = 0; + +class C { *gen() { + callCount += 1; + (function() { + var yield; + throw new Test262Error(); + }()) +}} + +var gen = C.prototype.gen; + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/class/gen-method/yield-spread-arr-multiple.js b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-arr-multiple.js new file mode 100644 index 0000000000..5fc963769b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-arr-multiple.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-multiple.case +// - src/generators/default/class-decl-method.template +/*--- +description: Use yield value in a array spread position (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +includes: [compareArray.js] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] + +---*/ +var arr = ['a', 'b', 'c']; +var item; + +var callCount = 0; + +class C { *gen() { + callCount += 1; + yield [...yield yield]; +}} + +var gen = C.prototype.gen; + +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/statements/class/gen-method/yield-spread-arr-single.js b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-arr-single.js new file mode 100644 index 0000000000..d93a8847dc --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-arr-single.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-arr-single.case +// - src/generators/default/class-decl-method.template +/*--- +description: Use yield value in a array spread position (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [generators] +flags: [generated] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] +---*/ +var arr = ['a', 'b', 'c']; + +var callCount = 0; + +class C { *gen() { + callCount += 1; + yield [...yield]; +}} + +var gen = C.prototype.gen; + +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/statements/class/gen-method/yield-spread-obj.js b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-obj.js new file mode 100644 index 0000000000..54171419bd --- /dev/null +++ b/js/src/tests/test262/language/statements/class/gen-method/yield-spread-obj.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/generators/yield-spread-obj.case +// - src/generators/default/class-decl-method.template +/*--- +description: Use yield value in a object spread position (Generator method as a ClassDeclaration element) +esid: prod-GeneratorMethod +features: [object-spread, generators] +flags: [generated] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ + +var callCount = 0; + +class C { *gen() { + callCount += 1; + yield { + ...yield, + y: 1, + ...yield yield, + }; +}} + +var gen = C.prototype.gen; + +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); |