blob: 7f0d1503f6d59bb7f3d2e6a42481c5013f6c057d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options
// Copyright (C) 2021 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-shadowrealm.prototype.evaluate
description: >
ShadowRealm can create a nested ShadowRealm
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.evaluate,
'function',
'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);
globalThis.myValue = 'a';
const realm1 = new ShadowRealm();
realm1.evaluate('globalThis.myValue = "b";');
const realm2Evaluate = realm1.evaluate(`
const realm2 = new ShadowRealm();
(str) => realm2.evaluate(str);
`);
realm2Evaluate('globalThis.myValue = "c";');
assert.sameValue(globalThis.myValue, 'a');
assert.sameValue(realm1.evaluate('globalThis.myValue'), 'b');
assert.sameValue(realm2Evaluate('globalThis.myValue'), 'c');
realm1.evaluate('globalThis.myValue = "d"');
assert.sameValue(globalThis.myValue, 'a', 'no side effects');
assert.sameValue(realm1.evaluate('globalThis.myValue'), 'd', 'no side effects');
assert.sameValue(realm2Evaluate('globalThis.myValue'), 'c', 'no side effects');
reportCompare(0, 0);
|