[go] misc/wasm: make wasm_exec.js supports enviroment without fs module

92 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Sep 3, 2021, 1:36:19 AM9/3/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

misc/wasm: make wasm_exec.js supports enviroment without fs module

Some of the environment (e.g. Cloudflare Worker) maybe not support for "fs" module and returns 'Uncaught Error: No such module "fs".' error.
This changes can fix the issue.

Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
GitHub-Last-Rev: 52d7dad0bc0f62d5a1c5e9ebe1813a02f7967f72
GitHub-Pull-Request: golang/go#48169
---
M misc/wasm/wasm_exec.js
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index 231185a..a629888 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -28,10 +28,12 @@
}

if (!global.fs && global.require) {
- const fs = require("fs");
- if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
- global.fs = fs;
- }
+ try {
+ const fs = require("fs");
+ if (typeof fs === "object" && fs !== null && Object.keys(fs).length !== 0) {
+ global.fs = fs;
+ }
+ } catch(e) {}
}

const enosys = () => {

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gerrit Bot (Gerrit)

unread,
Sep 3, 2021, 1:51:15 AM9/3/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Richard Musiol, Cherry Mui.

Gerrit Bot uploaded patch set #2 to this change.

View Change

misc/wasm: make wasm_exec.js supports enviroment without fs module

Some of the environment (e.g. Cloudflare Worker) maybe not support for "fs" module and returns 'Uncaught Error: No such module "fs".' error.
This changes can fix the issue.

Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
GitHub-Last-Rev: c56557b7a1e0b157679d4245f64da4103935887f

GitHub-Pull-Request: golang/go#48169
---
M misc/wasm/wasm_exec.js
1 file changed, 20 insertions(+), 12 deletions(-)

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Richard Musiol <neel...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-Attention: Richard Musiol <neel...@gmail.com>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Sep 3, 2021, 1:53:46 AM9/3/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Richard Musiol, Cherry Mui.

Gerrit Bot uploaded patch set #3 to this change.

View Change

misc/wasm: make wasm_exec.js try catch when require module


Some of the environment (e.g. Cloudflare Worker) maybe not support for "fs" module and returns 'Uncaught Error: No such module "fs".' error.
This changes can fix the issue.

Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
GitHub-Last-Rev: c56557b7a1e0b157679d4245f64da4103935887f
GitHub-Pull-Request: golang/go#48169
---
M misc/wasm/wasm_exec.js
1 file changed, 20 insertions(+), 12 deletions(-)

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 3

Gerrit Bot (Gerrit)

unread,
Sep 3, 2021, 1:56:18 AM9/3/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Richard Musiol, Cherry Mui.

Gerrit Bot uploaded patch set #4 to this change.

View Change

misc/wasm: make wasm_exec.js try catch when require module

Some of the environment (e.g. Cloudflare Worker) maybe not support for "fs" (or other modules) and returns 'Uncaught Error: No such module' error.

This changes can fix the issue.

Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
GitHub-Last-Rev: c56557b7a1e0b157679d4245f64da4103935887f
GitHub-Pull-Request: golang/go#48169
---
M misc/wasm/wasm_exec.js
1 file changed, 20 insertions(+), 12 deletions(-)

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 4

Richard Musiol (Gerrit)

unread,
Sep 3, 2021, 4:15:32 PM9/3/21
to Gerrit Bot, goph...@pubsubhelper.golang.org, Cherry Mui, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Cherry Mui.

View Change

1 comment:

  • Patchset:

    • Patch Set #4:

      I am reluctant to add support for yet another environment. Instead I wrote https://go-review.googlesource.com/c/go/+/347353. This should make it relatively easy for you to make it fit into the Cloudflare Worker environment, since wasm_exec.js itself is not using "require" any more. Please give it a try.

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Richard Musiol <neel...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Fri, 03 Sep 2021 20:15:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Richard Musiol (Gerrit)

unread,
Sep 4, 2021, 5:56:42 AM9/4/21
to Gerrit Bot, goph...@pubsubhelper.golang.org, SerKo, Cherry Mui, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: SerKo, Cherry Mui.

View Change

1 comment:

  • Patchset:

    • Patch Set #4:

      So that means when works on an another environment that not supported by native. […]

      Exactly.

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Richard Musiol <neel...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: SerKo <serk...@gmail.com>
Gerrit-Attention: SerKo <serk...@gmail.com>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Sat, 04 Sep 2021 09:56:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: SerKo <serk...@gmail.com>
Comment-In-Reply-To: Richard Musiol <neel...@gmail.com>
Gerrit-MessageType: comment

SerKo (Gerrit)

unread,
Sep 4, 2021, 9:21:54 AM9/4/21
to Gerrit Bot, goph...@pubsubhelper.golang.org, Richard Musiol, Cherry Mui, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Richard Musiol, Cherry Mui.

View Change

1 comment:

  • Patchset:

    • Patch Set #4:

      I am reluctant to add support for yet another environment. Instead I wrote https://go-review. […]

      So that means when works on an another environment that not supported by native. Developer should create a new js file (like wasm_exec_node.js) that custom the polyfill function right?

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Richard Musiol <neel...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: SerKo <serk...@gmail.com>
Gerrit-Attention: Richard Musiol <neel...@gmail.com>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Sat, 04 Sep 2021 05:18:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No

SerKo (Gerrit)

unread,
Sep 4, 2021, 9:21:54 AM9/4/21
to Gerrit Bot, goph...@pubsubhelper.golang.org, Richard Musiol, Cherry Mui, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Richard Musiol, Cherry Mui.

View Change

2 comments:

To view, visit change 347170. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I41ed8b65fd510d90fb8b72a94469f825093bcd00
Gerrit-Change-Number: 347170
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Richard Musiol <neel...@gmail.com>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: SerKo <serk...@gmail.com>
Gerrit-Attention: Richard Musiol <neel...@gmail.com>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Sat, 04 Sep 2021 11:41:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: SerKo <serk...@gmail.com>
Reply all
Reply to author
Forward
0 new messages