Skip to content

Commit c440735

Browse files
committed
update
1 parent 5a05d10 commit c440735

File tree

3 files changed

+11
-95
lines changed

3 files changed

+11
-95
lines changed

src/node_wasi.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,8 @@ void WASI::_SetMemory(const FunctionCallbackInfo<Value>& args) {
16451645
if (!args[0]->IsWasmMemoryObject()) {
16461646
return node::THROW_ERR_INVALID_ARG_TYPE(
16471647
wasi->env(),
1648-
"instance.exports.memory must be a WebAssembly.Memory object");
1648+
"\"instance.exports.memory\" property must be a WebAssembly.Memory "
1649+
"object");
16491650
}
16501651
wasi->memory_.Reset(wasi->env()->isolate(), args[0].As<WasmMemoryObject>());
16511652
}

test/wasi/test-wasi-initialize-validation.js

+6-47
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ const bufferSource = fixtures.readSync('simple.wasm');
4747

4848
Object.defineProperty(instance, 'exports', {
4949
get() {
50-
return { _initialize: 5, memory: new Uint8Array() };
50+
return {
51+
_initialize: 5,
52+
memory: new WebAssembly.Memory({ initial: 1 }),
53+
};
5154
},
5255
});
5356
assert.throws(
@@ -70,7 +73,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
7073
return {
7174
_start() {},
7275
_initialize() {},
73-
memory: new Uint8Array(),
76+
memory: new WebAssembly.Memory({ initial: 1 }),
7477
};
7578
}
7679
});
@@ -97,55 +100,11 @@ const bufferSource = fixtures.readSync('simple.wasm');
97100
() => { wasi.initialize(instance); },
98101
{
99102
code: 'ERR_INVALID_ARG_TYPE',
100-
message: /"instance\.exports\.memory" property must be of type object/
103+
message: /"instance\.exports\.memory" property must be a WebAssembly.Memory object/
101104
}
102105
);
103106
}
104107

105-
{
106-
// Verify that a non-ArrayBuffer memory.buffer is rejected.
107-
const wasi = new WASI({});
108-
const wasm = await WebAssembly.compile(bufferSource);
109-
const instance = await WebAssembly.instantiate(wasm);
110-
111-
Object.defineProperty(instance, 'exports', {
112-
get() {
113-
return {
114-
_initialize() {},
115-
memory: {},
116-
};
117-
}
118-
});
119-
// The error message is a little white lie because any object
120-
// with a .buffer property of type ArrayBuffer is accepted,
121-
// but 99% of the time a WebAssembly.Memory object is used.
122-
assert.throws(
123-
() => { wasi.initialize(instance); },
124-
{
125-
code: 'ERR_INVALID_ARG_TYPE',
126-
message: /"instance\.exports\.memory\.buffer" property must be an WebAssembly\.Memory/
127-
}
128-
);
129-
}
130-
131-
{
132-
// Verify that an argument that duck-types as a WebAssembly.Instance
133-
// is accepted.
134-
const wasi = new WASI({});
135-
const wasm = await WebAssembly.compile(bufferSource);
136-
const instance = await WebAssembly.instantiate(wasm);
137-
138-
Object.defineProperty(instance, 'exports', {
139-
get() {
140-
return {
141-
_initialize() {},
142-
memory: { buffer: new ArrayBuffer(0) },
143-
};
144-
}
145-
});
146-
wasi.initialize(instance);
147-
}
148-
149108
{
150109
// Verify that a WebAssembly.Instance from another VM context is accepted.
151110
const wasi = new WASI({});

test/wasi/test-wasi-start-validation.js

+3-47
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
4747

4848
Object.defineProperty(instance, 'exports', {
4949
get() {
50-
return { memory: new Uint8Array() };
50+
return { memory: new WebAssembly.Memory({ initial: 1 }) };
5151
},
5252
});
5353
assert.throws(
@@ -70,7 +70,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
7070
return {
7171
_start() {},
7272
_initialize() {},
73-
memory: new Uint8Array(),
73+
memory: new WebAssembly.Memory({ initial: 1 }),
7474
};
7575
}
7676
});
@@ -97,55 +97,11 @@ const bufferSource = fixtures.readSync('simple.wasm');
9797
() => { wasi.start(instance); },
9898
{
9999
code: 'ERR_INVALID_ARG_TYPE',
100-
message: /"instance\.exports\.memory" property must be of type object/
100+
message: /"instance\.exports\.memory" property must be a WebAssembly.Memory object/
101101
}
102102
);
103103
}
104104

105-
{
106-
// Verify that a non-ArrayBuffer memory.buffer is rejected.
107-
const wasi = new WASI({});
108-
const wasm = await WebAssembly.compile(bufferSource);
109-
const instance = await WebAssembly.instantiate(wasm);
110-
111-
Object.defineProperty(instance, 'exports', {
112-
get() {
113-
return {
114-
_start() {},
115-
memory: {},
116-
};
117-
}
118-
});
119-
// The error message is a little white lie because any object
120-
// with a .buffer property of type ArrayBuffer is accepted,
121-
// but 99% of the time a WebAssembly.Memory object is used.
122-
assert.throws(
123-
() => { wasi.start(instance); },
124-
{
125-
code: 'ERR_INVALID_ARG_TYPE',
126-
message: /"instance\.exports\.memory\.buffer" property must be an WebAssembly\.Memory/
127-
}
128-
);
129-
}
130-
131-
{
132-
// Verify that an argument that duck-types as a WebAssembly.Instance
133-
// is accepted.
134-
const wasi = new WASI({});
135-
const wasm = await WebAssembly.compile(bufferSource);
136-
const instance = await WebAssembly.instantiate(wasm);
137-
138-
Object.defineProperty(instance, 'exports', {
139-
get() {
140-
return {
141-
_start() {},
142-
memory: { buffer: new ArrayBuffer(0) },
143-
};
144-
}
145-
});
146-
wasi.start(instance);
147-
}
148-
149105
{
150106
// Verify that a WebAssembly.Instance from another VM context is accepted.
151107
const wasi = new WASI({});

0 commit comments

Comments
 (0)