sync_and_async_in_worker.js (3103B)
1 onmessage = async event => { 2 if (event.data.order === "test") { 3 globalThis["loaded"] = []; 4 const ns = await import("resource://test/non_shared_1.mjs"); 5 postMessage({}); 6 return; 7 } 8 9 if (event.data.order === "sync-before-async") { 10 globalThis["loaded"] = []; 11 const ns = ChromeUtils.importESModule("resource://test/non_shared_1.mjs", { 12 global: "current", 13 }); 14 15 const sync_beforeInc = ns.getCounter(); 16 ns.incCounter(); 17 const sync_afterInc = ns.getCounter(); 18 19 const loaded1 = globalThis["loaded"].join(","); 20 21 let nsPromise; 22 if (event.data.target === "top-level") { 23 nsPromise = import("resource://test/non_shared_1.mjs"); 24 } else { 25 nsPromise = import("resource://test/import_non_shared_1.mjs"); 26 } 27 28 const ns2 = await nsPromise; 29 30 const async_beforeInc = ns2.getCounter(); 31 ns2.incCounter(); 32 const async_afterInc = ns2.getCounter(); 33 const sync_afterIncInc = ns.getCounter(); 34 35 const loaded2 = globalThis["loaded"].join(","); 36 37 postMessage({ 38 sync_beforeInc, 39 sync_afterInc, 40 sync_afterIncInc, 41 async_beforeInc, 42 async_afterInc, 43 loaded1, 44 loaded2, 45 }); 46 return; 47 } 48 49 if (event.data.order === "sync-after-async") { 50 globalThis["loaded"] = []; 51 const ns = await import("resource://test/non_shared_1.mjs"); 52 53 const async_beforeInc = ns.getCounter(); 54 ns.incCounter(); 55 const async_afterInc = ns.getCounter(); 56 57 const loaded1 = globalThis["loaded"].join(","); 58 59 let ns2; 60 if (event.data.target === "top-level") { 61 ns2 = ChromeUtils.importESModule("resource://test/non_shared_1.mjs", { 62 global: "current", 63 }); 64 } else { 65 ns2 = ChromeUtils.importESModule("resource://test/import_non_shared_1.mjs", { 66 global: "current", 67 }); 68 } 69 70 const sync_beforeInc = ns2.getCounter(); 71 ns2.incCounter(); 72 const sync_afterInc = ns2.getCounter(); 73 const async_afterIncInc = ns.getCounter(); 74 75 const loaded2 = globalThis["loaded"].join(","); 76 77 postMessage({ 78 sync_beforeInc, 79 sync_afterInc, 80 async_beforeInc, 81 async_afterInc, 82 async_afterIncInc, 83 loaded1, 84 loaded2, 85 }); 86 return; 87 } 88 89 if (event.data.order === "sync-while-async") { 90 globalThis["loaded"] = []; 91 const nsPromise = import("resource://test/non_shared_1.mjs"); 92 93 let errorMessage = ""; 94 try { 95 if (event.data.target === "top-level") { 96 ChromeUtils.importESModule("resource://test/non_shared_1.mjs", { 97 global: "current", 98 }); 99 } else { 100 ChromeUtils.importESModule("resource://test/import_non_shared_1.mjs", { 101 global: "current", 102 }); 103 } 104 } catch (e) { 105 errorMessage = e.message; 106 } 107 108 const ns = await nsPromise; 109 110 const async_beforeInc = ns.getCounter(); 111 ns.incCounter(); 112 const async_afterInc = ns.getCounter(); 113 114 const loaded = globalThis["loaded"].join(","); 115 116 postMessage({ 117 sync_error: errorMessage, 118 async_beforeInc, 119 async_afterInc, 120 loaded, 121 }); 122 return; 123 } 124 };