From 60f6067cf9f8eeff10d5d9642e468bd3e9ad03b7 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 1 Aug 2018 15:56:27 -0400 Subject: [PATCH] Implement os.exit --- js/os.ts | 19 +++++++++++-------- src/reply.cc | 7 +++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/js/os.ts b/js/os.ts index 3f71c0e642..3344d1a51e 100644 --- a/js/os.ts +++ b/js/os.ts @@ -5,14 +5,17 @@ import { assert } from "./util"; import * as util from "./util"; import { flatbuffers } from "flatbuffers"; -export function exit(exitCode = 0): void { - assert(false, "Not Implemented"); - /* - pubInternal("os", { - command: fbs.Command.EXIT, - exitCode - }); - */ +export function exit(exitCode = 0): never { + const builder = new flatbuffers.Builder(); + fbs.Exit.startExit(builder); + fbs.Exit.addCode(builder, exitCode); + const msg = fbs.Exit.endExit(builder); + fbs.Base.startBase(builder); + fbs.Base.addMsg(builder, msg); + fbs.Base.addMsgType(builder, fbs.Any.Exit); + builder.finish(fbs.Base.endBase(builder)); + deno.send(builder.asUint8Array()); + throw Error("Unreachable"); } export function codeFetch( diff --git a/src/reply.cc b/src/reply.cc index 007f2c68b1..a6558890d3 100644 --- a/src/reply.cc +++ b/src/reply.cc @@ -71,6 +71,13 @@ void deno_handle_msg_from_js(Deno* d, deno_buf buf) { break; } + case deno::Any_Exit: { + auto msg = base->msg_as_Exit(); + uint32_t code = msg->code(); + exit(code); + break; + } + case deno::Any_NONE: CHECK(false && "Got message with msg_type == Any_NONE"); break;