From 7f845e614bda08e10c4e8635c937b5ec506298ee Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 26 Apr 2020 01:20:10 -0400 Subject: [PATCH] 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 e66039f1b1ae02..23c2182fff8ffd 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -70,14 +70,15 @@ added: v12.16.0 * `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`