Revert json ops (#2814)

* Revert "port more ops to JSON (#2809)"

This reverts commit 137f33733d.

* Revert "port ops to JSON: compiler, errors, fetch, files (#2804)"

This reverts commit 79f82cf10e.

* Revert "Port rest of os ops to JSON (#2802)"

This reverts commit 5b2baa5c99.
This commit is contained in:
Ryan Dahl 2019-08-24 13:20:48 -07:00 committed by GitHub
parent bdc0a13261
commit 2235dd795d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 1968 additions and 1045 deletions

View file

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