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/ShadowRealm/WrappedFunction | |
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/ShadowRealm/WrappedFunction')
7 files changed, 332 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/browser.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/browser.js diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length-throws-typeerror.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length-throws-typeerror.js new file mode 100644 index 0000000000..e6271daf3d --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length-throws-typeerror.js @@ -0,0 +1,39 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrappedfunctioncreate +description: > + WrappedFunctionCreate throws a TypeError from its caller realm. +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + + ... + 7. Let result be CopyNameAndLength(wrapped, Target). + 8. If result is an Abrupt Completion, throw a TypeError exception. + ... + +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +assert.throws(TypeError, () => r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'length', { + get: () => { + throw new Error('blah'); + }, + enumerable: false, + configurable: true, +}); +fn; +`), 'expect a TypeError on length getter throwing'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length.js new file mode 100644 index 0000000000..058375cd7b --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/length.js @@ -0,0 +1,125 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrappedfunctioncreate +description: > + The value of WrappedFunction.name is copied from the target function +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + + ... + 7. Let result be CopyNameAndLength(wrapped, Target). + ... + + CopyNameAndLength ( F: a function object, Target: a function object, prefix: a String, optional argCount: a Number, ) + + 1. If argCount is undefined, then set argCount to 0. + 2. Let L be 0. + 3. Let targetHasLength be ? HasOwnProperty(Target, "length"). + 4. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + b. If Type(targetLen) is Number, then + i. If targetLen is +∞𝔽, set L to +∞. + ii. Else if targetLen is -∞𝔽, set L to 0. + iii. Else, + 1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen). + 2. Assert: targetLenAsInt is finite. + 3. Set L to max(targetLenAsInt - argCount, 0). + 5. Perform ! SetFunctionLength(F, L). + ... + + SetFunctionLength ( F, length ) + + ... + 2. Return ! DefinePropertyOrThrow(F, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }). + +includes: [propertyHelper.js] +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + + +let wrapped = r.evaluate(` +function fn(foo, bar) {} +fn; +`); +verifyProperty(wrapped, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); + + +wrapped = r.evaluate(` +function fn() {} +delete fn.length; +fn; +`); +verifyProperty(wrapped, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + + +wrapped = r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'length', { + get: () => Infinity, + enumerable: false, + configurable: true, +}); +fn; +`); +verifyProperty(wrapped, "length", { + value: Infinity, + enumerable: false, + writable: false, + configurable: true, +}); + + +wrapped = r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'length', { + get: () => -Infinity, + enumerable: false, + configurable: true, +}); +fn; +`); +verifyProperty(wrapped, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + + +wrapped = r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'length', { + get: () => -1, + enumerable: false, + configurable: true, +}); +fn; +`); +verifyProperty(wrapped, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name-throws-typeerror.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name-throws-typeerror.js new file mode 100644 index 0000000000..b12e345513 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name-throws-typeerror.js @@ -0,0 +1,39 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrappedfunctioncreate +description: > + WrappedFunctionCreate throws a TypeError from its caller realm. +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + + ... + 7. Let result be CopyNameAndLength(wrapped, Target). + 8. If result is an Abrupt Completion, throw a TypeError exception. + ... + +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +assert.throws(TypeError, () => r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'name', { + get: () => { + throw new Error('blah'); + }, + enumerable: false, + configurable: true, +}); +fn; +`), 'expect a TypeError on name getter throwing'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name.js new file mode 100644 index 0000000000..c3ca6be91c --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/name.js @@ -0,0 +1,86 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrappedfunctioncreate +description: > + The value of WrappedFunction.name is copied from the target function +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + + ... + 7. Let result be CopyNameAndLength(wrapped, Target). + ... + + CopyNameAndLength ( F: a function object, Target: a function object, prefix: a String, optional argCount: a Number, ) + + ... + 6. Let targetName be ? Get(Target, "name"). + 7. If Type(targetName) is not String, set targetName to the empty String. + 8. Perform ! SetFunctionName(F, targetName, prefix). + + SetFunctionName ( F, name [ , prefix ] ) + + ... + 6. Return ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }). + +includes: [propertyHelper.js] +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +let wrapped = r.evaluate(` +function fn() {} +fn; +`); +verifyProperty(wrapped, "name", { + value: "fn", + enumerable: false, + writable: false, + configurable: true, +}); + +// The name property is an accessor. +wrapped = r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'name', { + get: () => "bar", + enumerable: false, + configurable: true, +}); +fn; +`); +verifyProperty(wrapped, "name", { + value: "bar", + enumerable: false, + writable: false, + configurable: true, +}); + +// The value of fn.name is not a string. +for (const name of [null, undefined, 0, '1n', false, NaN, Infinity, 'Symbol()', '[]', '{}']) { + wrapped = r.evaluate(` +function fn() {} +Object.defineProperty(fn, 'name', { + value: ${String(name)}, + enumerable: false, + configurable: true, +}); +fn; +`); + verifyProperty(wrapped, "name", { + value: "", + enumerable: false, + writable: false, + configurable: true, + }); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/shell.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/shell.js diff --git a/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js new file mode 100644 index 0000000000..5517103de5 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/WrappedFunction/throws-typeerror-on-revoked-proxy.js @@ -0,0 +1,43 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-wrapped-function-exotic-objects-call-thisargument-argumentslist +description: > + WrappedFunctionCreate throws a TypeError the target is a revoked proxy. + +info: | + WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, ) + 1. Let target be F.[[WrappedTargetFunction]]. + 2. Assert: IsCallable(target) is true. + 3. Let callerRealm be F.[[Realm]]. + 4. NOTE: Any exception objects produced after this point are associated with callerRealm. + 5. Let targetRealm be ? GetFunctionRealm(target). + ... + + GetFunctionRealm ( obj ) + ... + 3. If obj is a Proxy exotic object, then + a. If obj.[[ProxyHandler]] is null, throw a TypeError exception. + ... + +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +const fn = r.evaluate(` +globalThis.revocable = Proxy.revocable(() => {}, {}); + +globalThis.revocable.proxy; +`); +r.evaluate('revocable.revoke()'); +assert.throws(TypeError, () => fn()); + +reportCompare(0, 0); |