Skip to content

Commit 2d2442c

Browse files
osman-turankripken
authored andcommitted
Add fallback for emval_get_global to support Web Workers (#9723)
In generated WebAssembly modules, `emval_get_global` is used for accessing global variables. This function tries to get `globalThis` property with a fallback mechanism. Unfortunately, fallback mechanism does not use Web Workers environment global object (`self`). This commit fixes that problem.
1 parent 4b02802 commit 2d2442c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,4 @@ a license to everyone to use it as detailed in LICENSE.)
431431
* Cesar Guirao Robles <cesar@no2.es>
432432
* Mehdi Sabwat <mehdisabwat@gmail.com>
433433
* MinganMuon <mingan-muon@outlook.com>
434+
* Osman Turan <osman@osmanturan.com>

src/embind/emval.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ var LibraryEmVal = {
220220
}
221221
if (typeof global === 'object' && testGlobal(global)) {
222222
$$$embind_global$$$ = global;
223-
} else if (typeof window === 'object' && testGlobal(window)) {
224-
$$$embind_global$$$ = window;
223+
} else if (typeof self === 'object' && testGlobal(self)) {
224+
$$$embind_global$$$ = self; // This works for both "window" and "self" (Web Workers) global objects
225225
}
226226
if (typeof $$$embind_global$$$ === 'object') {
227227
return $$$embind_global$$$;

0 commit comments

Comments
 (0)