summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-08-24 13:20:48 -0700
committerGitHub <noreply@github.com>2019-08-24 13:20:48 -0700
commit2235dd795d3cc6c24ff1bdd1bbdcd110b4b0bdfc (patch)
treea5811adc062cbb1c66f05c863c9be245cf4fd2d2 /js/os.ts
parentbdc0a13261deaa3748f51d9948b4e7b92864c324 (diff)
Revert json ops (#2814)
* Revert "port more ops to JSON (#2809)" This reverts commit 137f33733d365026903d40e7cde6e34ac6c36dcf. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit 79f82cf10ed1dbf91346994250d7311a4d74377a. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit 5b2baa5c990fbeae747e952c5dcd7a5369e950b1.
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts63
1 files changed, 38 insertions, 25 deletions
diff --git a/js/os.ts b/js/os.ts
index c44c27825..f8938ab70 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -1,7 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { core } from "./core";
import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import * as dispatchJson from "./dispatch_json";
import { assert } from "./util";
import * as util from "./util";
import { window } from "./window";
@@ -23,17 +24,21 @@ function setGlobals(pid_: number, noColor_: boolean): void {
* console.log(Deno.isTTY().stdout);
*/
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
- return sendSync(dispatch.OP_IS_TTY);
+ return dispatchJson.sendSync(dispatch.OP_IS_TTY);
}
/** Exit the Deno process with optional exit code. */
export function exit(code = 0): never {
- sendSync(dispatch.OP_EXIT, { code });
+ dispatchJson.sendSync(dispatch.OP_EXIT, { code });
return util.unreachable();
}
function setEnv(key: string, value: string): void {
- sendSync(dispatch.OP_SET_ENV, { key, value });
+ 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);
}
/** Returns a snapshot of the environment variables at invocation. Mutating a
@@ -48,7 +53,7 @@ function setEnv(key: string, value: string): void {
* console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
*/
export function env(): { [index: string]: string } {
- const env = sendSync(dispatch.OP_ENV);
+ const env = dispatchJson.sendSync(dispatch.OP_ENV);
return new Proxy(env, {
set(obj, prop: string, value: string): boolean {
setEnv(prop, value);
@@ -57,35 +62,35 @@ export function env(): { [index: string]: string } {
});
}
-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;
+/** 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;
}
// 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): Start {
+export function start(
+ preserveDenoNamespace = true,
+ source?: string
+): msg.StartRes {
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 s = sendSync(dispatch.OP_START);
+ const startResMsg = sendStart();
- util.setLogDebug(s.debugFlag, source);
+ util.setLogDebug(startResMsg.debugFlag(), source);
- setGlobals(s.pid, s.noColor);
+ setGlobals(startResMsg.pid(), startResMsg.noColor());
if (preserveDenoNamespace) {
util.immutableDefine(window, "Deno", window.Deno);
@@ -100,7 +105,7 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
assert(window.Deno === undefined);
}
- return s;
+ return startResMsg;
}
/**
@@ -108,10 +113,18 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
* Requires the `--allow-env` flag.
*/
export function homeDir(): string {
- const path = sendSync(dispatch.OP_HOME_DIR);
+ 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();
+
if (!path) {
throw new Error("Could not get home directory.");
}
+
return path;
}
@@ -120,5 +133,5 @@ export function homeDir(): string {
* Requires the `--allow-env` flag.
*/
export function execPath(): string {
- return sendSync(dispatch.OP_EXEC_PATH);
+ return dispatchJson.sendSync(dispatch.OP_EXEC_PATH);
}