diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-from-ctor-realm.js b/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-from-ctor-realm.js new file mode 100644 index 0000000000..c36eb672ac --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-from-ctor-realm.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-shadowrealm.prototype.evaluate +description: > + ShadowRealm.prototype.evaluate throws a TypeError from ShadowRealm's creation realm. +features: [ShadowRealm, cross-realm, Reflect] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +var other = $262.createRealm().global; +var OtherTypeError = other.eval('TypeError'); +var OtherShadowRealm = other.eval('ShadowRealm'); + +var realm = Reflect.construct(OtherShadowRealm, []); +assert.throws(OtherTypeError, () => realm.evaluate('globalThis'), 'throws a TypeError if return value can not be wrapped'); +assert.throws(OtherTypeError, () => realm.evaluate(1), 'throws a TypeError if sourceText is not a string'); + +const bogus = {}; +assert.throws(OtherTypeError, function() { + realm.evaluate.call(bogus, ''); +}, 'throws a TypeError if this is not a ShadowRealm object'); diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js index bfb93f75df..9f509a2446 100644 --- a/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js +++ b/test/built-ins/ShadowRealm/prototype/evaluate/wrapped-function-proto-from-caller-realm.js @@ -35,5 +35,5 @@ var other = $262.createRealm().global; var OtherShadowRealm = other.ShadowRealm; var realm = Reflect.construct(OtherShadowRealm, []); -var fn = r.evaluate('() => {}'); +var fn = realm.evaluate('() => {}'); assert.sameValue(Object.getPrototypeOf(fn), Function.prototype, 'WrappedFunction should be derived from the caller realm');