Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 299d518

Browse filesBrowse files
cjihrigtargos
authored andcommitted
test: improve WASI start() coverage
This commit adds additional test cases to test-wasi-start-validation.js, which gets the JS test coverage of start() to 100%. PR-URL: #30972 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5d2ae05 commit 299d518
Copy full SHA for 299d518

File tree

Expand file treeCollapse file tree

1 file changed

+66
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+66
-1
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/wasi/test-wasi-start-validation.js
+66-1Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Flags: --experimental-wasi-unstable-preview0
22
'use strict';
33

4-
require('../common');
4+
const common = require('../common');
55
const assert = require('assert');
66
const { WASI } = require('wasi');
77

@@ -30,3 +30,68 @@ const fixtures = require('../common/fixtures');
3030
);
3131
})();
3232
}
33+
34+
(async () => {
35+
const wasi = new WASI();
36+
const bufferSource = fixtures.readSync('simple.wasm');
37+
const wasm = await WebAssembly.compile(bufferSource);
38+
const instance = await WebAssembly.instantiate(wasm);
39+
const values = [undefined, null, 'foo', 42, true, false, () => {}];
40+
let cnt = 0;
41+
42+
// Mock instance.exports to trigger start() validation.
43+
Object.defineProperty(instance, 'exports', {
44+
get() { return values[cnt++]; }
45+
});
46+
47+
values.forEach((val) => {
48+
assert.throws(
49+
() => { wasi.start(instance); },
50+
{ code: 'ERR_INVALID_ARG_TYPE', message: /\binstance\.exports\b/ }
51+
);
52+
});
53+
})();
54+
55+
(async () => {
56+
const wasi = new WASI();
57+
const bufferSource = fixtures.readSync('simple.wasm');
58+
const wasm = await WebAssembly.compile(bufferSource);
59+
const instance = await WebAssembly.instantiate(wasm);
60+
61+
// Mock instance.exports.memory to bypass start() validation.
62+
Object.defineProperty(instance, 'exports', {
63+
get() {
64+
return {
65+
memory: new WebAssembly.Memory({ initial: 1 })
66+
};
67+
}
68+
});
69+
70+
wasi.start(instance);
71+
assert.throws(
72+
() => { wasi.start(instance); },
73+
{
74+
code: 'ERR_WASI_ALREADY_STARTED',
75+
message: /^WASI instance has already started$/
76+
}
77+
);
78+
})();
79+
80+
(async () => {
81+
const wasi = new WASI();
82+
const bufferSource = fixtures.readSync('simple.wasm');
83+
const wasm = await WebAssembly.compile(bufferSource);
84+
const instance = await WebAssembly.instantiate(wasm);
85+
86+
// Mock instance.exports to bypass start() validation.
87+
Object.defineProperty(instance, 'exports', {
88+
get() {
89+
return {
90+
memory: new WebAssembly.Memory({ initial: 1 }),
91+
__wasi_unstable_reactor_start: common.mustCall()
92+
};
93+
}
94+
});
95+
96+
wasi.start(instance);
97+
})();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.