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/Reflect/apply | |
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/Reflect/apply')
11 files changed, 375 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Reflect/apply/apply.js b/js/src/tests/test262/built-ins/Reflect/apply/apply.js new file mode 100644 index 0000000000..cb06ed6808 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/apply.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Reflect.apply is configurable, writable and not enumerable. +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'apply'); +verifyWritable(Reflect, 'apply'); +verifyConfigurable(Reflect, 'apply'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js new file mode 100644 index 0000000000..b275eb80b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js @@ -0,0 +1,82 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-reflect.apply +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + Reflect.apply ( target, thisArgument, argumentsList ) + + ... + Let args be ? CreateListFromArrayLike(argumentsList). + + + CreateListFromArrayLike (obj [, elementTypes] ) + + ... + If Type(obj) is not Object, throw a TypeError exception. + Let len be ? LengthOfArrayLike(obj). + Let list be a new empty List. + Let index be 0. + Repeat, while index < len, + Let indexName be ! ToString(index). + Let next be ? Get(obj, indexName). + If Type(next) is not an element of elementTypes, throw a TypeError exception. + Append next as the last element of list. + Set index to index + 1. + Return list. +includes: [compareArray.js] +features: [Reflect, arrow-function, Symbol] +---*/ + +let count = 0; + +function fn(...args) { + count++; + return args; +} + +let f_unction = new Function(); + +Object.defineProperty(f_unction, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, f_unction), [undefined]); + +let object = new Object(); + +Object.defineProperty(object, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, object), [undefined]); + +let number = new Number(); + +Object.defineProperty(number, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, number), [undefined]); + +let boolean = new Boolean(); + +Object.defineProperty(boolean, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, boolean), [undefined]); + +assert.sameValue(count, 4, 'The value of `count` is 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js new file mode 100644 index 0000000000..0213686fc0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like.js @@ -0,0 +1,75 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-reflect.apply +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + Reflect.apply ( target, thisArgument, argumentsList ) + + ... + Let args be ? CreateListFromArrayLike(argumentsList). + + + CreateListFromArrayLike (obj [, elementTypes] ) + + ... + If Type(obj) is not Object, throw a TypeError exception. +features: [Reflect, arrow-function, Symbol] +---*/ + +let count = 0; + +function fn() { + count++; +} + +assert.throws(Test262Error, () => { + Reflect.apply(fn, null, { + get length() { + throw new Test262Error(); + } + }); +}, '`Reflect.apply(fn, null, {get length() {throw new Test262Error();}})` throws a Test262Error exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null /* empty */); +}, '`Reflect.apply(fn, null /* empty */)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Symbol()); +}, '`Reflect.apply(fn, null, Symbol())` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, 1); +}, '`Reflect.apply(fn, null, 1)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Infinity); +}, '`Reflect.apply(fn, null, Infinity)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, null); +}, '`Reflect.apply(fn, null, null)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, undefined); +}, '`Reflect.apply(fn, null, undefined)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, false); +}, '`Reflect.apply(fn, null, false)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, true); +}, '`Reflect.apply(fn, null, true)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, NaN); +}, '`Reflect.apply(fn, null, NaN)` throws a TypeError exception'); + + +assert.sameValue(count, 0, 'The value of `count` is 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/browser.js b/js/src/tests/test262/built-ins/Reflect/apply/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/apply/call-target.js b/js/src/tests/test262/built-ins/Reflect/apply/call-target.js new file mode 100644 index 0000000000..390d394776 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/call-target.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Call target with thisArgument and argumentsList +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + ... + 4. Perform PrepareForTailCall(). + 5. Return Call(target, thisArgument, args). +features: [Reflect] +---*/ + +var o = {}; +var count = 0; +var results, args; + +function fn() { + count++; + results = { + thisArg: this, + args: arguments + }; +} + +Reflect.apply(fn, o, ['arg1', 2, , null]); + +assert.sameValue(count, 1, 'Called target once'); +assert.sameValue(results.thisArg, o, 'Called target with `o` as `this` object'); +assert.sameValue(results.args.length, 4, 'Called target with 4 arguments'); +assert.sameValue(results.args[0], 'arg1'); +assert.sameValue(results.args[1], 2); +assert.sameValue(results.args[2], undefined); +assert.sameValue(results.args[3], null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/length.js b/js/src/tests/test262/built-ins/Reflect/apply/length.js new file mode 100644 index 0000000000..3499bc3355 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/length.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Reflect.apply.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.apply.length, 3, + 'The value of `Reflect.apply.length` is `3`' +); + +verifyNotEnumerable(Reflect.apply, 'length'); +verifyNotWritable(Reflect.apply, 'length'); +verifyConfigurable(Reflect.apply, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/name.js b/js/src/tests/test262/built-ins/Reflect/apply/name.js new file mode 100644 index 0000000000..5da83c4d24 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/name.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Reflect.apply.name value and property descriptor +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.apply.name, 'apply', + 'The value of `Reflect.apply.name` is `"apply"`' +); + +verifyNotEnumerable(Reflect.apply, 'name'); +verifyNotWritable(Reflect.apply, 'name'); +verifyConfigurable(Reflect.apply, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js new file mode 100644 index 0000000000..4e4aa65254 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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: > + Reflect.apply does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Reflect, arrow-function] +---*/ + +assert.sameValue(isConstructor(Reflect.apply), false, 'isConstructor(Reflect.apply) must return false'); + +assert.throws(TypeError, () => { + new Reflect.apply(() => {}, undefined, []); +}, '`new Reflect.apply(() => {}, undefined, [])` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-result.js b/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-result.js new file mode 100644 index 0000000000..a577540e1b --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/return-target-call-result.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Return target result +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + ... + 4. Perform PrepareForTailCall(). + 5. Return Call(target, thisArgument, args). +features: [Reflect] +---*/ + +var o = {}; + +function fn() { + return o; +} + +var result = Reflect.apply(fn, 1, []); + +assert.sameValue(result, o); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/apply/shell.js b/js/src/tests/test262/built-ins/Reflect/apply/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Reflect/apply/target-is-not-callable-throws.js b/js/src/tests/test262/built-ins/Reflect/apply/target-is-not-callable-throws.js new file mode 100644 index 0000000000..b795a5bdc4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/apply/target-is-not-callable-throws.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.1 +description: > + Throws a TypeError if `target` is not callable. +info: | + 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + + 1. If IsCallable(target) is false, throw a TypeError exception. + ... + + 7.2.3 IsCallable ( argument ) + + 1. ReturnIfAbrupt(argument). + 2. If Type(argument) is not Object, return false. + 3. If argument has a [[Call]] internal method, return true. + 4. Return false. +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.apply(1, 1, []); +}); + +assert.throws(TypeError, function() { + Reflect.apply(null, 1, []); +}); + +assert.throws(TypeError, function() { + Reflect.apply({}, 1, []); +}); + +reportCompare(0, 0); |