summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/chmod.ts5
-rw-r--r--cli/js/chown.ts5
-rw-r--r--cli/js/compiler_api.ts13
-rw-r--r--cli/js/compiler_imports.ts5
-rw-r--r--cli/js/compiler_util.ts24
-rw-r--r--cli/js/copy_file.ts5
-rw-r--r--cli/js/dir.ts5
-rw-r--r--cli/js/dispatch.ts85
-rw-r--r--cli/js/dispatch_json.ts9
-rw-r--r--cli/js/dispatch_json_test.ts6
-rw-r--r--cli/js/dispatch_minimal_test.ts7
-rw-r--r--cli/js/error_stack.ts3
-rw-r--r--cli/js/fetch.ts3
-rw-r--r--cli/js/files.ts36
-rw-r--r--cli/js/format_error.ts5
-rw-r--r--cli/js/fs_events.ts5
-rw-r--r--cli/js/get_random_values.ts3
-rw-r--r--cli/js/link.ts5
-rw-r--r--cli/js/make_temp.ts9
-rw-r--r--cli/js/metrics.ts3
-rw-r--r--cli/js/mkdir.ts5
-rw-r--r--cli/js/net.ts13
-rw-r--r--cli/js/os.ts21
-rw-r--r--cli/js/performance.ts3
-rw-r--r--cli/js/permissions.ts7
-rw-r--r--cli/js/plugins.ts3
-rw-r--r--cli/js/process.ts7
-rw-r--r--cli/js/read_dir.ts5
-rw-r--r--cli/js/read_link.ts5
-rw-r--r--cli/js/realpath.ts5
-rw-r--r--cli/js/remove.ts5
-rw-r--r--cli/js/rename.ts5
-rw-r--r--cli/js/repl.ts5
-rw-r--r--cli/js/resources.ts3
-rw-r--r--cli/js/runtime.ts14
-rw-r--r--cli/js/runtime_worker.ts5
-rw-r--r--cli/js/signals.ts7
-rw-r--r--cli/js/stat.ts9
-rw-r--r--cli/js/symlink.ts5
-rw-r--r--cli/js/timers.ts5
-rw-r--r--cli/js/tls.ts7
-rw-r--r--cli/js/truncate.ts5
-rw-r--r--cli/js/url_test.ts6
-rw-r--r--cli/js/utime.ts5
-rw-r--r--cli/js/workers.ts9
45 files changed, 149 insertions, 261 deletions
diff --git a/cli/js/chmod.ts b/cli/js/chmod.ts
index 722a9054c..22bd8c40e 100644
--- a/cli/js/chmod.ts
+++ b/cli/js/chmod.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Changes the permission of a specific file/directory of specified path
* synchronously.
@@ -8,7 +7,7 @@ import * as dispatch from "./dispatch.ts";
* Deno.chmodSync("/path/to/file", 0o666);
*/
export function chmodSync(path: string, mode: number): void {
- sendSync(dispatch.OP_CHMOD, { path, mode });
+ sendSync("op_chmod", { path, mode });
}
/** Changes the permission of a specific file/directory of specified path.
@@ -16,5 +15,5 @@ export function chmodSync(path: string, mode: number): void {
* await Deno.chmod("/path/to/file", 0o666);
*/
export async function chmod(path: string, mode: number): Promise<void> {
- await sendAsync(dispatch.OP_CHMOD, { path, mode });
+ await sendAsync("op_chmod", { path, mode });
}
diff --git a/cli/js/chown.ts b/cli/js/chown.ts
index 373d075b0..d56be3dc2 100644
--- a/cli/js/chown.ts
+++ b/cli/js/chown.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/**
* Change owner of a regular file or directory synchronously. Unix only at the moment.
@@ -9,7 +8,7 @@ import * as dispatch from "./dispatch.ts";
* @param gid group id of the new owner
*/
export function chownSync(path: string, uid: number, gid: number): void {
- sendSync(dispatch.OP_CHOWN, { path, uid, gid });
+ sendSync("op_chown", { path, uid, gid });
}
/**
@@ -23,5 +22,5 @@ export async function chown(
uid: number,
gid: number
): Promise<void> {
- await sendAsync(dispatch.OP_CHOWN, { path, uid, gid });
+ await sendAsync("op_chown", { path, uid, gid });
}
diff --git a/cli/js/compiler_api.ts b/cli/js/compiler_api.ts
index d397ca568..33748d2b8 100644
--- a/cli/js/compiler_api.ts
+++ b/cli/js/compiler_api.ts
@@ -4,7 +4,6 @@
// compiler within Deno.
import { DiagnosticItem } from "./diagnostics.ts";
-import * as dispatch from "./dispatch.ts";
import { sendAsync } from "./dispatch_json.ts";
import * as util from "./util.ts";
@@ -296,9 +295,7 @@ export function transpileOnly(
sources,
options: options ? JSON.stringify(options) : undefined
};
- return sendAsync(dispatch.OP_TRANSPILE, payload).then(result =>
- JSON.parse(result)
- );
+ return sendAsync("op_transpile", payload).then(result => JSON.parse(result));
}
/** Takes a root module name, any optionally a record set of sources. Resolves
@@ -344,9 +341,7 @@ export function compile(
sources: !!sources,
options
});
- return sendAsync(dispatch.OP_COMPILE, payload).then(result =>
- JSON.parse(result)
- );
+ return sendAsync("op_compile", payload).then(result => JSON.parse(result));
}
/** Takes a root module name, and optionally a record set of sources. Resolves
@@ -393,7 +388,5 @@ export function bundle(
sources: !!sources,
options
});
- return sendAsync(dispatch.OP_COMPILE, payload).then(result =>
- JSON.parse(result)
- );
+ return sendAsync("op_compile", payload).then(result => JSON.parse(result));
}
diff --git a/cli/js/compiler_imports.ts b/cli/js/compiler_imports.ts
index 09b2d4ba1..6e8a6585d 100644
--- a/cli/js/compiler_imports.ts
+++ b/cli/js/compiler_imports.ts
@@ -6,7 +6,6 @@ import {
SourceFileJson
} from "./compiler_sourcefile.ts";
import { cwd } from "./dir.ts";
-import * as dispatch from "./dispatch.ts";
import { sendAsync, sendSync } from "./dispatch_json.ts";
import { assert } from "./util.ts";
import * as util from "./util.ts";
@@ -68,7 +67,7 @@ export function resolveModules(
referrer?: string
): string[] {
util.log("compiler_imports::resolveModules", { specifiers, referrer });
- return sendSync(dispatch.OP_RESOLVE_MODULES, { specifiers, referrer });
+ return sendSync("op_resolve_modules", { specifiers, referrer });
}
/** Ops to Rust to fetch modules meta data. */
@@ -77,7 +76,7 @@ function fetchSourceFiles(
referrer?: string
): Promise<SourceFileJson[]> {
util.log("compiler_imports::fetchSourceFiles", { specifiers, referrer });
- return sendAsync(dispatch.OP_FETCH_SOURCE_FILES, {
+ return sendAsync("op_fetch_source_files", {
specifiers,
referrer
});
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts
index 6da38ab3b..8a043d7d1 100644
--- a/cli/js/compiler_util.ts
+++ b/cli/js/compiler_util.ts
@@ -6,7 +6,6 @@ import { buildBundle } from "./compiler_bundler.ts";
import { ConfigureResponse, Host } from "./compiler_host.ts";
import { SourceFile } from "./compiler_sourcefile.ts";
import { sendSync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { TextDecoder, TextEncoder } from "./text_encoding.ts";
import { core } from "./core.ts";
import * as util from "./util.ts";
@@ -71,7 +70,7 @@ function cache(
if (emittedFileName.endsWith(".map")) {
// Source Map
- sendSync(dispatch.OP_CACHE, {
+ sendSync("op_cache", {
extension: ".map",
moduleId,
contents
@@ -81,7 +80,7 @@ function cache(
emittedFileName.endsWith(".json")
) {
// Compiled JavaScript
- sendSync(dispatch.OP_CACHE, {
+ sendSync("op_cache", {
extension: ".js",
moduleId,
contents
@@ -91,30 +90,15 @@ function cache(
}
}
-let OP_FETCH_ASSET: number;
const encoder = new TextEncoder();
const decoder = new TextDecoder();
/** Retrieve an asset from Rust. */
export function getAsset(name: string): string {
- // this path should only be called for assets that are lazily loaded at
- // runtime
- if (dispatch.OP_FETCH_ASSET) {
- util.log("compiler_util::getAsset", name);
- return sendSync(dispatch.OP_FETCH_ASSET, { name }).sourceCode;
- }
-
- // this path should only be taken during snapshotting
- if (!OP_FETCH_ASSET) {
- const ops = core.ops();
- const opFetchAsset = ops["fetch_asset"];
- assert(opFetchAsset, "OP_FETCH_ASSET is not registered");
- OP_FETCH_ASSET = opFetchAsset;
- }
-
+ const opId = core.ops()["op_fetch_asset"];
// We really don't want to depend on JSON dispatch during snapshotting, so
// this op exchanges strings with Rust as raw byte arrays.
- const sourceCodeBytes = core.dispatch(OP_FETCH_ASSET, encoder.encode(name));
+ const sourceCodeBytes = core.dispatch(opId, encoder.encode(name));
return decoder.decode(sourceCodeBytes!);
}
diff --git a/cli/js/copy_file.ts b/cli/js/copy_file.ts
index 538a7a0ba..8ab013aab 100644
--- a/cli/js/copy_file.ts
+++ b/cli/js/copy_file.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Copies the contents of a file to another by name synchronously.
* Creates a new file if target does not exists, and if target exists,
@@ -12,7 +11,7 @@ import * as dispatch from "./dispatch.ts";
* Deno.copyFileSync("from.txt", "to.txt");
*/
export function copyFileSync(from: string, to: string): void {
- sendSync(dispatch.OP_COPY_FILE, { from, to });
+ sendSync("op_copy_file", { from, to });
}
/** Copies the contents of a file to another by name.
@@ -26,5 +25,5 @@ export function copyFileSync(from: string, to: string): void {
* await Deno.copyFile("from.txt", "to.txt");
*/
export async function copyFile(from: string, to: string): Promise<void> {
- await sendAsync(dispatch.OP_COPY_FILE, { from, to });
+ await sendAsync("op_copy_file", { from, to });
}
diff --git a/cli/js/dir.ts b/cli/js/dir.ts
index d9758570e..eea2ef691 100644
--- a/cli/js/dir.ts
+++ b/cli/js/dir.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/**
* `cwd()` Return a string representing the current working directory.
@@ -10,7 +9,7 @@ import * as dispatch from "./dispatch.ts";
* throws `NotFound` exception if directory not available
*/
export function cwd(): string {
- return sendSync(dispatch.OP_CWD);
+ return sendSync("op_cwd");
}
/**
@@ -18,5 +17,5 @@ export function cwd(): string {
* throws `NotFound` exception if directory not available
*/
export function chdir(directory: string): void {
- sendSync(dispatch.OP_CHDIR, { directory });
+ sendSync("op_chdir", { directory });
}
diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts
index 1b7e23463..db10db8ca 100644
--- a/cli/js/dispatch.ts
+++ b/cli/js/dispatch.ts
@@ -3,87 +3,6 @@ import * as minimal from "./dispatch_minimal.ts";
import * as json from "./dispatch_json.ts";
import { AsyncHandler } from "./plugins.ts";
-// These consts are shared with Rust. Update with care.
-export let OP_READ: number;
-export let OP_WRITE: number;
-export let OP_EXIT: number;
-export let OP_IS_TTY: number;
-export let OP_ENV: number;
-export let OP_EXEC_PATH: number;
-export let OP_UTIME: number;
-export let OP_SET_ENV: number;
-export let OP_GET_ENV: number;
-export let OP_GET_DIR: number;
-export let OP_START: number;
-export let OP_APPLY_SOURCE_MAP: number;
-export let OP_FORMAT_ERROR: number;
-export let OP_FORMAT_DIAGNOSTIC: number;
-export let OP_CACHE: number;
-export let OP_RESOLVE_MODULES: number;
-export let OP_FETCH_ASSET: number;
-export let OP_FETCH_SOURCE_FILES: number;
-export let OP_OPEN: number;
-export let OP_CLOSE: number;
-export let OP_SEEK: number;
-export let OP_FETCH: number;
-export let OP_METRICS: number;
-export let OP_REPL_START: number;
-export let OP_REPL_READLINE: number;
-export let OP_ACCEPT: number;
-export let OP_ACCEPT_TLS: number;
-export let OP_RECEIVE: number;
-export let OP_SEND: number;
-export let OP_CONNECT: number;
-export let OP_SHUTDOWN: number;
-export let OP_LISTEN: number;
-export let OP_LISTEN_TLS: number;
-export let OP_RESOURCES: number;
-export let OP_GET_RANDOM_VALUES: number;
-export let OP_GLOBAL_TIMER_STOP: number;
-export let OP_GLOBAL_TIMER: number;
-export let OP_NOW: number;
-export let OP_QUERY_PERMISSION: number;
-export let OP_REVOKE_PERMISSION: number;
-export let OP_REQUEST_PERMISSION: number;
-export let OP_CREATE_WORKER: number;
-export let OP_HOST_POST_MESSAGE: number;
-export let OP_HOST_TERMINATE_WORKER: number;
-export let OP_HOST_GET_MESSAGE: number;
-export let OP_WORKER_POST_MESSAGE: number;
-export let OP_WORKER_CLOSE: number;
-export let OP_RUN: number;
-export let OP_RUN_STATUS: number;
-export let OP_KILL: number;
-export let OP_CHDIR: number;
-export let OP_MKDIR: number;
-export let OP_CHMOD: number;
-export let OP_CHOWN: number;
-export let OP_REMOVE: number;
-export let OP_COPY_FILE: number;
-export let OP_STAT: number;
-export let OP_REALPATH: number;
-export let OP_READ_DIR: number;
-export let OP_RENAME: number;
-export let OP_LINK: number;
-export let OP_SYMLINK: number;
-export let OP_READ_LINK: number;
-export let OP_TRUNCATE: number;
-export let OP_MAKE_TEMP_DIR: number;
-export let OP_MAKE_TEMP_FILE: number;
-export let OP_CWD: number;
-export let OP_CONNECT_TLS: number;
-export let OP_HOSTNAME: number;
-export let OP_OPEN_PLUGIN: number;
-export let OP_FS_EVENTS_OPEN: number;
-export let OP_FS_EVENTS_POLL: number;
-export let OP_COMPILE: number;
-export let OP_TRANSPILE: number;
-export let OP_SIGNAL_BIND: number;
-export let OP_SIGNAL_UNBIND: number;
-export let OP_SIGNAL_POLL: number;
-export let OP_LOADAVG: number;
-export let OP_OS_RELEASE: number;
-
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
export function setPluginAsyncHandler(
@@ -95,8 +14,8 @@ export function setPluginAsyncHandler(
export function getAsyncHandler(opName: string): (msg: Uint8Array) => void {
switch (opName) {
- case "OP_WRITE":
- case "OP_READ":
+ case "op_write":
+ case "op_read":
return minimal.asyncMsgFromRust;
default:
return json.asyncMsgFromRust;
diff --git a/cli/js/dispatch_json.ts b/cli/js/dispatch_json.ts
index b0859e1ba..12c2d8821 100644
--- a/cli/js/dispatch_json.ts
+++ b/cli/js/dispatch_json.ts
@@ -2,6 +2,7 @@
import * as util from "./util.ts";
import { TextEncoder, TextDecoder } from "./text_encoding.ts";
import { core } from "./core.ts";
+import { OPS_CACHE } from "./runtime.ts";
import { ErrorKind, constructError } from "./errors.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -54,10 +55,12 @@ export function asyncMsgFromRust(resUi8: Uint8Array): void {
}
export function sendSync(
- opId: number,
+ opName: string,
args: object = {},
zeroCopy?: Uint8Array
): Ok {
+ const opId = OPS_CACHE[opName];
+ util.log("sendSync", opName, opId);
const argsUi8 = encode(args);
const resUi8 = core.dispatch(opId, argsUi8, zeroCopy);
util.assert(resUi8 != null);
@@ -68,10 +71,12 @@ export function sendSync(
}
export async function sendAsync(
- opId: number,
+ opName: string,
args: object = {},
zeroCopy?: Uint8Array
): Promise<Ok> {
+ const opId = OPS_CACHE[opName];
+ util.log("sendAsync", opName, opId);
const promiseId = nextPromiseId();
args = Object.assign(args, { promiseId });
const promise = util.createResolvable<Ok>();
diff --git a/cli/js/dispatch_json_test.ts b/cli/js/dispatch_json_test.ts
index 90f93746e..50efeb360 100644
--- a/cli/js/dispatch_json_test.ts
+++ b/cli/js/dispatch_json_test.ts
@@ -1,7 +1,7 @@
import {
+ assert,
test,
testPerm,
- assert,
assertMatch,
unreachable
} from "./test_util.ts";
@@ -24,7 +24,9 @@ testPerm({ read: true }, async function sendAsyncStackTrace(): Promise<void> {
test(async function malformedJsonControlBuffer(): Promise<void> {
// @ts-ignore
- const res = Deno.core.send(10, new Uint8Array([1, 2, 3, 4, 5]));
+ const opId = Deno.core.ops()["op_open"];
+ // @ts-ignore
+ const res = Deno.core.send(opId, new Uint8Array([1, 2, 3, 4, 5]));
const resText = new TextDecoder().decode(res);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const resJson = JSON.parse(resText) as any;
diff --git a/cli/js/dispatch_minimal_test.ts b/cli/js/dispatch_minimal_test.ts
index 75381204f..2ae3fceeb 100644
--- a/cli/js/dispatch_minimal_test.ts
+++ b/cli/js/dispatch_minimal_test.ts
@@ -1,8 +1,8 @@
import {
- test,
assert,
assertEquals,
assertMatch,
+ test,
unreachable
} from "./test_util.ts";
@@ -16,8 +16,9 @@ const readErrorStackPattern = new RegExp(
test(async function sendAsyncStackTrace(): Promise<void> {
const buf = new Uint8Array(10);
+ const rid = 10;
try {
- await Deno.read(10, buf);
+ await Deno.read(rid, buf);
unreachable();
} catch (error) {
assertMatch(error.stack, readErrorStackPattern);
@@ -26,7 +27,7 @@ test(async function sendAsyncStackTrace(): Promise<void> {
test(async function malformedMinimalControlBuffer(): Promise<void> {
// @ts-ignore
- const readOpId = Deno.core.ops()["read"];
+ const readOpId = Deno.core.ops()["op_read"];
// @ts-ignore
const res = Deno.core.send(readOpId, new Uint8Array([1, 2, 3, 4, 5]));
const header = res.slice(0, 12);
diff --git a/cli/js/error_stack.ts b/cli/js/error_stack.ts
index 7f19773bd..ff15cee60 100644
--- a/cli/js/error_stack.ts
+++ b/cli/js/error_stack.ts
@@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// Some of the code here is adapted directly from V8 and licensed under a BSD
// style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
import { assert } from "./util.ts";
import { exposeForTest } from "./internals.ts";
@@ -44,7 +43,7 @@ export function applySourceMap(location: Location): Location {
const { filename, line, column } = location;
// On this side, line/column are 1 based, but in the source maps, they are
// 0 based, so we have to convert back and forth
- const res = sendSync(dispatch.OP_APPLY_SOURCE_MAP, {
+ const res = sendSync("op_apply_source_map", {
filename,
line: line - 1,
column: column - 1
diff --git a/cli/js/fetch.ts b/cli/js/fetch.ts
index 43a23cb59..2f493c02e 100644
--- a/cli/js/fetch.ts
+++ b/cli/js/fetch.ts
@@ -15,7 +15,6 @@ import { Buffer } from "./buffer.ts";
import { FormData } from "./form_data.ts";
import { URL } from "./url.ts";
import { URLSearchParams } from "./url_search_params.ts";
-import * as dispatch from "./dispatch.ts";
import { sendAsync } from "./dispatch_json.ts";
function getHeaderValueParams(value: string): Map<string, string> {
@@ -469,7 +468,7 @@ async function sendFetchReq(
headers: headerArray
};
- return (await sendAsync(dispatch.OP_FETCH, args, zeroCopy)) as FetchResponse;
+ return (await sendAsync("op_fetch", args, zeroCopy)) as FetchResponse;
}
/** Fetch a resource from the network. */
diff --git a/cli/js/files.ts b/cli/js/files.ts
index c966b9fa0..903564cd1 100644
--- a/cli/js/files.ts
+++ b/cli/js/files.ts
@@ -11,11 +11,15 @@ import {
SyncSeeker
} from "./io.ts";
import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal.ts";
-import * as dispatch from "./dispatch.ts";
import {
sendSync as sendSyncJson,
sendAsync as sendAsyncJson
} from "./dispatch_json.ts";
+import { OPS_CACHE } from "./runtime.ts";
+
+// This is done because read/write are extremely performance sensitive.
+let OP_READ = -1;
+let OP_WRITE = -1;
/** Open a file and return an instance of the `File` object
* synchronously.
@@ -44,7 +48,7 @@ export function openSync(
options = modeOrOptions;
}
- const rid = sendSyncJson(dispatch.OP_OPEN, { filename, options, mode });
+ const rid = sendSyncJson("op_open", { filename, options, mode });
return new File(rid);
}
@@ -78,7 +82,7 @@ export async function open(
options = modeOrOptions;
}
- const rid = await sendAsyncJson(dispatch.OP_OPEN, {
+ const rid = await sendAsyncJson("op_open", {
filename,
options,
mode
@@ -118,7 +122,10 @@ export function readSync(rid: number, p: Uint8Array): number | EOF {
if (p.length == 0) {
return 0;
}
- const nread = sendSyncMinimal(dispatch.OP_READ, rid, p);
+ if (OP_READ < 0) {
+ OP_READ = OPS_CACHE["op_read"];
+ }
+ const nread = sendSyncMinimal(OP_READ, rid, p);
if (nread < 0) {
throw new Error("read error");
} else if (nread == 0) {
@@ -141,7 +148,10 @@ export async function read(rid: number, p: Uint8Array): Promise<number | EOF> {
if (p.length == 0) {
return 0;
}
- const nread = await sendAsyncMinimal(dispatch.OP_READ, rid, p);
+ if (OP_READ < 0) {
+ OP_READ = OPS_CACHE["op_read"];
+ }
+ const nread = await sendAsyncMinimal(OP_READ, rid, p);
if (nread < 0) {
throw new Error("read error");
} else if (nread == 0) {
@@ -161,7 +171,10 @@ export async function read(rid: number, p: Uint8Array): Promise<number | EOF> {
* Deno.writeSync(file.rid, data);
*/
export function writeSync(rid: number, p: Uint8Array): number {
- const result = sendSyncMinimal(dispatch.OP_WRITE, rid, p);
+ if (OP_WRITE < 0) {
+ OP_WRITE = OPS_CACHE["op_write"];
+ }
+ const result = sendSyncMinimal(OP_WRITE, rid, p);
if (result < 0) {
throw new Error("write error");
} else {
@@ -180,7 +193,10 @@ export function writeSync(rid: number, p: Uint8Array): number {
*
*/
export async function write(rid: number, p: Uint8Array): Promise<number> {
- const result = await sendAsyncMinimal(dispatch.OP_WRITE, rid, p);
+ if (OP_WRITE < 0) {
+ OP_WRITE = OPS_CACHE["op_write"];
+ }
+ const result = await sendAsyncMinimal(OP_WRITE, rid, p);
if (result < 0) {
throw new Error("write error");
} else {
@@ -194,7 +210,7 @@ export async function write(rid: number, p: Uint8Array): Promise<number> {
* Deno.seekSync(file.rid, 0, 0);
*/
export function seekSync(rid: number, offset: number, whence: SeekMode): void {
- sendSyncJson(dispatch.OP_SEEK, { rid, offset, whence });
+ sendSyncJson("op_seek", { rid, offset, whence });
}
/** Seek a file ID to the given offset under mode given by `whence`.
@@ -207,12 +223,12 @@ export async function seek(
offset: number,
whence: SeekMode
): Promise<void> {
- await sendAsyncJson(dispatch.OP_SEEK, { rid, offset, whence });
+ await sendAsyncJson("op_seek", { rid, offset, whence });
}
/** Close the file ID. */
export function close(rid: number): void {
- sendSyncJson(dispatch.OP_CLOSE, { rid });
+ sendSyncJson("op_close", { rid });
}
/** The Deno abstraction for reading and writing files. */
diff --git a/cli/js/format_error.ts b/cli/js/format_error.ts
index 63250473b..21c4bcfa8 100644
--- a/cli/js/format_error.ts
+++ b/cli/js/format_error.ts
@@ -1,11 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { DiagnosticItem } from "./diagnostics.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
// TODO(bartlomieju): move to `repl.ts`?
export function formatError(errString: string): string {
- const res = sendSync(dispatch.OP_FORMAT_ERROR, { error: errString });
+ const res = sendSync("op_format_error", { error: errString });
return res.error;
}
@@ -14,5 +13,5 @@ export function formatError(errString: string): string {
* @param items An array of diagnostic items to format
*/
export function formatDiagnostics(items: DiagnosticItem[]): string {
- return sendSync(dispatch.OP_FORMAT_DIAGNOSTIC, { items });
+ return sendSync("op_format_diagnostic", { items });
}
diff --git a/cli/js/fs_events.ts b/cli/js/fs_events.ts
index a4deff48a..b549b3d4d 100644
--- a/cli/js/fs_events.ts
+++ b/cli/js/fs_events.ts
@@ -1,6 +1,5 @@
// Copyright 2019 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { close } from "./files.ts";
export interface FsEvent {
@@ -13,11 +12,11 @@ class FsEvents implements AsyncIterableIterator<FsEvent> {
constructor(paths: string[], options: { recursive: boolean }) {
const { recursive } = options;
- this.rid = sendSync(dispatch.OP_FS_EVENTS_OPEN, { recursive, paths });
+ this.rid = sendSync("op_fs_events_open", { recursive, paths });
}
async next(): Promise<IteratorResult<FsEvent>> {
- return await sendAsync(dispatch.OP_FS_EVENTS_POLL, {
+ return await sendAsync("op_fs_events_poll", {
rid: this.rid
});
}
diff --git a/cli/js/get_random_values.ts b/cli/js/get_random_values.ts
index e8b61b268..799173702 100644
--- a/cli/js/get_random_values.ts
+++ b/cli/js/get_random_values.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
import { assert } from "./util.ts";
@@ -26,6 +25,6 @@ export function getRandomValues<
typedArray.byteOffset,
typedArray.byteLength
);
- sendSync(dispatch.OP_GET_RANDOM_VALUES, {}, ui8);
+ sendSync("op_get_random_values", {}, ui8);
return typedArray;
}
diff --git a/cli/js/link.ts b/cli/js/link.ts
index dc04d717a..4d66d1cf9 100644
--- a/cli/js/link.ts
+++ b/cli/js/link.ts
@@ -1,13 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Synchronously creates `newname` as a hard link to `oldname`.
*
* Deno.linkSync("old/name", "new/name");
*/
export function linkSync(oldname: string, newname: string): void {
- sendSync(dispatch.OP_LINK, { oldname, newname });
+ sendSync("op_link", { oldname, newname });
}
/** Creates `newname` as a hard link to `oldname`.
@@ -15,5 +14,5 @@ export function linkSync(oldname: string, newname: string): void {
* await Deno.link("old/name", "new/name");
*/
export async function link(oldname: string, newname: string): Promise<void> {
- await sendAsync(dispatch.OP_LINK, { oldname, newname });
+ await sendAsync("op_link", { oldname, newname });
}
diff --git a/cli/js/make_temp.ts b/cli/js/make_temp.ts
index 8b15ab184..7b0038388 100644
--- a/cli/js/make_temp.ts
+++ b/cli/js/make_temp.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
export interface MakeTempOptions {
dir?: string;
@@ -14,7 +13,7 @@ export interface MakeTempOptions {
* const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });
*/
export function makeTempDirSync(options: MakeTempOptions = {}): string {
- return sendSync(dispatch.OP_MAKE_TEMP_DIR, options);
+ return sendSync("op_make_temp_dir", options);
}
/** makeTempDir creates a new temporary directory in the directory `dir`, its
@@ -31,7 +30,7 @@ export function makeTempDirSync(options: MakeTempOptions = {}): string {
export async function makeTempDir(
options: MakeTempOptions = {}
): Promise<string> {
- return await sendAsync(dispatch.OP_MAKE_TEMP_DIR, options);
+ return await sendAsync("op_make_temp_dir", options);
}
/** makeTempFileSync is the synchronous version of `makeTempFile`.
@@ -40,7 +39,7 @@ export async function makeTempDir(
* const tempFileName1 = Deno.makeTempFileSync({ prefix: 'my_temp' });
*/
export function makeTempFileSync(options: MakeTempOptions = {}): string {
- return sendSync(dispatch.OP_MAKE_TEMP_FILE, options);
+ return sendSync("op_make_temp_file", options);
}
/** makeTempFile creates a new temporary file in the directory `dir`, its
@@ -57,5 +56,5 @@ export function makeTempFileSync(options: MakeTempOptions = {}): string {
export async function makeTempFile(
options: MakeTempOptions = {}
): Promise<string> {
- return await sendAsync(dispatch.OP_MAKE_TEMP_FILE, options);
+ return await sendAsync("op_make_temp_file", options);
}
diff --git a/cli/js/metrics.ts b/cli/js/metrics.ts
index 90c99ff89..b735dc6b3 100644
--- a/cli/js/metrics.ts
+++ b/cli/js/metrics.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
export interface Metrics {
@@ -24,5 +23,5 @@ export interface Metrics {
* └──────────────────┴────────┘
*/
export function metrics(): Metrics {
- return sendSync(dispatch.OP_METRICS);
+ return sendSync("op_metrics");
}
diff --git a/cli/js/mkdir.ts b/cli/js/mkdir.ts
index 836b785cf..532d2b73c 100644
--- a/cli/js/mkdir.ts
+++ b/cli/js/mkdir.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
// TODO(ry) The complexity in argument parsing is to support deprecated forms of
// mkdir and mkdirSync.
@@ -45,7 +44,7 @@ export function mkdirSync(
optionsOrRecursive?: MkdirOption | boolean,
mode?: number
): void {
- sendSync(dispatch.OP_MKDIR, mkdirArgs(path, optionsOrRecursive, mode));
+ sendSync("op_mkdir", mkdirArgs(path, optionsOrRecursive, mode));
}
/** Creates a new directory with the specified path.
@@ -62,5 +61,5 @@ export async function mkdir(
optionsOrRecursive?: MkdirOption | boolean,
mode?: number
): Promise<void> {
- await sendAsync(dispatch.OP_MKDIR, mkdirArgs(path, optionsOrRecursive, mode));
+ await sendAsync("op_mkdir", mkdirArgs(path, optionsOrRecursive, mode));
}
diff --git a/cli/js/net.ts b/cli/js/net.ts
index 9d82a3a3f..e03175b57 100644
--- a/cli/js/net.ts
+++ b/cli/js/net.ts
@@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { EOF, Reader, Writer, Closer } from "./io.ts";
import { read, write, close } from "./files.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync, sendAsync } from "./dispatch_json.ts";
export type Transport = "tcp" | "udp";
@@ -72,7 +71,7 @@ export enum ShutdownMode {
* Deno.shutdown(conn.rid, Deno.ShutdownMode.Write);
*/
export function shutdown(rid: number, how: ShutdownMode): void {
- sendSync(dispatch.OP_SHUTDOWN, { rid, how });
+ sendSync("op_shutdown", { rid, how });
}
export class ConnImpl implements Conn {
@@ -117,7 +116,7 @@ export class ListenerImpl implements Listener {
) {}
async accept(): Promise<Conn> {
- const res = await sendAsync(dispatch.OP_ACCEPT, { rid: this.rid });
+ const res = await sendAsync("op_accept", { rid: this.rid });
return new ConnImpl(res.rid, res.remoteAddr, res.localAddr);
}
@@ -152,7 +151,7 @@ export async function recvfrom(
rid: number,
p: Uint8Array
): Promise<[number, Addr]> {
- const { size, remoteAddr } = await sendAsync(dispatch.OP_RECEIVE, { rid }, p);
+ const { size, remoteAddr } = await sendAsync("op_receive", { rid }, p);
return [size, remoteAddr];
}
@@ -175,7 +174,7 @@ export class UDPConnImpl implements UDPConn {
const remote = { hostname: "127.0.0.1", transport: "udp", ...addr };
if (remote.transport !== "udp") throw Error("Remote transport must be UDP");
const args = { ...remote, rid: this.rid };
- await sendAsync(dispatch.OP_SEND, args, p);
+ await sendAsync("op_send", args, p);
}
close(): void {
@@ -253,7 +252,7 @@ export function listen(
export function listen(options: ListenOptions & { transport: "udp" }): UDPConn;
export function listen(options: ListenOptions): Listener | UDPConn {
const args = { ...listenDefaults, ...options };
- const res = sendSync(dispatch.OP_LISTEN, args);
+ const res = sendSync("op_listen", args);
if (args.transport === "tcp") {
return new ListenerImpl(res.rid, res.localAddr);
@@ -289,6 +288,6 @@ const connectDefaults = { hostname: "127.0.0.1", transport: "tcp" };
*/
export async function connect(options: ConnectOptions): Promise<Conn> {
options = Object.assign(connectDefaults, options);
- const res = await sendAsync(dispatch.OP_CONNECT, options);
+ const res = await sendAsync("op_connect", options);
return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!);
}
diff --git a/cli/js/os.ts b/cli/js/os.ts
index 7458ee469..2a68ff8d3 100644
--- a/cli/js/os.ts
+++ b/cli/js/os.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
import { errors } from "./errors.ts";
import * as util from "./util.ts";
@@ -9,7 +8,7 @@ import * as util from "./util.ts";
* console.log(Deno.isTTY().stdout);
*/
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
- return sendSync(dispatch.OP_IS_TTY);
+ return sendSync("op_is_tty");
}
/** Get the loadavg.
* Requires the `--allow-env` flag.
@@ -17,7 +16,7 @@ export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
* console.log(Deno.loadavg());
*/
export function loadavg(): number[] {
- return sendSync(dispatch.OP_LOADAVG);
+ return sendSync("op_loadavg");
}
/** Get the hostname.
@@ -26,7 +25,7 @@ export function loadavg(): number[] {
* console.log(Deno.hostname());
*/
export function hostname(): string {
- return sendSync(dispatch.OP_HOSTNAME);
+ return sendSync("op_hostname");
}
/** Get OS release.
@@ -35,21 +34,21 @@ export function hostname(): string {
* console.log(Deno.osRelease());
*/
export function osRelease(): string {
- return sendSync(dispatch.OP_OS_RELEASE);
+ return sendSync("op_os_release");
}
/** Exit the Deno process with optional exit code. */
export function exit(code = 0): never {
- sendSync(dispatch.OP_EXIT, { code });
+ sendSync("op_exit", { code });
return util.unreachable();
}
function setEnv(key: string, value: string): void {
- sendSync(dispatch.OP_SET_ENV, { key, value });
+ sendSync("op_set_env", { key, value });
}
function getEnv(key: string): string | undefined {
- return sendSync(dispatch.OP_GET_ENV, { key })[0];
+ return sendSync("op_get_env", { key })[0];
}
/** Returns a snapshot of the environment variables at invocation. Mutating a
@@ -72,7 +71,7 @@ export function env(
if (key) {
return getEnv(key);
}
- const env = sendSync(dispatch.OP_ENV);
+ const env = sendSync("op_env");
return new Proxy(env, {
set(obj, prop: string, value: string): boolean {
setEnv(prop, value);
@@ -208,7 +207,7 @@ type DirKind =
*/
export function dir(kind: DirKind): string | null {
try {
- return sendSync(dispatch.OP_GET_DIR, { kind });
+ return sendSync("op_get_dir", { kind });
} catch (error) {
if (error instanceof errors.PermissionDenied) {
throw error;
@@ -222,5 +221,5 @@ export function dir(kind: DirKind): string | null {
* Requires the `--allow-env` flag.
*/
export function execPath(): string {
- return sendSync(dispatch.OP_EXEC_PATH);
+ return sendSync("op_exec_path");
}
diff --git a/cli/js/performance.ts b/cli/js/performance.ts
index 37cca35ab..981be64d4 100644
--- a/cli/js/performance.ts
+++ b/cli/js/performance.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
interface NowResponse {
@@ -16,7 +15,7 @@ export class Performance {
* console.log(`${t} ms since start!`);
*/
now(): number {
- const res = sendSync(dispatch.OP_NOW) as NowResponse;
+ const res = sendSync("op_now") as NowResponse;
return res.seconds * 1e3 + res.subsecNanos / 1e6;
}
}
diff --git a/cli/js/permissions.ts b/cli/js/permissions.ts
index 229f8de8b..d414dd1ef 100644
--- a/cli/js/permissions.ts
+++ b/cli/js/permissions.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
/** Permissions as granted by the caller
@@ -61,7 +60,7 @@ export class Permissions {
* }
*/
async query(desc: PermissionDescriptor): Promise<PermissionStatus> {
- const { state } = sendSync(dispatch.OP_QUERY_PERMISSION, desc);
+ const { state } = sendSync("op_query_permission", desc);
return new PermissionStatus(state);
}
@@ -70,7 +69,7 @@ export class Permissions {
* assert(status.state !== "granted")
*/
async revoke(desc: PermissionDescriptor): Promise<PermissionStatus> {
- const { state } = sendSync(dispatch.OP_REVOKE_PERMISSION, desc);
+ const { state } = sendSync("op_revoke_permission", desc);
return new PermissionStatus(state);
}
@@ -83,7 +82,7 @@ export class Permissions {
* }
*/
async request(desc: PermissionDescriptor): Promise<PermissionStatus> {
- const { state } = sendSync(dispatch.OP_REQUEST_PERMISSION, desc);
+ const { state } = sendSync("op_request_permission", desc);
return new PermissionStatus(state);
}
}
diff --git a/cli/js/plugins.ts b/cli/js/plugins.ts
index 4d2072c79..44a3083bb 100644
--- a/cli/js/plugins.ts
+++ b/cli/js/plugins.ts
@@ -1,5 +1,4 @@
import { sendSync } from "./dispatch_json.ts";
-import { OP_OPEN_PLUGIN } from "./dispatch.ts";
import { core } from "./core.ts";
export interface AsyncHandler {
@@ -59,7 +58,7 @@ interface OpenPluginResponse {
}
export function openPlugin(filename: string): Plugin {
- const response: OpenPluginResponse = sendSync(OP_OPEN_PLUGIN, {
+ const response: OpenPluginResponse = sendSync("op_open_plugin", {
filename
});
return new PluginImpl(response.rid, response.ops);
diff --git a/cli/js/process.ts b/cli/js/process.ts
index 5267763c1..4c8685cae 100644
--- a/cli/js/process.ts
+++ b/cli/js/process.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { File, close } from "./files.ts";
import { ReadCloser, WriteCloser } from "./io.ts";
import { readAll } from "./buffer.ts";
@@ -38,7 +37,7 @@ interface RunStatusResponse {
}
async function runStatus(rid: number): Promise<ProcessStatus> {
- const res = (await sendAsync(dispatch.OP_RUN_STATUS, {
+ const res = (await sendAsync("op_run_status", {
rid
})) as RunStatusResponse;
@@ -57,7 +56,7 @@ async function runStatus(rid: number): Promise<ProcessStatus> {
* Requires the `--allow-run` flag.
*/
export function kill(pid: number, signo: number): void {
- sendSync(dispatch.OP_KILL, { pid, signo });
+ sendSync("op_kill", { pid, signo });
}
export class Process {
@@ -220,7 +219,7 @@ export function run(opt: RunOptions): Process {
stderrRid
};
- const res = sendSync(dispatch.OP_RUN, req) as RunResponse;
+ const res = sendSync("op_run", req) as RunResponse;
return new Process(res);
}
diff --git a/cli/js/read_dir.ts b/cli/js/read_dir.ts
index ba6419032..948bad044 100644
--- a/cli/js/read_dir.ts
+++ b/cli/js/read_dir.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { FileInfo, FileInfoImpl } from "./file_info.ts";
import { StatResponse } from "./stat.ts";
@@ -22,7 +21,7 @@ function res(response: ReadDirResponse): FileInfo[] {
* const files = Deno.readDirSync("/");
*/
export function readDirSync(path: string): FileInfo[] {
- return res(sendSync(dispatch.OP_READ_DIR, { path }));
+ return res(sendSync("op_read_dir", { path }));
}
/** Reads the directory given by path and returns a list of file info.
@@ -30,5 +29,5 @@ export function readDirSync(path: string): FileInfo[] {
* const files = await Deno.readDir("/");
*/
export async function readDir(path: string): Promise<FileInfo[]> {
- return res(await sendAsync(dispatch.OP_READ_DIR, { path }));
+ return res(await sendAsync("op_read_dir", { path }));
}
diff --git a/cli/js/read_link.ts b/cli/js/read_link.ts
index acd2d9189..5432bedf7 100644
--- a/cli/js/read_link.ts
+++ b/cli/js/read_link.ts
@@ -1,13 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Returns the destination of the named symbolic link synchronously.
*
* const targetPath = Deno.readlinkSync("symlink/path");
*/
export function readlinkSync(name: string): string {
- return sendSync(dispatch.OP_READ_LINK, { name });
+ return sendSync("op_read_link", { name });
}
/** Returns the destination of the named symbolic link.
@@ -15,5 +14,5 @@ export function readlinkSync(name: string): string {
* const targetPath = await Deno.readlink("symlink/path");
*/
export async function readlink(name: string): Promise<string> {
- return await sendAsync(dispatch.OP_READ_LINK, { name });
+ return await sendAsync("op_read_link", { name });
}
diff --git a/cli/js/realpath.ts b/cli/js/realpath.ts
index 502ced3b8..c425049f4 100644
--- a/cli/js/realpath.ts
+++ b/cli/js/realpath.ts
@@ -1,13 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Returns absolute normalized path with symbolic links resolved synchronously.
*
* const realPath = Deno.realpathSync("./some/path");
*/
export function realpathSync(path: string): string {
- return sendSync(dispatch.OP_REALPATH, { path });
+ return sendSync("op_realpath", { path });
}
/** Returns absolute normalized path with symbolic links resolved.
@@ -15,5 +14,5 @@ export function realpathSync(path: string): string {
* const realPath = await Deno.realpath("./some/path");
*/
export async function realpath(path: string): Promise<string> {
- return await sendAsync(dispatch.OP_REALPATH, { path });
+ return await sendAsync("op_realpath", { path });
}
diff --git a/cli/js/remove.ts b/cli/js/remove.ts
index f4b1bfe19..53ceb825b 100644
--- a/cli/js/remove.ts
+++ b/cli/js/remove.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
export interface RemoveOption {
recursive?: boolean;
@@ -14,7 +13,7 @@ export interface RemoveOption {
* Deno.removeSync("/path/to/dir/or/file", {recursive: false});
*/
export function removeSync(path: string, options: RemoveOption = {}): void {
- sendSync(dispatch.OP_REMOVE, { path, recursive: !!options.recursive });
+ sendSync("op_remove", { path, recursive: !!options.recursive });
}
/** Removes the named file, directory or symlink. Would throw error if
@@ -28,5 +27,5 @@ export async function remove(
path: string,
options: RemoveOption = {}
): Promise<void> {
- await sendAsync(dispatch.OP_REMOVE, { path, recursive: !!options.recursive });
+ await sendAsync("op_remove", { path, recursive: !!options.recursive });
}
diff --git a/cli/js/rename.ts b/cli/js/rename.ts
index 6c0b5d95d..a689061a2 100644
--- a/cli/js/rename.ts
+++ b/cli/js/rename.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
* exists and is not a directory, `renameSync()` replaces it. OS-specific
@@ -10,7 +9,7 @@ import * as dispatch from "./dispatch.ts";
* Deno.renameSync("old/path", "new/path");
*/
export function renameSync(oldpath: string, newpath: string): void {
- sendSync(dispatch.OP_RENAME, { oldpath, newpath });
+ sendSync("op_rename", { oldpath, newpath });
}
/** Renames (moves) `oldpath` to `newpath`. If `newpath` already exists and is
@@ -20,5 +19,5 @@ export function renameSync(oldpath: string, newpath: string): void {
* await Deno.rename("old/path", "new/path");
*/
export async function rename(oldpath: string, newpath: string): Promise<void> {
- await sendAsync(dispatch.OP_RENAME, { oldpath, newpath });
+ await sendAsync("op_rename", { oldpath, newpath });
}
diff --git a/cli/js/repl.ts b/cli/js/repl.ts
index 813f0cb21..6e4f2545a 100644
--- a/cli/js/repl.ts
+++ b/cli/js/repl.ts
@@ -4,7 +4,6 @@ import { exit } from "./os.ts";
import { core } from "./core.ts";
import { formatError } from "./format_error.ts";
import { stringifyArgs } from "./console.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync, sendAsync } from "./dispatch_json.ts";
/**
@@ -44,12 +43,12 @@ const replCommands = {
};
function startRepl(historyFile: string): number {
- return sendSync(dispatch.OP_REPL_START, { historyFile });
+ return sendSync("op_repl_start", { historyFile });
}
// @internal
export async function readline(rid: number, prompt: string): Promise<string> {
- return sendAsync(dispatch.OP_REPL_READLINE, { rid, prompt });
+ return sendAsync("op_repl_readline", { rid, prompt });
}
// Error messages that allow users to continue input
diff --git a/cli/js/resources.ts b/cli/js/resources.ts
index e24c1da67..4c2de1fc3 100644
--- a/cli/js/resources.ts
+++ b/cli/js/resources.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
export interface ResourceMap {
@@ -10,7 +9,7 @@ export interface ResourceMap {
* representation.
*/
export function resources(): ResourceMap {
- const res = sendSync(dispatch.OP_RESOURCES) as Array<[number, string]>;
+ const res = sendSync("op_resources") as Array<[number, string]>;
const resources: ResourceMap = {};
for (const resourceTuple of res) {
resources[resourceTuple[0]] = resourceTuple[1];
diff --git a/cli/js/runtime.ts b/cli/js/runtime.ts
index 53ce5fcee..8149c065c 100644
--- a/cli/js/runtime.ts
+++ b/cli/js/runtime.ts
@@ -28,16 +28,14 @@ interface Start {
arch: Arch;
}
+export let OPS_CACHE: { [name: string]: number };
+
// TODO(bartlomieju): temporary solution, must be fixed when moving
// dispatches to separate crates
export function initOps(): void {
- const ops = core.ops();
- for (const [name, opId] of Object.entries(ops)) {
- const opName = `OP_${name.toUpperCase()}`;
- // Assign op ids to actual variables
- // TODO(ry) This type casting is gross and should be fixed.
- ((dispatch as unknown) as { [key: string]: number })[opName] = opId;
- core.setAsyncHandler(opId, dispatch.getAsyncHandler(opName));
+ OPS_CACHE = core.ops();
+ for (const [name, opId] of Object.entries(OPS_CACHE)) {
+ core.setAsyncHandler(opId, dispatch.getAsyncHandler(name));
}
}
@@ -51,7 +49,7 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
// 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 s = sendSync("op_start");
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
setBuildInfo(s.os, s.arch);
diff --git a/cli/js/runtime_worker.ts b/cli/js/runtime_worker.ts
index a9ed8b924..cdc7d52dd 100644
--- a/cli/js/runtime_worker.ts
+++ b/cli/js/runtime_worker.ts
@@ -16,7 +16,6 @@ import {
windowOrWorkerGlobalScopeProperties,
eventTargetProperties
} from "./globals.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync } from "./dispatch_json.ts";
import { log } from "./util.ts";
import { TextEncoder } from "./text_encoding.ts";
@@ -32,7 +31,7 @@ export const onerror: (e: { data: any }) => void = (): void => {};
export function postMessage(data: any): void {
const dataJson = JSON.stringify(data);
const dataIntArray = encoder.encode(dataJson);
- sendSync(dispatch.OP_WORKER_POST_MESSAGE, {}, dataIntArray);
+ sendSync("op_worker_post_message", {}, dataIntArray);
}
let isClosing = false;
@@ -44,7 +43,7 @@ export function close(): void {
}
isClosing = true;
- sendSync(dispatch.OP_WORKER_CLOSE);
+ sendSync("op_worker_close");
}
export async function workerMessageRecvCallback(data: string): Promise<void> {
diff --git a/cli/js/signals.ts b/cli/js/signals.ts
index 9f47313d4..b79868888 100644
--- a/cli/js/signals.ts
+++ b/cli/js/signals.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { Signal } from "./process.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync, sendAsync } from "./dispatch_json.ts";
import { build } from "./build.ts";
@@ -106,13 +105,13 @@ export class SignalStream
/** The flag, which is true when the stream is disposed. */
private disposed = false;
constructor(signo: number) {
- this.rid = sendSync(dispatch.OP_SIGNAL_BIND, { signo }).rid;
+ this.rid = sendSync("op_signal_bind", { signo }).rid;
this.loop();
}
private async pollSignal(): Promise<boolean> {
return (
- await sendAsync(dispatch.OP_SIGNAL_POLL, {
+ await sendAsync("op_signal_poll", {
rid: this.rid
})
).done;
@@ -144,6 +143,6 @@ export class SignalStream
throw new Error("The stream has already been disposed.");
}
this.disposed = true;
- sendSync(dispatch.OP_SIGNAL_UNBIND, { rid: this.rid });
+ sendSync("op_signal_unbind", { rid: this.rid });
}
}
diff --git a/cli/js/stat.ts b/cli/js/stat.ts
index b27170263..1fd28e893 100644
--- a/cli/js/stat.ts
+++ b/cli/js/stat.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { FileInfo, FileInfoImpl } from "./file_info.ts";
export interface StatResponse {
@@ -30,7 +29,7 @@ export interface StatResponse {
* assert(fileInfo.isFile());
*/
export async function lstat(filename: string): Promise<FileInfo> {
- const res = (await sendAsync(dispatch.OP_STAT, {
+ const res = (await sendAsync("op_stat", {
filename,
lstat: true
})) as StatResponse;
@@ -45,7 +44,7 @@ export async function lstat(filename: string): Promise<FileInfo> {
* assert(fileInfo.isFile());
*/
export function lstatSync(filename: string): FileInfo {
- const res = sendSync(dispatch.OP_STAT, {
+ const res = sendSync("op_stat", {
filename,
lstat: true
}) as StatResponse;
@@ -59,7 +58,7 @@ export function lstatSync(filename: string): FileInfo {
* assert(fileInfo.isFile());
*/
export async function stat(filename: string): Promise<FileInfo> {
- const res = (await sendAsync(dispatch.OP_STAT, {
+ const res = (await sendAsync("op_stat", {
filename,
lstat: false
})) as StatResponse;
@@ -73,7 +72,7 @@ export async function stat(filename: string): Promise<FileInfo> {
* assert(fileInfo.isFile());
*/
export function statSync(filename: string): FileInfo {
- const res = sendSync(dispatch.OP_STAT, {
+ const res = sendSync("op_stat", {
filename,
lstat: false
}) as StatResponse;
diff --git a/cli/js/symlink.ts b/cli/js/symlink.ts
index 79a79c72c..de4d8a729 100644
--- a/cli/js/symlink.ts
+++ b/cli/js/symlink.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import * as util from "./util.ts";
import { build } from "./build.ts";
@@ -18,7 +17,7 @@ export function symlinkSync(
if (build.os === "win" && type) {
return util.notImplemented();
}
- sendSync(dispatch.OP_SYMLINK, { oldname, newname });
+ sendSync("op_symlink", { oldname, newname });
}
/** Creates `newname` as a symbolic link to `oldname`. The type argument can be
@@ -35,5 +34,5 @@ export async function symlink(
if (build.os === "win" && type) {
return util.notImplemented();
}
- await sendAsync(dispatch.OP_SYMLINK, { oldname, newname });
+ await sendAsync("op_symlink", { oldname, newname });
}
diff --git a/cli/js/timers.ts b/cli/js/timers.ts
index da8fc7a22..a92896efd 100644
--- a/cli/js/timers.ts
+++ b/cli/js/timers.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert } from "./util.ts";
-import * as dispatch from "./dispatch.ts";
import { sendSync, sendAsync } from "./dispatch_json.ts";
import { RBTree } from "./rbtree.ts";
@@ -27,7 +26,7 @@ const dueTree = new RBTree<DueNode>((a, b) => a.due - b.due);
function clearGlobalTimeout(): void {
globalTimeoutDue = null;
- sendSync(dispatch.OP_GLOBAL_TIMER_STOP);
+ sendSync("op_global_timer_stop");
}
let pendingEvents = 0;
@@ -44,7 +43,7 @@ async function setGlobalTimeout(due: number, now: number): Promise<void> {
// Send message to the backend.
globalTimeoutDue = due;
pendingEvents++;
- await sendAsync(dispatch.OP_GLOBAL_TIMER, { timeout });
+ await sendAsync("op_global_timer", { timeout });
pendingEvents--;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
fireTimers();
diff --git a/cli/js/tls.ts b/cli/js/tls.ts
index b8815831b..2780956a1 100644
--- a/cli/js/tls.ts
+++ b/cli/js/tls.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendAsync, sendSync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
import { Listener, Transport, Conn, ConnImpl, ListenerImpl } from "./net.ts";
// TODO(ry) There are many configuration options to add...
@@ -18,13 +17,13 @@ const connectTLSDefaults = { hostname: "127.0.0.1", transport: "tcp" };
*/
export async function connectTLS(options: ConnectTLSOptions): Promise<Conn> {
options = Object.assign(connectTLSDefaults, options);
- const res = await sendAsync(dispatch.OP_CONNECT_TLS, options);
+ const res = await sendAsync("op_connect_tls", options);
return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!);
}
class TLSListenerImpl extends ListenerImpl {
async accept(): Promise<Conn> {
- const res = await sendAsync(dispatch.OP_ACCEPT_TLS, { rid: this.rid });
+ const res = await sendAsync("op_accept_tls", { rid: this.rid });
return new ConnImpl(res.rid, res.remoteAddr, res.localAddr);
}
}
@@ -53,7 +52,7 @@ export interface ListenTLSOptions {
export function listenTLS(options: ListenTLSOptions): Listener {
const hostname = options.hostname || "0.0.0.0";
const transport = options.transport || "tcp";
- const res = sendSync(dispatch.OP_LISTEN_TLS, {
+ const res = sendSync("op_listen_tls", {
hostname,
port: options.port,
transport,
diff --git a/cli/js/truncate.ts b/cli/js/truncate.ts
index bd572e75a..17c08674c 100644
--- a/cli/js/truncate.ts
+++ b/cli/js/truncate.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import * as dispatch from "./dispatch.ts";
function coerceLen(len?: number): number {
if (!len) {
@@ -20,7 +19,7 @@ function coerceLen(len?: number): number {
* Deno.truncateSync("hello.txt", 10);
*/
export function truncateSync(name: string, len?: number): void {
- sendSync(dispatch.OP_TRUNCATE, { name, len: coerceLen(len) });
+ sendSync("op_truncate", { name, len: coerceLen(len) });
}
/**
@@ -30,5 +29,5 @@ export function truncateSync(name: string, len?: number): void {
* await Deno.truncate("hello.txt", 10);
*/
export async function truncate(name: string, len?: number): Promise<void> {
- await sendAsync(dispatch.OP_TRUNCATE, { name, len: coerceLen(len) });
+ await sendAsync("op_truncate", { name, len: coerceLen(len) });
}
diff --git a/cli/js/url_test.ts b/cli/js/url_test.ts
index 64130b6b9..003fcd347 100644
--- a/cli/js/url_test.ts
+++ b/cli/js/url_test.ts
@@ -180,6 +180,7 @@ test(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void {
assertEquals(url.search, "");
});
+/*
test(function customInspectFunction(): void {
const url = new URL("http://example.com/?");
assertEquals(
@@ -187,6 +188,7 @@ test(function customInspectFunction(): void {
'URL { href: "http://example.com/?", origin: "http://example.com", protocol: "http:", username: "", password: "", host: "example.com", hostname: "example.com", port: "", pathname: "/", hash: "", search: "?" }'
);
});
+*/
test(function protocolNotHttpOrFile() {
const url = new URL("about:blank");
@@ -200,3 +202,7 @@ test(function createBadUrl(): void {
new URL("0.0.0.0:8080");
});
});
+
+if (import.meta.main) {
+ Deno.runTests();
+}
diff --git a/cli/js/utime.ts b/cli/js/utime.ts
index c96461b2c..d80b8b396 100644
--- a/cli/js/utime.ts
+++ b/cli/js/utime.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./dispatch_json.ts";
-import { OP_UTIME } from "./dispatch.ts";
function toSecondsFromEpoch(v: number | Date): number {
return v instanceof Date ? v.valueOf() / 1000 : v;
@@ -17,7 +16,7 @@ export function utimeSync(
atime: number | Date,
mtime: number | Date
): void {
- sendSync(OP_UTIME, {
+ sendSync("op_utime", {
filename,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
@@ -36,7 +35,7 @@ export async function utime(
atime: number | Date,
mtime: number | Date
): Promise<void> {
- await sendAsync(OP_UTIME, {
+ await sendAsync("op_utime", {
filename,
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
atime: toSecondsFromEpoch(atime),
diff --git a/cli/js/workers.ts b/cli/js/workers.ts
index 7b0c50336..3258e4137 100644
--- a/cli/js/workers.ts
+++ b/cli/js/workers.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/* eslint-disable @typescript-eslint/no-explicit-any */
-import * as dispatch from "./dispatch.ts";
import { sendAsync, sendSync } from "./dispatch_json.ts";
import { log } from "./util.ts";
import { TextDecoder, TextEncoder } from "./text_encoding.ts";
@@ -30,7 +29,7 @@ function createWorker(
sourceCode: Uint8Array,
name?: string
): { id: number } {
- return sendSync(dispatch.OP_CREATE_WORKER, {
+ return sendSync("op_create_worker", {
specifier,
hasSourceCode,
sourceCode: new TextDecoder().decode(sourceCode),
@@ -39,12 +38,12 @@ function createWorker(
}
function hostTerminateWorker(id: number): void {
- sendSync(dispatch.OP_HOST_TERMINATE_WORKER, { id });
+ sendSync("op_host_terminate_worker", { id });
}
function hostPostMessage(id: number, data: any): void {
const dataIntArray = encodeMessage(data);
- sendSync(dispatch.OP_HOST_POST_MESSAGE, { id }, dataIntArray);
+ sendSync("op_host_post_message", { id }, dataIntArray);
}
interface WorkerEvent {
@@ -54,7 +53,7 @@ interface WorkerEvent {
}
async function hostGetMessage(id: number): Promise<any> {
- return await sendAsync(dispatch.OP_HOST_GET_MESSAGE, { id });
+ return await sendAsync("op_host_get_message", { id });
}
export interface Worker {