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:
parent
d15d334c24
commit
60f6067cf9
2 changed files with 18 additions and 8 deletions
19
js/os.ts
19
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(
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue