2 var sr = new ShadowRealm();
5 var allSettled = new Promise((resolved) => { resolve = resolved });
7 self.onmessage = async function (e) {
10 if (e.data === 'evaluate') {
11 sr.evaluate("var s = 'PASS set string in realm';")
12 var res = sr.evaluate('s');
17 // If Import works in a worker, then it ought to work in a shadow realm
19 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 and
20 // https://bugzilla.mozilla.org/show_bug.cgi?id=1772162
21 if (e.data == 'import') {
22 var import_worked = false;
23 var importValue_worked = false;
24 var importNested_worked = false;
26 var module = await import("./shadow_realm_module.js");
34 await sr.importValue("./shadow_realm_module.js", 'x').then((x) => {
35 if (x == 1) { importValue_worked = true; }
42 import("./shadow_realm_module.js").then((module) => {
50 importNested_worked = sr.evaluate("imported");
55 if (importValue_worked == importNested_worked) {
56 postMessage(`PASS: import in workers ${
57 import_worked ? "worked" : "failed"
58 }. importValue, and nested import all ${
59 importValue_worked ? "worked" : "failed"
65 postMessage(`FAIL: importValue ${importValue_worked}, import ${import_worked}, importNested ${importNested_worked}`);
71 // Reply back with finish
72 if (e.data == 'finish') {
74 postMessage("finish");
78 postMessage("FAIL: " + e.message);
80 postMessage('Unknown message type.');