mirror of https://github.com/tc39/test262.git
Add test for ShadowRealm.prototype.evaluate throwing realm check
This commit is contained in:
parent
fc975b171d
commit
fc3878f0a4
27
test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-from-ctor-realm.js
vendored
Normal file
27
test/built-ins/ShadowRealm/prototype/evaluate/throws-typeerror-from-ctor-realm.js
vendored
Normal 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-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');
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue