1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

Implement os.exit

This commit is contained in:
Ryan Dahl 2018-08-01 15:56:27 -04:00
parent d15d334c24
commit 60f6067cf9
2 changed files with 18 additions and 8 deletions

View file

@ -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(

View file

@ -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;