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/expressions/new.target | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.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/expressions/new.target')
16 files changed, 573 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/new.target/asi.js b/js/src/tests/test262/language/expressions/new.target/asi.js new file mode 100644 index 0000000000..e0244833a9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/asi.js @@ -0,0 +1,69 @@ +// 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-meta-properties-runtime-semantics-evaluation +es6id: 12.3.8.1 +description: NewTarget is composed of three distinct tokens +features: [new.target] +---*/ + +var newTarget = null; + +var withSpaces = function() { + newTarget = new . target; +}; + +withSpaces(); +assert.sameValue(newTarget, undefined, 'tokens seperated by whitespace'); + +new withSpaces(); +assert.sameValue(newTarget, withSpaces, 'tokens separateed by whitespace'); + +newTarget = null; + +var withLineBreaks = function() { + newTarget = new + +. + +target; +}; + +withLineBreaks(); +assert.sameValue(newTarget, undefined, 'tokens seperated by line breaks'); + +new withLineBreaks(); +assert.sameValue(newTarget, withLineBreaks, 'tokens seperated by line breaks'); + +var withSLDC = function() { + newTarget = new/* */./* */target; +}; + +withSLDC(); +assert.sameValue( + newTarget, undefined, 'tokens separated by SingleLineDelimitedComments' +); + +new withSLDC(); +assert.sameValue( + newTarget, withSLDC, 'tokens separated by SingleLineDelimitedComments' +); + + +var withMLC = function() { + newTarget = new/* + */./* + */target; +}; + +withMLC(); +assert.sameValue( + newTarget, undefined, 'tokens separated by MultiLineComments' +); + +new withMLC(); +assert.sameValue( + newTarget, withMLC, 'tokens separated by MultiLineComments' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/browser.js b/js/src/tests/test262/language/expressions/new.target/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/browser.js diff --git a/js/src/tests/test262/language/expressions/new.target/escaped-new.js b/js/src/tests/test262/language/expressions/new.target/escaped-new.js new file mode 100644 index 0000000000..18410c8955 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/escaped-new.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-grammar-notation +description: > + The `new` keyword must not contain Unicode escape sequences. +info: | + Terminal symbols are shown + in fixed width font, both in the productions of the grammars and throughout this + specification whenever the text directly refers to such a terminal symbol. These + are to appear in a script exactly as written. All terminal symbol code points + specified in this way are to be understood as the appropriate Unicode code points + from the Basic Latin range, as opposed to any similar-looking code points from + other Unicode ranges. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + n\u0065w.target; +} diff --git a/js/src/tests/test262/language/expressions/new.target/escaped-target.js b/js/src/tests/test262/language/expressions/new.target/escaped-target.js new file mode 100644 index 0000000000..7a7d996ee9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/escaped-target.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-grammar-notation +description: > + The `target` contextual keyword must not contain Unicode escape sequences. +info: | + Terminal symbols are shown + in fixed width font, both in the productions of the grammars and throughout this + specification whenever the text directly refers to such a terminal symbol. These + are to appear in a script exactly as written. All terminal symbol code points + specified in this way are to be understood as the appropriate Unicode code points + from the Basic Latin range, as opposed to any similar-looking code points from + other Unicode ranges. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + new.t\u0061rget; +} diff --git a/js/src/tests/test262/language/expressions/new.target/shell.js b/js/src/tests/test262/language/expressions/new.target/shell.js new file mode 100644 index 0000000000..ae18ad584d --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/shell.js @@ -0,0 +1,113 @@ +// GENERATED, DO NOT EDIT +// file: asyncHelpers.js +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of assertion and wrapper functions for testing asynchronous built-ins. +defines: [asyncTest] +---*/ + +function asyncTest(testFunc) { + if (!Object.hasOwn(globalThis, "$DONE")) { + throw new Test262Error("asyncTest called without async flag"); + } + if (typeof testFunc !== "function") { + $DONE(new Test262Error("asyncTest called with non-function argument")); + return; + } + try { + testFunc().then( + function () { + $DONE(); + }, + function (error) { + $DONE(error); + } + ); + } catch (syncError) { + $DONE(syncError); + } +} + +assert.throwsAsync = async function (expectedErrorConstructor, func, message) { + var innerThenable; + if (message === undefined) { + message = ""; + } else { + message += " "; + } + if (typeof func === "function") { + try { + innerThenable = func(); + if ( + innerThenable === null || + typeof innerThenable !== "object" || + typeof innerThenable.then !== "function" + ) { + message += + "Expected to obtain an inner promise that would reject with a" + + expectedErrorConstructor.name + + " but result was not a thenable"; + throw new Test262Error(message); + } + } catch (thrown) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise"; + throw new Test262Error(message); + } + } else { + message += + "assert.throwsAsync called with an argument that is not a function"; + throw new Test262Error(message); + } + + try { + return innerThenable.then( + function () { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but no exception was thrown at all"; + throw new Test262Error(message); + }, + function (thrown) { + var expectedName, actualName; + if (typeof thrown !== "object" || thrown === null) { + message += "Thrown value was not an object!"; + throw new Test262Error(message); + } else if (thrown.constructor !== expectedErrorConstructor) { + expectedName = expectedErrorConstructor.name; + actualName = thrown.constructor.name; + if (expectedName === actualName) { + message += + "Expected a " + + expectedName + + " but got a different error constructor with the same name"; + } else { + message += + "Expected a " + expectedName + " but got a " + actualName; + } + throw new Test262Error(message); + } + } + ); + } catch (thrown) { + if (typeof thrown !== "object" || thrown === null) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but innerThenable synchronously threw a value that was not an object "; + } else { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but a " + + thrown.constructor.name + + " was thrown synchronously"; + } + throw new Test262Error(message); + } +}; diff --git a/js/src/tests/test262/language/expressions/new.target/unary-expr.js b/js/src/tests/test262/language/expressions/new.target/unary-expr.js new file mode 100644 index 0000000000..a9302ae43e --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/unary-expr.js @@ -0,0 +1,33 @@ +// |reftest| async +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: prod-UnaryExpression +description: > + While increments and decrements are restricted to use with NewTarget, + other unary operators should not throw SyntaxError. +info: | + UnaryExpression[Yield, Await]: + UpdateExpression[?Yield, ?Await]: + LeftHandSideExpression[?Yield, ?Await]: + NewExpression[?Yield, ?Await]: + MemberExpression[Yield, Await]: + MetaProperty: + NewTarget +features: [new.target, async-functions] +flags: [async] +includes: [asyncHelpers.js] +---*/ + +(function() { assert.sameValue(delete (new.target), true); })(); +(function() { assert.sameValue(void new.target, undefined); })(); +new function() { assert.sameValue(typeof new.target, 'function'); }; +new function() { assert.sameValue(+(new.target), NaN); }; +(function() { assert.sameValue(-(new.target), NaN); })(); +new function() { assert.sameValue(~new.target, -1); }; +(function() { assert.sameValue(!new.target, true); })(); +new function() { assert.sameValue(delete void typeof +-~!(new.target), true); }; + +asyncTest(async function() { + assert.sameValue(await new.target, undefined); +}); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-call.js b/js/src/tests/test262/language/expressions/new.target/value-via-call.js new file mode 100644 index 0000000000..29483d17a4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-call.js @@ -0,0 +1,25 @@ +// 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-function-calls-runtime-semantics-evaluation +es6id: 12.3.4.1 +description: Value when invoked via CallExpression +info: | + CallExpression : MemberExpressionArguments + + [...] + 8. Return ? EvaluateDirectCall(func, thisValue, Arguments, tailCall). +features: [new.target] +---*/ + +var newTarget = null; + +function f() { + newTarget = new.target; +} + +f(); + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-fpapply.js b/js/src/tests/test262/language/expressions/new.target/value-via-fpapply.js new file mode 100644 index 0000000000..603a1a700d --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-fpapply.js @@ -0,0 +1,23 @@ +// 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-function.prototype.apply +es6id: 19.2.3.1 +description: Value when invoked via `Function.prototype.apply` +info: | + [...] + 5. Return ? Call(func, thisArg, argList). +features: [new.target] +---*/ + +var newTarget = null; + +function f() { + newTarget = new.target; +} + +f.apply({}); + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-fpcall.js b/js/src/tests/test262/language/expressions/new.target/value-via-fpcall.js new file mode 100644 index 0000000000..9e9c63aea6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-fpcall.js @@ -0,0 +1,23 @@ +// 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-function.prototype.call +es6id: 19.2.3.3 +description: Value when invoked via `Function.prototype.call` +info: | + [...] + 5. Return ? Call(func, thisArg, argList). +features: [new.target] +---*/ + +var newTarget = null; + +function f() { + newTarget = new.target; +} + +f.call({}); + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-member.js b/js/src/tests/test262/language/expressions/new.target/value-via-member.js new file mode 100644 index 0000000000..6c668a747f --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-member.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-property-accessors-runtime-semantics-evaluation +es6id: 12.3.2.1 +description: Value when invoked via MemberExpression +info: | + MemberExpression:MemberExpression.IdentifierName + + [...] + 6. Return a value of type Reference whose base value component is bv, whose + referenced name component is propertyNameString, and whose strict + reference flag is strict. + + 13.5.1 Runtime Semantics: Evaluation + + ExpressionStatement : Expression ; + + 1. Let exprRef be the result of evaluating Expression. + 2. Return ? GetValue(exprRef). +features: [new.target] +---*/ + +var newTarget = null; + +var obj = { + get m() { + newTarget = new.target; + } +}; + +obj.m; + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-new.js b/js/src/tests/test262/language/expressions/new.target/value-via-new.js new file mode 100644 index 0000000000..795e9dc0e8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-new.js @@ -0,0 +1,42 @@ +// 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-new-operator-runtime-semantics-evaluation +es6id: 12.3.3.1 +description: Value when invoked via NewExpression +info: | + NewExpression:newNewExpression + + 1. Return ? EvaluateNew(NewExpression, empty). + + MemberExpression:newMemberExpressionArguments + + 2. Return ? EvaluateNew(MemberExpression, Arguments). + + 12.3.3.1.1 Runtime Semantics: EvaluateNew + + [...] + 8. Return ? Construct(constructor, argList). + + 7.3.13 Construct (F [ , argumentsList [ , newTarget ]]) + + 1. If newTarget was not passed, let newTarget be F. +features: [new.target] +---*/ + +var newTarget = null; +function f() { + newTarget = new.target; +} + +new f; + +assert.sameValue(newTarget, f, 'Invoked without Arguments'); + +newTarget = null; + +new f(); + +assert.sameValue(newTarget, f, 'Invoked with Arguments'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-reflect-apply.js b/js/src/tests/test262/language/expressions/new.target/value-via-reflect-apply.js new file mode 100644 index 0000000000..f811818cbc --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-reflect-apply.js @@ -0,0 +1,23 @@ +// 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-reflect.apply +es6id: 26.1.1 +description: Value when invoked via `Reflect.apply` +info: | + [...] + 5. Return ? Call(target, thisArgument, args). +features: [new.target, Reflect] +---*/ + +var newTarget = null; + +function f() { + newTarget = new.target; +} + +Reflect.apply(f, {}, []); + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-reflect-construct.js b/js/src/tests/test262/language/expressions/new.target/value-via-reflect-construct.js new file mode 100644 index 0000000000..6e157d465b --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-reflect-construct.js @@ -0,0 +1,30 @@ +// 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-reflect.construct +es6id: 26.1.2 +description: Value when invoked via `Reflect.construct` +info: | + [...] + 2. If newTarget is not present, let newTarget be target. + [...] + 5. Return ? Construct(target, args, newTarget). +features: [new.target, Reflect, Reflect.construct] +---*/ + +var customNewTarget = function() {}; +var newTarget = null; + +function f() { + newTarget = new.target; +} + +Reflect.construct(f, []); + +assert.sameValue(newTarget, f, 'NewTarget unspecified'); + +Reflect.construct(f, [], customNewTarget); + +assert.sameValue(newTarget, customNewTarget, 'NewTarget explicitly defined'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-super-call.js b/js/src/tests/test262/language/expressions/new.target/value-via-super-call.js new file mode 100644 index 0000000000..730f086f21 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-super-call.js @@ -0,0 +1,43 @@ +// 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-super-keyword-runtime-semantics-evaluation +es6id: 12.3.5.1 +description: Value when invoked via SuperCall +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + [...] + 6. Let result be ? Construct(func, argList, newTarget). + [...] +features: [class, new.target] +---*/ + +var baseNewTarget, parentNewTarget; + +class Base { + constructor() { + baseNewTarget = new.target; + } +} + +class Parent extends Base { + constructor() { + parentNewTarget = new.target; + super(); + } +} + +class Child extends Parent { + constructor() { + super(); + } +} + +new Child(); + +assert.sameValue(parentNewTarget, Child, 'within "parent" constructor'); +assert.sameValue(baseNewTarget, Child, 'within "base" constructor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-super-property.js b/js/src/tests/test262/language/expressions/new.target/value-via-super-property.js new file mode 100644 index 0000000000..e19b1e2c55 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-super-property.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-super-keyword-runtime-semantics-evaluation +es6id: 12.3.5.1 +description: Value when invoked via SuperCall +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + [...] + 6. Let result be ? Construct(func, argList, newTarget). + [...] +features: [class, new.target] +---*/ + +var newTarget = null; + +class Parent { + get attr() { + newTarget = new.target; + } +} + +class Child extends Parent { + constructor() { + super(); + super.attr; + } +} + +new Child(); + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/new.target/value-via-tagged-template.js b/js/src/tests/test262/language/expressions/new.target/value-via-tagged-template.js new file mode 100644 index 0000000000..928af96d14 --- /dev/null +++ b/js/src/tests/test262/language/expressions/new.target/value-via-tagged-template.js @@ -0,0 +1,25 @@ +// 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-tagged-templates-runtime-semantics-evaluation +es6id: 12.3.7.1 +description: Value when invoked via tagged template +info: | + MemberExpression : MemberExpression TemplateLiteral + + [...] + 4. Return ? EvaluateCall(tagRef, TemplateLiteral, tailCall). +features: [new.target, template] +---*/ + +var newTarget = null; + +function f() { + newTarget = new.target; +} + +f``; + +assert.sameValue(newTarget, undefined); + +reportCompare(0, 0); |