forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadowRealm-importValue.html
46 lines (40 loc) · 1.66 KB
/
ShadowRealm-importValue.html
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
41
42
43
44
45
46
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- webkit-test-runner [ jscOptions=--useShadowRealm=true ] -->
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script src =../resources/testharness.js></script>
<script src =../resources/testharnessreport.js></script>
<script>
description("Test to ensure correct behaviour of ShadowRealm.prototype.importValue");
function wrappedLog(prefix) {
return function (msg) {
debug(prefix + ": " + msg);
};
}
const module_path = "./resources/example-module.js";
promise_test(async t => {
const outerShadowRealm = new ShadowRealm();
const checkFn = await outerShadowRealm.importValue(module_path, "check");
assert_equals(checkFn(wrappedLog("shadowRealm")), true);
const ourModule = await import(module_path);
assert_equals(ourModule.value, true, "bloop");
ourModule.setValue(42);
assert_equals(ourModule.value, 42);
const importedVal = await outerShadowRealm.importValue(module_path, "value");
assert_equals(importedVal, true);
const setValueImported = await outerShadowRealm.importValue(module_path, "setValue");
setValueImported(100);
const importedVal2 = await outerShadowRealm.importValue(module_path, "value");
assert_equals(importedVal2, 100);
assert_equals(ourModule.value, 42);
}, "can import module in a shadow realm");
promise_test(async t => {
const outerShadowRealm = new ShadowRealm();
const checkFn = await outerShadowRealm.importValue(module_path, "check_nested");
assert_equals(checkFn(wrappedLog("shadowRealm")), true);
}, "can nest realms");
</script>
</body>
</html>