esm: --experimental-wasm-modules integration support#27659
esm: --experimental-wasm-modules integration support#27659guybedford wants to merge 1 commit intonodejs:masterfrom
Conversation
littledan
left a comment
There was a problem hiding this comment.
Note that this is slightly different than the standards track semantics, as it doesn't take a turn on the event loop during Instantiation. However, I don't expect this to affect most programs. I would also encourage you to write several more tests before landing.
There was a problem hiding this comment.
In a cycle-closing edge, will reflect.imports usually be an empty object? If so, this will be basically the right semantics.
There was a problem hiding this comment.
On the unexecuted cycle edge, reflect.imports would contain all the imported module namespaces, with their named exports, but all of those named exports would be undefined. Function exports would be supported in cycles here though just like ES modules.
There was a problem hiding this comment.
Actually cycles would throw for any accesses to uninitialized let bindings on the namespaces, since these would be in TDZ.
There was a problem hiding this comment.
To summarize:
- Unexecuted cycle edge with function exports: fine - function is defined
- Unexecuted cycle edge with let binding: throws - TDZ error
There was a problem hiding this comment.
And specifically these errors are only thrown if the WASM module actually attempts to access the given binding.
There was a problem hiding this comment.
Right, so in particular, Wasm exports should always act like const bindings, and all imports are accessed during Instantiate (in the ESM evaluate phase). Does this implementation do that?
There was a problem hiding this comment.
yep! reflect.imports is namespace objects so the imports are accessed directly.
There was a problem hiding this comment.
please upload a wat source for simple.wasm with a comment in the top with the command used to produce simple.wasm
example: https://github.com/nodejs/node/blob/master/test/fixtures/shared-memory.wat
ljharb
left a comment
There was a problem hiding this comment.
- How might one have an entry point that's directly in wasm, without the need for an ESM wrapper?
- how might one consume wasm modules in CJS?
declare a wasm start function in your wasm module this reminds me, @guybedford can you make a test which verifies that start functions run at the correct time?
at the moment, |
|
@devsnek so I'll rephrase the question - how might one synchronously consume wasm modules in cjs? |
yes
not possible atm. if |
|
Sure, I've added a start function test. |
doc/api/esm.md
Outdated
There was a problem hiding this comment.
There's one additional mention of the non-existent --entry-type CLI flag 7 lines below this one. Is this the right PR to remove or update that material?
|
Landed in bbc254d. |
PR-URL: #27659 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: #27659 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Notable changes:
* esm:
* Added the `--experimental-wasm-modules` flag to support
WebAssembly modules (Myles Borins & Guy Bedford)
#27659
* process:
* Log errors using `util.inspect` in case of fatal exceptions
(Ruben Bridgewater) #27243
* repl:
* Add `process.on('uncaughtException')` support (Ruben Bridgewater)
#27151
* stream:
* Implemented `Readable.from` async iterator utility (Guy Bedford)
#27660
* tls:
* Expose built-in root certificates (Ben Noordhuis)
#26415
* Support `net.Server` options (Luigi Pinca)
#27665
* Expose `keylog` event on TLSSocket (Alba Mendez)
#27654
* worker:
* Added the ability to unshift messages from the `MessagePort`
(Anna Henningsen) #27294
PR-URL: #27799
Notable changes:
* esm:
* Added the `--experimental-wasm-modules` flag to support
WebAssembly modules (Myles Borins & Guy Bedford)
#27659
* process:
* Log errors using `util.inspect` in case of fatal exceptions
(Ruben Bridgewater) #27243
* repl:
* Add `process.on('uncaughtException')` support (Ruben Bridgewater)
#27151
* stream:
* Implemented `Readable.from` async iterator utility (Guy Bedford)
#27660
* tls:
* Expose built-in root certificates (Ben Noordhuis)
#26415
* Support `net.Server` options (Luigi Pinca)
#27665
* Expose `keylog` event on TLSSocket (Alba Mendez)
#27654
* worker:
* Added the ability to unshift messages from the `MessagePort`
(Anna Henningsen) #27294
PR-URL: #27799
|
Ahem, very interesting! 😄 Any guidelines or examples on how to start playing with it in Node.js? |
|
I've created an example project using '--experimental-wasm-modules' for those who're interested. |
PR-URL: #27948 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This PR provides support for
node --experimental-modules --experimental-wasm-modulesto support the ES module integration of WebAssembly modules through egimport './module.wasm'.The semantics match the proposed ES module integration semantics for Web Assembly as specified in https://github.com/webassembly/esm-integration.
At the previous modules group meeting we got consensus approval for upstreaming this feature under the
--experimental-wasm-modulesflag.//cc @nodejs/modules
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes