Skip to content
Prev Previous commit
Next Next commit
lib: rename setupInstance to finalizeBindings
  • Loading branch information
toyobayashi committed Jun 21, 2025
commit 3f9b57b68ea734c18d912862e2f78b479a10ac8a
24 changes: 10 additions & 14 deletions lib/wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,21 @@ class WASI {
this[kInstance] = undefined;
}

setupInstance(instance, memory) {
finalizeBindings(instance, {
memory = instance.exports.memory
} = {}) {
if (this[kStarted]) {
throw new ERR_WASI_ALREADY_STARTED();
}

validateObject(instance, 'instance');
validateObject(instance.exports, 'instance.exports');
Comment thread
toyobayashi marked this conversation as resolved.
Resolved

if (memory != null) {
if (!(memory instanceof WebAssembly.Memory)) {
throw new ERR_INVALID_ARG_TYPE('memory', 'WebAssembly.Memory', memory);
throw new ERR_INVALID_ARG_TYPE('options.memory', 'WebAssembly.Memory', memory);
}
this[kSetMemory](memory);
} else {
this[kSetMemory](instance.exports.memory);
}

this[kInstance] = instance;
Expand All @@ -133,11 +137,7 @@ class WASI {

// Must not export _initialize, must export _start
start(instance) {
if (this[kStarted]) {
throw new ERR_WASI_ALREADY_STARTED();
}

this.setupInstance(instance);
this.finalizeBindings(instance);

const { _start, _initialize } = this[kInstance].exports;

Expand All @@ -157,11 +157,7 @@ class WASI {

// Must not export _start, may optionally export _initialize
initialize(instance) {
if (this[kStarted]) {
throw new ERR_WASI_ALREADY_STARTED();
}

this.setupInstance(instance);
this.finalizeBindings(instance);

const { _start, _initialize } = this[kInstance].exports;

Expand Down