blob: 52ec5306635916b5db6cf10de27bc9e171aad529 (
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
|
const sourcePromise = new Promise(resolve => {
if ('DedicatedWorkerGlobalScope' in self &&
self instanceof DedicatedWorkerGlobalScope) {
self.onmessage = e => {
resolve(e.target);
};
} else if (
'SharedWorkerGlobalScope' in self &&
self instanceof SharedWorkerGlobalScope) {
self.onconnect = e => {
resolve(e.ports[0]);
};
}
});
const importedModulesPromise =
import('./export-block-cross-origin.js')
.then(module => module.importedModules)
.catch(() => ['ERROR']);
Promise.all([sourcePromise, importedModulesPromise]).then(results => {
const [source, importedModules] = results;
source.postMessage(importedModules);
});
|