diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/AsyncFunction | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/AsyncFunction')
20 files changed, 451 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-construct.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-construct.js new file mode 100644 index 0000000000..dbae1415b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-construct.js @@ -0,0 +1,33 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor +description: > + %AsyncFunction% creates functions with or without new and handles arguments + similarly to functions. +---*/ + +var AsyncFunction = async function foo() {}.constructor; +var fn; + +fn = AsyncFunction("a", "await 1;"); +assert.sameValue(fn.length, 1, "length with 1 argument, call"); + +fn = AsyncFunction("a,b", "await 1;"); +assert.sameValue(fn.length, 2, "length with 2 arguments in one, call"); + +fn = AsyncFunction("a", "b", "await 1;"); +assert.sameValue(fn.length, 2, "length with 2 arguments, call"); + +fn = new AsyncFunction("a", "await 1;"); +assert.sameValue(fn.length, 1, "length with 1 argument, construct"); + +fn = new AsyncFunction("a,b", "await 1;"); +assert.sameValue(fn.length, 2, "length with 2 arguments in one, construct"); + +fn = new AsyncFunction("a", "b", "await 1;"); +assert.sameValue(fn.length, 2, "length with 2 arguments, construct"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-extensible.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-extensible.js new file mode 100644 index 0000000000..a069166cd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-extensible.js @@ -0,0 +1,15 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: > + %AsyncFunction% is extensible +---*/ + +var AsyncFunction = async function() {}.constructor; +AsyncFunction.x = 1; +assert.sameValue(AsyncFunction.x, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-subclass.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-subclass.js new file mode 100644 index 0000000000..ea84be36e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-is-subclass.js @@ -0,0 +1,16 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor +description: > + %AsyncFunction% is a subclass of Function +---*/ +async function foo() {}; +var AsyncFunction = foo.constructor; +assert.sameValue(Object.getPrototypeOf(AsyncFunction), Function, "Prototype of constructor is Function"); +assert.sameValue(Object.getPrototypeOf(AsyncFunction.prototype), Function.prototype, "Prototype of constructor's prototype is Function.prototype"); +assert(foo instanceof Function, 'async function instance is instanceof Function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-length.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-length.js new file mode 100644 index 0000000000..03a0119a4e --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-length.js @@ -0,0 +1,18 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor-length +description: > + %AsyncFunction% has a length of 1 with writable false, enumerable false, configurable true. +includes: [propertyHelper.js] +---*/ + +var AsyncFunction = async function foo() {}.constructor; +assert.sameValue(AsyncFunction.length, 1); +verifyNotWritable(AsyncFunction, 'length'); +verifyNotEnumerable(AsyncFunction, 'length'); +verifyConfigurable(AsyncFunction, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-name.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-name.js new file mode 100644 index 0000000000..b745e91a15 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-name.js @@ -0,0 +1,18 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor-properties +description: > + %AsyncFunction% has a name of "AsyncFunction". +includes: [propertyHelper.js] +---*/ + +var AsyncFunction = async function foo() {}.constructor; +assert.sameValue(AsyncFunction.name, "AsyncFunction"); +verifyNotWritable(AsyncFunction, "name"); +verifyNotEnumerable(AsyncFunction, "name"); +verifyConfigurable(AsyncFunction, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-prototype.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-prototype.js new file mode 100644 index 0000000000..a8a2f2be9a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction-prototype.js @@ -0,0 +1,16 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor-prototype +description: AsyncFunction has a prototype property with writable false, enumerable false, configurable false. +includes: [propertyHelper.js] +---*/ + +var AsyncFunction = async function foo() {}.constructor; +verifyNotConfigurable(AsyncFunction, 'prototype'); +verifyNotWritable(AsyncFunction, 'prototype'); +verifyNotEnumerable(AsyncFunction, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction.js new file mode 100644 index 0000000000..8d5207c2fa --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunction.js @@ -0,0 +1,14 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-objects +description: > + %AsyncFunction% exists and is a function +---*/ + +var AsyncFunction = async function foo() {}.constructor; +assert.sameValue(typeof AsyncFunction, "function"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-extensible.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-extensible.js new file mode 100644 index 0000000000..fecb464d08 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-extensible.js @@ -0,0 +1,15 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-sync-function-prototype-properties +description: > + %AsyncFunctionPrototype% has a [[Extensible]] of true +---*/ + +var AsyncFunction = async function foo() {}.constructor; +AsyncFunction.prototype.x = 1; +assert.sameValue(AsyncFunction.prototype.x, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-not-callable.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-not-callable.js new file mode 100644 index 0000000000..f3db773ba1 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-is-not-callable.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-function-prototype-properties +description: > + %AsyncFunction.prototype% is an ordinary non-callable object. +info: | + Properties of the AsyncFunction Prototype Object + + The AsyncFunction prototype object: + + [...] + * is an ordinary object. + * is not a function object and does not have an [[ECMAScriptCode]] internal slot + or any other of the internal slots listed in Table 28. +features: [async-functions] +---*/ + +var AsyncFunctionPrototype = Object.getPrototypeOf(async function() {}); + +assert.sameValue(typeof AsyncFunctionPrototype, "object"); +assert.throws(TypeError, function() { + AsyncFunctionPrototype(); +}); + +assert(!AsyncFunctionPrototype.hasOwnProperty("length"), "length"); +assert(!AsyncFunctionPrototype.hasOwnProperty("name"), "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-prototype.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-prototype.js new file mode 100644 index 0000000000..f69dcf6a6a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-prototype.js @@ -0,0 +1,12 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-sync-function-prototype-properties +description: AsyncFunction.prototype has a [[prototype]] of Function.prototype +---*/ +var AsyncFunction = async function foo() {}.constructor; +assert.sameValue(Object.getPrototypeOf(AsyncFunction.prototype), Function.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-to-string.js b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-to-string.js new file mode 100644 index 0000000000..3aa8d3a4fa --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/AsyncFunctionPrototype-to-string.js @@ -0,0 +1,20 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-prototype-properties-toStringTag +description: > + %AsyncFunctionPrototype% has a Symbol.toStringTag property of "AsyncFunction" +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +var AsyncFunction = async function foo() {}.constructor; +var AFP = AsyncFunction.prototype; +assert.sameValue(AFP[Symbol.toStringTag], "AsyncFunction", "toStringTag value"); +verifyNotWritable(AFP, Symbol.toStringTag); +verifyNotEnumerable(AFP, Symbol.toStringTag); +verifyConfigurable(AFP, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/browser.js b/js/src/tests/test262/built-ins/AsyncFunction/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/browser.js diff --git a/js/src/tests/test262/built-ins/AsyncFunction/instance-construct-throws.js b/js/src/tests/test262/built-ins/AsyncFunction/instance-construct-throws.js new file mode 100644 index 0000000000..e51c40a3e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/instance-construct-throws.js @@ -0,0 +1,40 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-instances +description: > + Async function instances are not constructors and do not have a + [[Construct]] slot. +info: | + 25.5.1.1 AsyncFunction( p1, p2, … , pn, body ) + + ... + 3. Return CreateDynamicFunction(C, NewTarget, "async", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction( constructor, newTarget, kind, args ) + + ... + 33. Perform FunctionInitialize(F, Normal, parameters, body, scope). + 34. If kind is "generator", then + ... + 35. Else if kind is "normal", perform MakeConstructor(F). + 36. NOTE: Async functions are not constructable and do not have a [[Construct]] internal method + or a "prototype" property. + ... +---*/ + +async function foo() {} +assert.throws(TypeError, function() { + new foo(); +}); + +var AsyncFunction = Object.getPrototypeOf(foo).constructor; +var instance = AsyncFunction(); + +assert.throws(TypeError, function() { + new instance(); +}) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/instance-has-name.js b/js/src/tests/test262/built-ins/AsyncFunction/instance-has-name.js new file mode 100644 index 0000000000..13a6a8eb53 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/instance-has-name.js @@ -0,0 +1,18 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-instances-name +description: Async function declarations have a name property +includes: [propertyHelper.js] +---*/ + +async function foo() {}; + +assert.sameValue(foo.name, "foo"); +verifyNotWritable(foo, "name"); +verifyNotEnumerable(foo, "name"); +verifyConfigurable(foo, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/instance-length.js b/js/src/tests/test262/built-ins/AsyncFunction/instance-length.js new file mode 100644 index 0000000000..6a139180d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/instance-length.js @@ -0,0 +1,24 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-instances-length +description: > + Async functions have a length property that is the number of expected + arguments. +includes: [propertyHelper.js] +---*/ + +async function l0() {} +async function l1(a) {} +async function l2(a, b) {} +assert.sameValue(l0.length, 0); +assert.sameValue(l1.length, 1); +assert.sameValue(l2.length, 2) + +verifyNotWritable(l0, 'length'); +verifyNotEnumerable(l0, 'length'); +verifyConfigurable(l0, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/instance-prototype-property.js b/js/src/tests/test262/built-ins/AsyncFunction/instance-prototype-property.js new file mode 100644 index 0000000000..74e17773f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/instance-prototype-property.js @@ -0,0 +1,14 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-instances +description: > + Async function instances do not have a prototype property. +---*/ +async function foo() {}; +assert.sameValue(foo.prototype, undefined, 'foo.prototype should be undefined'); +assert(!foo.hasOwnProperty('prototype'), 'foo.prototype should not exist'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/is-a-constructor.js b/js/src/tests/test262/built-ins/AsyncFunction/is-a-constructor.js new file mode 100644 index 0000000000..7730d8f081 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The AsyncFunction constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js, hidden-constructors.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(isConstructor(AsyncFunction), true, 'isConstructor(AsyncFunction) must return true'); +new AsyncFunction(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/is-not-a-global.js b/js/src/tests/test262/built-ins/AsyncFunction/is-not-a-global.js new file mode 100644 index 0000000000..97f167ce05 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/is-not-a-global.js @@ -0,0 +1,15 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-constructor-properties +description: > + %AsyncFunction% is not exposed as a global +---*/ + +assert.throws(ReferenceError, function() { + AsyncFunction +}, "AsyncFunction should not be present as a global"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/AsyncFunction/proto-from-ctor-realm.js new file mode 100644 index 0000000000..780202a02a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/proto-from-ctor-realm.js @@ -0,0 +1,64 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-function-constructor-arguments +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + AsyncFunction ( p1, p2, … , pn, body ) + + ... + 3. Return CreateDynamicFunction(C, NewTarget, "async", args). + + Runtime Semantics: CreateDynamicFunction ( constructor, newTarget, kind, args ) + + ... + 9. Else if kind is "async", then + ... + c. Let fallbackProto be "%AsyncFunction.prototype%". + ... + 18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). + ... + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [async-functions, cross-realm, Reflect, Symbol] +---*/ + +var AsyncFunction = Object.getPrototypeOf(async function() {}).constructor; +var other = $262.createRealm().global; +var OtherAsyncFunction = Object.getPrototypeOf(other.eval('(0, async function() {})')).constructor; +var newTarget = new other.Function(); +var fn; + +newTarget.prototype = undefined; +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = true; +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = ''; +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +fn = Reflect.construct(AsyncFunction, [], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Number'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncFunction/shell.js b/js/src/tests/test262/built-ins/AsyncFunction/shell.js new file mode 100644 index 0000000000..7af18bddd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncFunction/shell.js @@ -0,0 +1,43 @@ +// GENERATED, DO NOT EDIT +// file: hidden-constructors.js +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Provides uniform access to built-in constructors that are not exposed to the global object. +defines: + - AsyncArrowFunction + - AsyncFunction + - AsyncGeneratorFunction + - GeneratorFunction +---*/ + +var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor; +var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; +var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} |