Skip to content

Commit 758ac37

Browse files
neelanceRichard Musiol
authored and
Richard Musiol
committed
misc/wasm: make wasm_exec more robust against uncommon environments
JavaScript environments are quite unpredictable because bundlers add mocks for compatibility and libraries can polute the global namespace. Detect more of such situations: - Add check that require("fs") returns an object. - Fix check that require("fs") returns an non-empty object. - Add check that "module" is defined. Fixes #40730 Change-Id: I2ce65fc7db64bbbb0b60eec79a4cfe5c3fec99c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/248758 Run-TryBot: Richard Musiol <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 8381408 commit 758ac37

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

misc/wasm/wasm_exec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// - Node.js
1212
// - Electron
1313
// - Parcel
14+
// - Webpack
1415

1516
if (typeof global !== "undefined") {
1617
// global already exists
@@ -28,7 +29,7 @@
2829

2930
if (!global.fs && global.require) {
3031
const fs = require("fs");
31-
if (Object.keys(fs) !== 0) {
32+
if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
3233
global.fs = fs;
3334
}
3435
}
@@ -556,6 +557,7 @@
556557
}
557558

558559
if (
560+
typeof module !== "undefined" &&
559561
global.require &&
560562
global.require.main === module &&
561563
global.process &&

0 commit comments

Comments
 (0)