diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js new file mode 100644 index 0000000000..987ae67b45 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js @@ -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__'); diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-returns.js b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-returns.js new file mode 100644 index 0000000000..4faab63df6 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-returns.js @@ -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__');