diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-if-evaluation-resolves-to-non-primitive.js')
-rw-r--r-- | js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-if-evaluation-resolves-to-non-primitive.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-if-evaluation-resolves-to-non-primitive.js b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-if-evaluation-resolves-to-non-primitive.js new file mode 100644 index 0000000000..d2017c9a44 --- /dev/null +++ b/js/src/tests/test262/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-if-evaluation-resolves-to-non-primitive.js @@ -0,0 +1,30 @@ +// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-shadowrealm.prototype.evaluate +description: > + ShadowRealm.prototype.evaluate throws a TypeError if evaluate resolves to 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__'); + +reportCompare(0, 0); |