From 0ea1c6f5b07e18dad60bca5f1c7631be5b5005b3 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Fri, 4 Dec 2020 02:57:35 +0800 Subject: feat(std/wasi): add return on exit option (#8605) This adds an exitOnReturn option to context making it possible to unwind the stack on the exit(2) syscall instead of delegating to it directly. Use case is being able to treat WASI execution contexts as children that don't kill the parent on exit. --- std/wasi/snapshot_preview1_test.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (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 d7e29e195..01b91bc3e 100644 --- a/std/wasi/snapshot_preview1_test.ts +++ b/std/wasi/snapshot_preview1_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import Context from "./snapshot_preview1.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import Context, { ExitStatus } from "./snapshot_preview1.ts"; +import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; import { copy } from "../fs/mod.ts"; import * as path from "../path/mod.ts"; @@ -179,6 +179,24 @@ Deno.test("context_start", function () { TypeError, "export _start must be a function", ); + + try { + const context = new Context({ + exitOnReturn: false, + }); + context.start({ + exports: { + _start() { + const exit = context.exports["proc_exit"] as CallableFunction; + exit(0); + }, + memory: new WebAssembly.Memory({ initial: 1 }), + }, + }); + } catch (err) { + assert(err instanceof ExitStatus); + assertEquals(err.code, 0); + } }); Deno.test("context_initialize", function () { -- cgit v1.2.3