From 4791ea09bd15fac9d7a057611d62c145f4f7a536 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 25 Apr 2020 23:38:34 -0400 Subject: [PATCH 1/2] wasi: rename __wasi_unstable_reactor_start() Upstream WASI has renamed __wasi_unstable_reactor_start() to _initialize(). This commit updates Node's WASI implementation to reflect that change. PR-URL: https://github.com/nodejs/node/pull/33073 Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan --- doc/api/wasi.md | 4 ++-- lib/wasi.js | 4 ++-- test/wasi/test-wasi-start-validation.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 1fe78aeecd6a1f..09ea12e811f6a5 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -78,8 +78,8 @@ added: Attempt to begin execution of `instance` by invoking its `_start()` export. If `instance` does not contain a `_start()` export, then `start()` attempts to -invoke the `__wasi_unstable_reactor_start()` export. If neither of those exports -is present on `instance`, then `start()` does nothing. +invoke the `_initialize()` export. If neither of those exports is present on +`instance`, then `start()` does nothing. `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named `memory`. If `instance` does not have a `memory` export an exception is thrown. diff --git a/lib/wasi.js b/lib/wasi.js index a6d90f0f57365f..4283216afc7547 100644 --- a/lib/wasi.js +++ b/lib/wasi.js @@ -97,8 +97,8 @@ class WASI { try { if (exports._start) exports._start(); - else if (exports.__wasi_unstable_reactor_start) - exports.__wasi_unstable_reactor_start(); + else if (exports._initialize) + exports._initialize(); } catch (err) { if (err !== kExitCode) { throw err; diff --git a/test/wasi/test-wasi-start-validation.js b/test/wasi/test-wasi-start-validation.js index a31c5847968491..94d31f2e1257c3 100644 --- a/test/wasi/test-wasi-start-validation.js +++ b/test/wasi/test-wasi-start-validation.js @@ -83,7 +83,7 @@ const bufferSource = fixtures.readSync('simple.wasm'); get() { return { memory: new WebAssembly.Memory({ initial: 1 }), - __wasi_unstable_reactor_start: common.mustCall() + _initialize: common.mustCall() }; } }); From 6ca6db105d8db40af538e275f39612b569b9c141 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 26 Apr 2020 01:20:10 -0400 Subject: [PATCH 2/2] wasi: update start() behavior to match spec _start() and _initialize() shouldn't be called from the same function, as they have different behavior. Furthermore, Node should throw if both are provided. This commit updates the implementation, docs, and tests accordingly. PR-URL: https://github.com/nodejs/node/pull/33073 Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan --- doc/api/wasi.md | 9 +- lib/wasi.js | 17 ++- test/wasi/test-wasi-start-validation.js | 162 ++++++++++++++---------- 3 files changed, 111 insertions(+), 77 deletions(-) diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 09ea12e811f6a5..ebaf15525d03f0 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -76,14 +76,15 @@ added: * `instance` {WebAssembly.Instance} -Attempt to begin execution of `instance` by invoking its `_start()` export. -If `instance` does not contain a `_start()` export, then `start()` attempts to -invoke the `_initialize()` export. If neither of those exports is present on -`instance`, then `start()` does nothing. +Attempt to begin execution of `instance` as a WASI command by invoking its +`_start()` export. If `instance` does not contain a `_start()` export, or if +`instance` contains an `_initialize()` export, then an exception is thrown. `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named `memory`. If `instance` does not have a `memory` export an exception is thrown. +If `start()` is called more than once, an exception is thrown. + ### `wasi.wasiImport`