From 6ca6db105d8db40af538e275f39612b569b9c141 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 | 164 ++++++++++++++---------- 3 files changed, 112 insertions(+), 78 deletions(-) diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 09ea12e811f..ebaf15525d0 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`