Skip to content

wasm: patch wasm_exec.js and wasm_exec_node.js from Go 1.18+#5483

Open
Darckfast wants to merge 3 commits into
tinygo-org:devfrom
Darckfast:port-go-wasm-exec-changes
Open

wasm: patch wasm_exec.js and wasm_exec_node.js from Go 1.18+#5483
Darckfast wants to merge 3 commits into
tinygo-org:devfrom
Darckfast:port-go-wasm-exec-changes

Conversation

@Darckfast

Copy link
Copy Markdown

Port these commits:
golang/go@680caf1 Removes polyfills from wasm_exec.js

The list of environments to support with wasm_exec.js was becoming too
large to maintain. With this change, wasm_exec.js expects that the
environment provides all necessary polyfills.

The standardized "globalThis" is used for accessing the environment.
wasm_exec.js now only provides stub fallbacks for globalThis.fs and
globalThis.process.

All code specific to Node.js is now in a separate file.

golang/go@04d8d24 Enables ECMAScript strict mode on wasm_exec.js

Current wasm_exec.js does not enable ECMAScript strict mode. But it is
recommended to be enabled because it

1. eliminates some ECMAScript silent errors by changing them to throw
   errors
2. fixes mistakes that make it difficult for JavaScript engines to
   perform optimizations
3. prohibits some syntax likely to be defined in future versions of
   ECMAScript

golang/go@ff34676 Replace deprecated substr with substring

String.prototype.substr is deprecated and usage is no longer
recommended so using String.prototype.substring instead.

this fixes #5370

NOTE: i added some polyfill on wasmexit.js,wasmfunc.js and wasmfunc.js tests files to keep compatibility with node 18

Port this commit golang/go@680caf1 removing polyfills from `wasm_exec.js`, now the environment is expected to provide all the required polyfills.

`wasm_exec.js` now only provides stub fallbacks for globalThis.fs and globalThis.process.

All NodeJS specific code is now in a separate file `wasm_exec_node.js` with its required polyfills.
@deadprogram

Copy link
Copy Markdown
Member

@Darckfast thanks for working on this. Please note test failures: https://github.com/tinygo-org/tinygo/actions/runs/28388339892/job/84268546073?pr=5483

@Darckfast

Copy link
Copy Markdown
Author

@deadprogram thx for the ping

what happened is, on NodeJS 18 crypto is not on the global scope (globalThis), which requires an extra polyfill, but on 19 onward it is, and it's write protected, meaning the polyfill breaks, and the CI is running on Node 22

my question is, does it make sense to still provide support for NodeJS 18? or we could drop it in place of an LTS version (+22)? this way i could trim some polyfill down

@b0ch3nski

Copy link
Copy Markdown
Contributor

NodeJS 18 has EOL date more than a year ago (2025-04-30) - in my opinion, it could be dropped.

@deadprogram

Copy link
Copy Markdown
Member

NodeJS 18 has EOL date more than a year ago (2025-04-30) - in my opinion, it could be dropped.

I would agree. The current Node LTS v22 seems quite reasonable.

@Darckfast

Copy link
Copy Markdown
Author

i agree too, also it will be less code to maintain in the long run

i will update the PR with these changes

Darckfast added 2 commits July 1, 2026 17:37
Drops official support for NodeJS 18 for WASM by removing the provided polyfills in the `wasm_exec.js`.

Now the environment is expected to provide the polyfill if it is running on older NodeJS versions

The new minimum required version for WASM is NodeJS 22+.
`wasm_exec_node.js` no longer contains the polyfill for NodeJS 18
@Darckfast

Darckfast commented Jul 1, 2026

Copy link
Copy Markdown
Author

bump'ed the node version to 22, but i couldn't find in the macOs, windows, and Linux CI where the node version is being set, only Linux > test-linux-build had it explicit

do you guys know where it gets installed from?

@deadprogram

Copy link
Copy Markdown
Member

Except for the Linux install, the default for that OS should be the only one installed, which is mostly 22.x

See
https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md

@Darckfast

Copy link
Copy Markdown
Author

Except for the Linux install, the default for that OS should be the only one installed, which is mostly 22.x

See https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md

thx, then we should be good in that regard

can i get some help with this failing test https://github.com/tinygo-org/tinygo/actions/runs/28546702015/job/84720226561?pr=5483 ? i took a look and i dont know why the timers.go test broke

@Darckfast

Copy link
Copy Markdown
Author

test-compat is also failing in this other branch https://github.com/tinygo-org/tinygo/actions/runs/28663073119/job/85008082001 from this PR #5488. a flaky test maybe?

@b0ch3nski

Copy link
Copy Markdown
Contributor

flaky test maybe?

See #5384 and #5487 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasm_exec.js doesn't play well with CloudFlare workers

3 participants