Add tests on ShadowRealm WrappedFunction value wrapping

This commit is contained in:
legendecas 2021-10-22 01:19:38 +08:00 committed by Rick Waldron
parent 541715762c
commit ec998749ec
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 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: >
WrappedFunction throws a TypeError if any of the arguments are non-primitive
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 wrappedFunction = r.evaluate('() => {}');
assert.throws(TypeError, () => wrappedFunction(1, globalThis), 'globalThis');
assert.throws(TypeError, () => wrappedFunction(1, []), 'array literal');
assert.throws(TypeError, () => wrappedFunction(1, {
[Symbol.toPrimitive]() { return 'string'; },
toString() { return 'str'; },
valueOf() { return 1; }
}), 'object literal with immediate primitive coercion methods');
assert.throws(TypeError, () => wrappedFunction(1, Object.create(null)), 'ordinary object with null __proto__');

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 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: >
WrappedFunction throws a TypeError if it returns non-primitive values
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('() => globalThis'), 'globalThis');
assert.throws(TypeError, r.evaluate('() => []'), 'array literal');
assert.throws(TypeError, r.evaluate(`
() => ({
[Symbol.toPrimitive]() { return 'string'; },
toString() { return 'str'; },
valueOf() { return 1; }
});
`), 'object literal with immediate primitive coercion methods');
assert.throws(TypeError, r.evaluate('() => Object.create(null)'), 'ordinary object with null __proto__');