diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js')
-rw-r--r-- | js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js new file mode 100644 index 0000000000..2f61961521 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments.js @@ -0,0 +1,36 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// 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.sameValue( + typeof wrappedFunction, + 'function', + 'This test must fail if wrappedFunction is not a function' +); + +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__'); +assert.throws(TypeError, () => wrappedFunction(1, new Proxy({}, { apply() {} })), 'non-callable proxy'); + +reportCompare(0, 0); |