5
5
// bigger than it used to be before any changes is applied to this file.
6
6
7
7
import * as JSON from '@ungap/structured-clone/json' ;
8
- import coincident from 'coincident/window' ;
8
+ import coincident from 'coincident/window/worker ' ;
9
9
10
10
import { assign , create , createFunction , createOverload , createResolved , dispatch , registerJSModules } from '../utils.js' ;
11
11
import createJSModules from './js_modules.js' ;
@@ -32,19 +32,23 @@ const add = (type, fn) => {
32
32
33
33
const { parse, stringify } = JSON ;
34
34
35
- const { proxy : sync , window, isWindowProxy } = coincident ( self , {
35
+ const { proxy : sync , sync : syncMainAndWorker , polyfill , window, isWindowProxy } = await coincident ( {
36
36
parse,
37
37
stringify,
38
38
transform : value => transform ? transform ( value ) : value
39
39
} ) ;
40
40
41
41
const xworker = {
42
+ // propagate the fact SharedArrayBuffer is polyfilled
43
+ polyfill,
42
44
// allows synchronous utilities between this worker and the main thread
43
45
sync,
44
46
// allow access to the main thread world
45
47
window,
46
48
// allow introspection for foreign (main thread) refrences
47
49
isWindowProxy,
50
+ // propagate the fact `window` can be used
51
+ hasWindow : syncMainAndWorker ,
48
52
// standard worker related events / features
49
53
onmessage : console . info ,
50
54
onerror : console . error ,
@@ -61,38 +65,10 @@ add('message', ({ data: { options, config: baseURL, configURL, code, hooks } })
61
65
62
66
const interpreter = await getRuntime ( runtimeID , baseURL , configURL , config ) ;
63
67
64
- const { js_modules, sync_main_only } = configs . get ( runtimeID ) ;
68
+ const { js_modules } = configs . get ( runtimeID ) ;
65
69
66
70
const mainModules = js_modules ?. main ;
67
71
68
- // this flag allows interacting with the xworker.sync exposed
69
- // *only in the worker* and eventually invoked *only from main*.
70
- // If that flag is `false` or not present, then SharedArrayBuffer
71
- // must be available or not much can work in here.
72
- let syncMainAndWorker = ! sync_main_only ;
73
-
74
- // bails out out of the box with a native/meaningful error
75
- // in case the SharedArrayBuffer is not available
76
- try {
77
- new SharedArrayBuffer ( 4 ) ;
78
- // if this does not throw there's no reason to
79
- // branch out of all the features ... but ...
80
- syncMainAndWorker = true ;
81
- }
82
- // eslint-disable-next-line no-unused-vars
83
- catch ( _ ) {
84
- // if it does throw and `sync_main_only` was not `true`
85
- // then there's no way to go further
86
- if ( syncMainAndWorker ) {
87
- throw new Error (
88
- [
89
- 'Unable to use SharedArrayBuffer due insecure environment.' ,
90
- 'Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements' ,
91
- ] . join ( '\n' ) ,
92
- ) ;
93
- }
94
- }
95
-
96
72
const details = create ( registry . get ( type ) ) ;
97
73
98
74
const resolved = createResolved (
0 commit comments