Skip to content

Commit

Permalink
test: simplify test-wasi-start-validation.js
Browse files Browse the repository at this point in the history
This commit removes an extra block scope, and avoid reading
the simple.wasm file for every test case.

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>
  • Loading branch information
cjihrig authored and MylesBorins committed Dec 17, 2019
1 parent c2d9552 commit 5e268b8
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions test/wasi/test-wasi-start-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const assert = require('assert');
const { WASI } = require('wasi');

const fixtures = require('../common/fixtures');
const bufferSource = fixtures.readSync('simple.wasm');

{
const wasi = new WASI();
Expand All @@ -17,23 +18,19 @@ const fixtures = require('../common/fixtures');
);
}

{
(async () => {
const wasi = new WASI({});
(async () => {
const bufferSource = fixtures.readSync('simple.wasm');
const wasm = await WebAssembly.compile(bufferSource);
const instance = await WebAssembly.instantiate(wasm);
const wasm = await WebAssembly.compile(bufferSource);
const instance = await WebAssembly.instantiate(wasm);

assert.throws(
() => { wasi.start(instance); },
{ code: 'ERR_INVALID_ARG_TYPE', message: /\bWebAssembly\.Memory\b/ }
);
})();
}
assert.throws(
() => { wasi.start(instance); },
{ code: 'ERR_INVALID_ARG_TYPE', message: /\bWebAssembly\.Memory\b/ }
);
})();

(async () => {
const wasi = new WASI();
const bufferSource = fixtures.readSync('simple.wasm');
const wasm = await WebAssembly.compile(bufferSource);
const instance = await WebAssembly.instantiate(wasm);
const values = [undefined, null, 'foo', 42, true, false, () => {}];
Expand All @@ -54,7 +51,6 @@ const fixtures = require('../common/fixtures');

(async () => {
const wasi = new WASI();
const bufferSource = fixtures.readSync('simple.wasm');
const wasm = await WebAssembly.compile(bufferSource);
const instance = await WebAssembly.instantiate(wasm);

Expand All @@ -79,7 +75,6 @@ const fixtures = require('../common/fixtures');

(async () => {
const wasi = new WASI();
const bufferSource = fixtures.readSync('simple.wasm');
const wasm = await WebAssembly.compile(bufferSource);
const instance = await WebAssembly.instantiate(wasm);

Expand Down

0 comments on commit 5e268b8

Please sign in to comment.