2020-01-27 21:12:25 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-06 21:45:39 -04:00
|
|
|
|
2020-01-27 21:12:25 -05:00
|
|
|
import { core } from "./core.ts";
|
2020-03-11 10:49:53 -04:00
|
|
|
import * as dispatchMinimal from "./ops/dispatch_minimal.ts";
|
|
|
|
import * as dispatchJson from "./ops/dispatch_json.ts";
|
2020-01-27 21:12:25 -05:00
|
|
|
import * as util from "./util.ts";
|
|
|
|
import { setBuildInfo } from "./build.ts";
|
|
|
|
import { setVersions } from "./version.ts";
|
|
|
|
import { setPrepareStackTrace } from "./error_stack.ts";
|
2020-04-28 12:35:23 -04:00
|
|
|
import { Start, opStart } from "./ops/runtime.ts";
|
2020-03-19 10:45:28 -04:00
|
|
|
import { handleTimerMacrotask } from "./web/timers.ts";
|
2020-01-27 21:12:25 -05:00
|
|
|
|
2020-03-11 10:49:53 -04:00
|
|
|
function getAsyncHandler(opName: string): (msg: Uint8Array) => void {
|
|
|
|
switch (opName) {
|
|
|
|
case "op_write":
|
|
|
|
case "op_read":
|
|
|
|
return dispatchMinimal.asyncMsgFromRust;
|
|
|
|
default:
|
|
|
|
return dispatchJson.asyncMsgFromRust;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 21:12:25 -05:00
|
|
|
// TODO(bartlomieju): temporary solution, must be fixed when moving
|
|
|
|
// dispatches to separate crates
|
|
|
|
export function initOps(): void {
|
2020-06-21 10:34:43 -04:00
|
|
|
const opsMap = core.ops();
|
|
|
|
for (const [name, opId] of Object.entries(opsMap)) {
|
2020-03-11 10:49:53 -04:00
|
|
|
core.setAsyncHandler(opId, getAsyncHandler(name));
|
2020-01-27 21:12:25 -05:00
|
|
|
}
|
2020-03-19 10:45:28 -04:00
|
|
|
core.setMacrotaskCallback(handleTimerMacrotask);
|
2020-01-27 21:12:25 -05:00
|
|
|
}
|
|
|
|
|
2020-03-11 16:57:24 -04:00
|
|
|
export function start(source?: string): Start {
|
2020-01-27 21:12:25 -05:00
|
|
|
initOps();
|
|
|
|
// First we send an empty `Start` message to let the privileged side know we
|
|
|
|
// are ready. The response should be a `StartRes` message containing the CLI
|
|
|
|
// args and other info.
|
2020-04-28 12:35:23 -04:00
|
|
|
const s = opStart();
|
2020-01-27 21:12:25 -05:00
|
|
|
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
2020-04-28 12:35:23 -04:00
|
|
|
setBuildInfo(s.target);
|
2020-01-27 21:12:25 -05:00
|
|
|
util.setLogDebug(s.debugFlag, source);
|
|
|
|
setPrepareStackTrace(Error);
|
|
|
|
return s;
|
|
|
|
}
|