Add test for ShadowRealm.prototype.evaluate throwing realm check

This commit is contained in:
legendecas 2021-10-07 23:25:33 +08:00 committed by Rick Waldron
parent fc975b171d
commit fc3878f0a4
2 changed files with 28 additions and 1 deletions

View 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');

View File

@ -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');