From 77b2bc3bc1c986d8fce90a144bdfdb66a7537efe Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Thu, 10 Dec 2020 20:37:09 +0800 Subject: fix(std/wasi): disallow multiple starts (#8712) --- std/wasi/snapshot_preview1_test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'std/wasi/snapshot_preview1_test.ts') diff --git a/std/wasi/snapshot_preview1_test.ts b/std/wasi/snapshot_preview1_test.ts index f102f083d..55982545f 100644 --- a/std/wasi/snapshot_preview1_test.ts +++ b/std/wasi/snapshot_preview1_test.ts @@ -198,6 +198,23 @@ Deno.test("context_start", function () { assert(err instanceof ExitStatus); assertEquals(err.code, 0); } + + assertThrows( + () => { + const context = new Context({}); + context.start({ + exports: { + memory: new WebAssembly.Memory({ initial: 1 }), + _start() {}, + }, + }); + context.start({ + exports: {}, + }); + }, + Error, + "WebAssembly.Instance has already started", + ); }); Deno.test("context_initialize", function () { @@ -240,4 +257,20 @@ Deno.test("context_initialize", function () { TypeError, "export _initialize must be a function", ); + assertThrows( + () => { + const context = new Context({}); + context.initialize({ + exports: { + memory: new WebAssembly.Memory({ initial: 1 }), + _initialize() {}, + }, + }); + context.initialize({ + exports: {}, + }); + }, + Error, + "WebAssembly.Instance has already started", + ); }); -- cgit v1.2.3