summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/dispatch.ts3
-rw-r--r--js/main.ts24
-rw-r--r--js/os.ts63
3 files changed, 39 insertions, 51 deletions
diff --git a/js/dispatch.ts b/js/dispatch.ts
index 0c5c59553..d1da45b06 100644
--- a/js/dispatch.ts
+++ b/js/dispatch.ts
@@ -12,6 +12,9 @@ export const OP_IS_TTY = 4;
export const OP_ENV = 5;
export const OP_EXEC_PATH = 6;
export const OP_UTIME = 7;
+export const OP_SET_ENV = 8;
+export const OP_HOME_DIR = 9;
+export const OP_START = 10;
export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
switch (opId) {
diff --git a/js/main.ts b/js/main.ts
index 769f522a6..25e27b69f 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -22,12 +22,12 @@ export default function denoMain(
preserveDenoNamespace: boolean = true,
name?: string
): void {
- const startResMsg = os.start(preserveDenoNamespace, name);
+ const s = os.start(preserveDenoNamespace, name);
- setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
+ setVersions(s.denoVersion, s.v8Version);
// handle `--version`
- if (startResMsg.versionFlag()) {
+ if (s.versionFlag) {
console.log("deno:", deno.version.deno);
console.log("v8:", deno.version.v8);
console.log("typescript:", deno.version.typescript);
@@ -36,24 +36,22 @@ export default function denoMain(
setPrepareStackTrace(Error);
- const mainModule = startResMsg.mainModule();
- if (mainModule) {
- assert(mainModule.length > 0);
- setLocation(mainModule);
+ if (s.mainModule) {
+ assert(s.mainModule.length > 0);
+ setLocation(s.mainModule);
}
- const cwd = startResMsg.cwd();
- log("cwd", cwd);
+ log("cwd", s.cwd);
- for (let i = 1; i < startResMsg.argvLength(); i++) {
- args.push(startResMsg.argv(i));
+ for (let i = 1; i < s.argv.length; i++) {
+ args.push(s.argv[i]);
}
log("args", args);
Object.freeze(args);
if (window["_xevalWrapper"] !== undefined) {
- xevalMain(window["_xevalWrapper"] as XevalFunc, startResMsg.xevalDelim());
- } else if (!mainModule) {
+ xevalMain(window["_xevalWrapper"] as XevalFunc, s.xevalDelim);
+ } else if (!s.mainModule) {
replLoop();
}
}
diff --git a/js/os.ts b/js/os.ts
index f8938ab70..c44c27825 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -1,8 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { core } from "./core";
import * as dispatch from "./dispatch";
-import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
-import * as dispatchJson from "./dispatch_json";
+import { sendSync } from "./dispatch_json";
import { assert } from "./util";
import * as util from "./util";
import { window } from "./window";
@@ -24,21 +23,17 @@ function setGlobals(pid_: number, noColor_: boolean): void {
* console.log(Deno.isTTY().stdout);
*/
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
- return dispatchJson.sendSync(dispatch.OP_IS_TTY);
+ return sendSync(dispatch.OP_IS_TTY);
}
/** Exit the Deno process with optional exit code. */
export function exit(code = 0): never {
- dispatchJson.sendSync(dispatch.OP_EXIT, { code });
+ sendSync(dispatch.OP_EXIT, { code });
return util.unreachable();
}
function setEnv(key: string, value: string): void {
- const builder = flatbuffers.createBuilder();
- const key_ = builder.createString(key);
- const value_ = builder.createString(value);
- const inner = msg.SetEnv.createSetEnv(builder, key_, value_);
- sendSync(builder, msg.Any.SetEnv, inner);
+ sendSync(dispatch.OP_SET_ENV, { key, value });
}
/** Returns a snapshot of the environment variables at invocation. Mutating a
@@ -53,7 +48,7 @@ function setEnv(key: string, value: string): void {
* console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
*/
export function env(): { [index: string]: string } {
- const env = dispatchJson.sendSync(dispatch.OP_ENV);
+ const env = sendSync(dispatch.OP_ENV);
return new Proxy(env, {
set(obj, prop: string, value: string): boolean {
setEnv(prop, value);
@@ -62,35 +57,35 @@ export function env(): { [index: string]: string } {
});
}
-/** Send to the privileged side that we have setup and are ready. */
-function sendStart(): msg.StartRes {
- const builder = flatbuffers.createBuilder();
- const startOffset = msg.Start.createStart(builder, 0 /* unused */);
- const baseRes = sendSync(builder, msg.Any.Start, startOffset);
- assert(baseRes != null);
- assert(msg.Any.StartRes === baseRes!.innerType());
- const startResMsg = new msg.StartRes();
- assert(baseRes!.inner(startResMsg) != null);
- return startResMsg;
+interface Start {
+ cwd: string;
+ pid: number;
+ argv: string[];
+ mainModule: string; // Absolute URL.
+ debugFlag: boolean;
+ depsFlag: boolean;
+ typesFlag: boolean;
+ versionFlag: boolean;
+ denoVersion: string;
+ v8Version: string;
+ noColor: boolean;
+ xevalDelim: string;
}
// This function bootstraps an environment within Deno, it is shared both by
// the runtime and the compiler environments.
// @internal
-export function start(
- preserveDenoNamespace = true,
- source?: string
-): msg.StartRes {
+export function start(preserveDenoNamespace = true, source?: string): Start {
core.setAsyncHandler(dispatch.asyncMsgFromRust);
// 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.
- const startResMsg = sendStart();
+ const s = sendSync(dispatch.OP_START);
- util.setLogDebug(startResMsg.debugFlag(), source);
+ util.setLogDebug(s.debugFlag, source);
- setGlobals(startResMsg.pid(), startResMsg.noColor());
+ setGlobals(s.pid, s.noColor);
if (preserveDenoNamespace) {
util.immutableDefine(window, "Deno", window.Deno);
@@ -105,7 +100,7 @@ export function start(
assert(window.Deno === undefined);
}
- return startResMsg;
+ return s;
}
/**
@@ -113,18 +108,10 @@ export function start(
* Requires the `--allow-env` flag.
*/
export function homeDir(): string {
- const builder = flatbuffers.createBuilder();
- const inner = msg.HomeDir.createHomeDir(builder);
- const baseRes = sendSync(builder, msg.Any.HomeDir, inner)!;
- assert(msg.Any.HomeDirRes === baseRes.innerType());
- const res = new msg.HomeDirRes();
- assert(baseRes.inner(res) != null);
- const path = res.path();
-
+ const path = sendSync(dispatch.OP_HOME_DIR);
if (!path) {
throw new Error("Could not get home directory.");
}
-
return path;
}
@@ -133,5 +120,5 @@ export function homeDir(): string {
* Requires the `--allow-env` flag.
*/
export function execPath(): string {
- return dispatchJson.sendSync(dispatch.OP_EXEC_PATH);
+ return sendSync(dispatch.OP_EXEC_PATH);
}