mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 15:34:29 +02:00
Test WrappedFunction properties
This commit is contained in:
parent
d71cf3a339
commit
d5d9f66a8f
@ -0,0 +1,36 @@
|
|||||||
|
// 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');
|
121
test/built-ins/ShadowRealm/WrappedFunction/length.js
Normal file
121
test/built-ins/ShadowRealm/WrappedFunction/length.js
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
// 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 }).
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
@ -0,0 +1,36 @@
|
|||||||
|
// 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');
|
80
test/built-ins/ShadowRealm/WrappedFunction/name.js
Normal file
80
test/built-ins/ShadowRealm/WrappedFunction/name.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// 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 }).
|
||||||
|
|
||||||
|
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.
|
||||||
|
wrapped = r.evaluate(`
|
||||||
|
function fn() {}
|
||||||
|
Object.defineProperty(fn, 'name', {
|
||||||
|
get: () => 1,
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
fn;
|
||||||
|
`);
|
||||||
|
verifyProperty(wrapped, "name", {
|
||||||
|
value: "",
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user