From 8cc5e57af346110187145a31c21bc55391fe0675 Mon Sep 17 00:00:00 2001 From: toyobayashi Date: Tue, 25 Feb 2025 23:59:23 +0800 Subject: [PATCH] lib: expose `setupInstance` method on WASI class PR-URL: https://github.com/nodejs/node/pull/57214 Reviewed-By: Guy Bedford --- doc/api/wasi.md | 22 ++++ lib/wasi.js | 35 +++--- test/fixtures/wasi-preview-1.js | 194 +++++++++++++++++++++++++++++++- test/wasi/Makefile | 3 + test/wasi/c/pthread.c | 24 ++++ test/wasi/test-wasi.js | 1 + test/wasi/wasm/pthread.wasm | Bin 0 -> 33455 bytes tools/doc/type-parser.mjs | 2 + 8 files changed, 256 insertions(+), 25 deletions(-) create mode 100644 test/wasi/c/pthread.c create mode 100755 test/wasi/wasm/pthread.wasm diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 9b67d9a942b..ffa1ea6d8b2 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -243,6 +243,28 @@ export, then an exception is thrown. If `initialize()` is called more than once, an exception is thrown. +### `wasi.finalizeBindings(instance[, options])` + + + +* `instance` {WebAssembly.Instance} +* `options` {Object} + * `memory` {WebAssembly.Memory} **Default:** `instance.exports.memory`. + +Set up WASI host bindings to `instance` without calling `initialize()` +or `start()`. This method is useful when the WASI module is instantiated in +child threads for sharing the memory across threads. + +`finalizeBindings()` requires that either `instance` exports a +[`WebAssembly.Memory`][] named `memory` or user specify a +[`WebAssembly.Memory`][] object in `options.memory`. If the `memory` is invalid +an exception is thrown. + +`start()` and `initialize()` will call `finalizeBindings()` internally. +If `finalizeBindings()` is called more than once, an exception is thrown. + ### `wasi.wasiImport`