mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fbs_util.ts -> dispatch.ts
And send() -> sendSync()
This commit is contained in:
parent
e2a285b871
commit
3afc0b8482
8 changed files with 28 additions and 31 deletions
4
BUILD.gn
4
BUILD.gn
|
@ -190,8 +190,8 @@ run_node("gen_declarations") {
|
||||||
"js/compiler.ts",
|
"js/compiler.ts",
|
||||||
"js/console.ts",
|
"js/console.ts",
|
||||||
"js/deno.ts",
|
"js/deno.ts",
|
||||||
|
"js/dispatch.ts",
|
||||||
"js/errors.ts",
|
"js/errors.ts",
|
||||||
"js/fbs_util.ts",
|
|
||||||
"js/fetch.ts",
|
"js/fetch.ts",
|
||||||
"js/global-eval.ts",
|
"js/global-eval.ts",
|
||||||
"js/globals.ts",
|
"js/globals.ts",
|
||||||
|
@ -226,8 +226,8 @@ run_node("bundle") {
|
||||||
"js/assets.ts",
|
"js/assets.ts",
|
||||||
"js/compiler.ts",
|
"js/compiler.ts",
|
||||||
"js/console.ts",
|
"js/console.ts",
|
||||||
|
"js/dispatch.ts",
|
||||||
"js/errors.ts",
|
"js/errors.ts",
|
||||||
"js/fbs_util.ts",
|
|
||||||
"js/fetch.ts",
|
"js/fetch.ts",
|
||||||
"js/fetch_types.d.ts",
|
"js/fetch_types.d.ts",
|
||||||
"js/globals.ts",
|
"js/globals.ts",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
// TODO Rename this file to //js/dispatch.ts
|
|
||||||
import { libdeno } from "./libdeno";
|
import { libdeno } from "./libdeno";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import * as fbs from "gen/msg_generated";
|
import * as fbs from "gen/msg_generated";
|
||||||
|
@ -12,7 +11,6 @@ const promiseTable = new Map<number, util.Resolvable<fbs.Base>>();
|
||||||
export function handleAsyncMsgFromRust(ui8: Uint8Array) {
|
export function handleAsyncMsgFromRust(ui8: Uint8Array) {
|
||||||
const bb = new flatbuffers.ByteBuffer(ui8);
|
const bb = new flatbuffers.ByteBuffer(ui8);
|
||||||
const base = fbs.Base.getRootAsBase(bb);
|
const base = fbs.Base.getRootAsBase(bb);
|
||||||
|
|
||||||
const cmdId = base.cmdId();
|
const cmdId = base.cmdId();
|
||||||
const promise = promiseTable.get(cmdId);
|
const promise = promiseTable.get(cmdId);
|
||||||
util.assert(promise != null, `Expecting promise in table. ${cmdId}`);
|
util.assert(promise != null, `Expecting promise in table. ${cmdId}`);
|
||||||
|
@ -38,9 +36,8 @@ export function sendAsync(
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Rename to sendSync
|
|
||||||
// @internal
|
// @internal
|
||||||
export function send(
|
export function sendSync(
|
||||||
builder: flatbuffers.Builder,
|
builder: flatbuffers.Builder,
|
||||||
msgType: fbs.Any,
|
msgType: fbs.Any,
|
||||||
msg: flatbuffers.Offset
|
msg: flatbuffers.Offset
|
|
@ -8,7 +8,7 @@ import {
|
||||||
notImplemented
|
notImplemented
|
||||||
} from "./util";
|
} from "./util";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { sendAsync } from "./fbs_util";
|
import { sendAsync } from "./dispatch";
|
||||||
import * as fbs from "gen/msg_generated";
|
import * as fbs from "gen/msg_generated";
|
||||||
import {
|
import {
|
||||||
Headers,
|
Headers,
|
||||||
|
|
|
@ -6,13 +6,13 @@ import * as os from "./os";
|
||||||
import { DenoCompiler } from "./compiler";
|
import { DenoCompiler } from "./compiler";
|
||||||
import { libdeno } from "./libdeno";
|
import { libdeno } from "./libdeno";
|
||||||
import { argv } from "./deno";
|
import { argv } from "./deno";
|
||||||
import { send, handleAsyncMsgFromRust } from "./fbs_util";
|
import { sendSync, handleAsyncMsgFromRust } from "./dispatch";
|
||||||
|
|
||||||
function sendStart(): fbs.StartRes {
|
function sendStart(): fbs.StartRes {
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
fbs.Start.startStart(builder);
|
fbs.Start.startStart(builder);
|
||||||
const startOffset = fbs.Start.endStart(builder);
|
const startOffset = fbs.Start.endStart(builder);
|
||||||
const baseRes = send(builder, fbs.Any.Start, startOffset);
|
const baseRes = sendSync(builder, fbs.Any.Start, startOffset);
|
||||||
assert(baseRes != null);
|
assert(baseRes != null);
|
||||||
assert(fbs.Any.StartRes === baseRes!.msgType());
|
assert(fbs.Any.StartRes === baseRes!.msgType());
|
||||||
const startRes = new fbs.StartRes();
|
const startRes = new fbs.StartRes();
|
||||||
|
|
36
js/os.ts
36
js/os.ts
|
@ -4,14 +4,14 @@ import * as fbs from "gen/msg_generated";
|
||||||
import { assert } from "./util";
|
import { assert } from "./util";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { send } from "./fbs_util";
|
import { sendSync } from "./dispatch";
|
||||||
|
|
||||||
export function exit(exitCode = 0): never {
|
export function exit(exitCode = 0): never {
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
fbs.Exit.startExit(builder);
|
fbs.Exit.startExit(builder);
|
||||||
fbs.Exit.addCode(builder, exitCode);
|
fbs.Exit.addCode(builder, exitCode);
|
||||||
const msg = fbs.Exit.endExit(builder);
|
const msg = fbs.Exit.endExit(builder);
|
||||||
send(builder, fbs.Any.Exit, msg);
|
sendSync(builder, fbs.Any.Exit, msg);
|
||||||
return util.unreachable();
|
return util.unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ export function codeFetch(
|
||||||
fbs.CodeFetch.addModuleSpecifier(builder, moduleSpecifier_);
|
fbs.CodeFetch.addModuleSpecifier(builder, moduleSpecifier_);
|
||||||
fbs.CodeFetch.addContainingFile(builder, containingFile_);
|
fbs.CodeFetch.addContainingFile(builder, containingFile_);
|
||||||
const msg = fbs.CodeFetch.endCodeFetch(builder);
|
const msg = fbs.CodeFetch.endCodeFetch(builder);
|
||||||
const baseRes = send(builder, fbs.Any.CodeFetch, msg);
|
const baseRes = sendSync(builder, fbs.Any.CodeFetch, msg);
|
||||||
assert(baseRes != null);
|
assert(baseRes != null);
|
||||||
assert(
|
assert(
|
||||||
fbs.Any.CodeFetchRes === baseRes!.msgType(),
|
fbs.Any.CodeFetchRes === baseRes!.msgType(),
|
||||||
|
@ -59,7 +59,7 @@ export function codeCache(
|
||||||
fbs.CodeCache.addSourceCode(builder, sourceCode_);
|
fbs.CodeCache.addSourceCode(builder, sourceCode_);
|
||||||
fbs.CodeCache.addOutputCode(builder, outputCode_);
|
fbs.CodeCache.addOutputCode(builder, outputCode_);
|
||||||
const msg = fbs.CodeCache.endCodeCache(builder);
|
const msg = fbs.CodeCache.endCodeCache(builder);
|
||||||
const baseRes = send(builder, fbs.Any.CodeCache, msg);
|
const baseRes = sendSync(builder, fbs.Any.CodeCache, msg);
|
||||||
assert(baseRes == null); // Expect null or error.
|
assert(baseRes == null); // Expect null or error.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export function makeTempDirSync({
|
||||||
fbs.MakeTempDir.addSuffix(builder, fbSuffix);
|
fbs.MakeTempDir.addSuffix(builder, fbSuffix);
|
||||||
}
|
}
|
||||||
const msg = fbs.MakeTempDir.endMakeTempDir(builder);
|
const msg = fbs.MakeTempDir.endMakeTempDir(builder);
|
||||||
const baseRes = send(builder, fbs.Any.MakeTempDir, msg);
|
const baseRes = sendSync(builder, fbs.Any.MakeTempDir, msg);
|
||||||
assert(baseRes != null);
|
assert(baseRes != null);
|
||||||
assert(fbs.Any.MakeTempDirRes === baseRes!.msgType());
|
assert(fbs.Any.MakeTempDirRes === baseRes!.msgType());
|
||||||
const res = new fbs.MakeTempDirRes();
|
const res = new fbs.MakeTempDirRes();
|
||||||
|
@ -111,7 +111,7 @@ export function makeTempDirSync({
|
||||||
// and permission bits (before umask).
|
// and permission bits (before umask).
|
||||||
export function mkdirSync(path: string, mode = 0o777): void {
|
export function mkdirSync(path: string, mode = 0o777): void {
|
||||||
/* Ideally we could write:
|
/* Ideally we could write:
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.MKDIR_SYNC,
|
command: fbs.Command.MKDIR_SYNC,
|
||||||
mkdirSyncPath: path,
|
mkdirSyncPath: path,
|
||||||
mkdirSyncMode: mode,
|
mkdirSyncMode: mode,
|
||||||
|
@ -123,7 +123,7 @@ export function mkdirSync(path: string, mode = 0o777): void {
|
||||||
fbs.MkdirSync.addPath(builder, path_);
|
fbs.MkdirSync.addPath(builder, path_);
|
||||||
fbs.MkdirSync.addMode(builder, mode);
|
fbs.MkdirSync.addMode(builder, mode);
|
||||||
const msg = fbs.MkdirSync.endMkdirSync(builder);
|
const msg = fbs.MkdirSync.endMkdirSync(builder);
|
||||||
send(builder, fbs.Any.MkdirSync, msg);
|
sendSync(builder, fbs.Any.MkdirSync, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +136,7 @@ export function mkdirSync(path: string, mode = 0o777): void {
|
||||||
*/
|
*/
|
||||||
export function readFileSync(filename: string): Uint8Array {
|
export function readFileSync(filename: string): Uint8Array {
|
||||||
/* Ideally we could write
|
/* Ideally we could write
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.READ_FILE_SYNC,
|
command: fbs.Command.READ_FILE_SYNC,
|
||||||
readFileSyncFilename: filename
|
readFileSyncFilename: filename
|
||||||
});
|
});
|
||||||
|
@ -147,7 +147,7 @@ export function readFileSync(filename: string): Uint8Array {
|
||||||
fbs.ReadFileSync.startReadFileSync(builder);
|
fbs.ReadFileSync.startReadFileSync(builder);
|
||||||
fbs.ReadFileSync.addFilename(builder, filename_);
|
fbs.ReadFileSync.addFilename(builder, filename_);
|
||||||
const msg = fbs.ReadFileSync.endReadFileSync(builder);
|
const msg = fbs.ReadFileSync.endReadFileSync(builder);
|
||||||
const baseRes = send(builder, fbs.Any.ReadFileSync, msg);
|
const baseRes = sendSync(builder, fbs.Any.ReadFileSync, msg);
|
||||||
assert(baseRes != null);
|
assert(baseRes != null);
|
||||||
assert(fbs.Any.ReadFileSyncRes === baseRes!.msgType());
|
assert(fbs.Any.ReadFileSyncRes === baseRes!.msgType());
|
||||||
const res = new fbs.ReadFileSyncRes();
|
const res = new fbs.ReadFileSyncRes();
|
||||||
|
@ -182,7 +182,7 @@ function setEnv(key: string, value: string): void {
|
||||||
fbs.SetEnv.addKey(builder, _key);
|
fbs.SetEnv.addKey(builder, _key);
|
||||||
fbs.SetEnv.addValue(builder, _value);
|
fbs.SetEnv.addValue(builder, _value);
|
||||||
const msg = fbs.SetEnv.endSetEnv(builder);
|
const msg = fbs.SetEnv.endSetEnv(builder);
|
||||||
send(builder, fbs.Any.SetEnv, msg);
|
sendSync(builder, fbs.Any.SetEnv, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,14 +200,14 @@ function setEnv(key: string, value: string): void {
|
||||||
*/
|
*/
|
||||||
export function env(): { [index: string]: string } {
|
export function env(): { [index: string]: string } {
|
||||||
/* Ideally we could write
|
/* Ideally we could write
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.ENV,
|
command: fbs.Command.ENV,
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
fbs.Environ.startEnviron(builder);
|
fbs.Environ.startEnviron(builder);
|
||||||
const msg = fbs.Environ.endEnviron(builder);
|
const msg = fbs.Environ.endEnviron(builder);
|
||||||
const baseRes = send(builder, fbs.Any.Environ, msg)!;
|
const baseRes = sendSync(builder, fbs.Any.Environ, msg)!;
|
||||||
assert(fbs.Any.EnvironRes === baseRes.msgType());
|
assert(fbs.Any.EnvironRes === baseRes.msgType());
|
||||||
const res = new fbs.EnvironRes();
|
const res = new fbs.EnvironRes();
|
||||||
assert(baseRes.msg(res) != null);
|
assert(baseRes.msg(res) != null);
|
||||||
|
@ -303,7 +303,7 @@ export function statSync(filename: string): FileInfo {
|
||||||
|
|
||||||
function statSyncInner(filename: string, lstat: boolean): FileInfo {
|
function statSyncInner(filename: string, lstat: boolean): FileInfo {
|
||||||
/* Ideally we could write
|
/* Ideally we could write
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.STAT_FILE_SYNC,
|
command: fbs.Command.STAT_FILE_SYNC,
|
||||||
StatFilename: filename,
|
StatFilename: filename,
|
||||||
StatLStat: lstat,
|
StatLStat: lstat,
|
||||||
|
@ -316,7 +316,7 @@ function statSyncInner(filename: string, lstat: boolean): FileInfo {
|
||||||
fbs.StatSync.addFilename(builder, filename_);
|
fbs.StatSync.addFilename(builder, filename_);
|
||||||
fbs.StatSync.addLstat(builder, lstat);
|
fbs.StatSync.addLstat(builder, lstat);
|
||||||
const msg = fbs.StatSync.endStatSync(builder);
|
const msg = fbs.StatSync.endStatSync(builder);
|
||||||
const baseRes = send(builder, fbs.Any.StatSync, msg);
|
const baseRes = sendSync(builder, fbs.Any.StatSync, msg);
|
||||||
assert(baseRes != null);
|
assert(baseRes != null);
|
||||||
assert(fbs.Any.StatSyncRes === baseRes!.msgType());
|
assert(fbs.Any.StatSyncRes === baseRes!.msgType());
|
||||||
const res = new fbs.StatSyncRes();
|
const res = new fbs.StatSyncRes();
|
||||||
|
@ -338,7 +338,7 @@ export function writeFileSync(
|
||||||
perm = 0o666
|
perm = 0o666
|
||||||
): void {
|
): void {
|
||||||
/* Ideally we could write:
|
/* Ideally we could write:
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.WRITE_FILE_SYNC,
|
command: fbs.Command.WRITE_FILE_SYNC,
|
||||||
writeFileSyncFilename: filename,
|
writeFileSyncFilename: filename,
|
||||||
writeFileSyncData: data,
|
writeFileSyncData: data,
|
||||||
|
@ -353,7 +353,7 @@ export function writeFileSync(
|
||||||
fbs.WriteFileSync.addData(builder, dataOffset);
|
fbs.WriteFileSync.addData(builder, dataOffset);
|
||||||
fbs.WriteFileSync.addPerm(builder, perm);
|
fbs.WriteFileSync.addPerm(builder, perm);
|
||||||
const msg = fbs.WriteFileSync.endWriteFileSync(builder);
|
const msg = fbs.WriteFileSync.endWriteFileSync(builder);
|
||||||
send(builder, fbs.Any.WriteFileSync, msg);
|
sendSync(builder, fbs.Any.WriteFileSync, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,7 +366,7 @@ export function writeFileSync(
|
||||||
*/
|
*/
|
||||||
export function renameSync(oldpath: string, newpath: string): void {
|
export function renameSync(oldpath: string, newpath: string): void {
|
||||||
/* Ideally we could write:
|
/* Ideally we could write:
|
||||||
const res = send({
|
const res = sendSync({
|
||||||
command: fbs.Command.RENAME_SYNC,
|
command: fbs.Command.RENAME_SYNC,
|
||||||
renameOldPath: oldpath,
|
renameOldPath: oldpath,
|
||||||
renameNewPath: newpath
|
renameNewPath: newpath
|
||||||
|
@ -379,5 +379,5 @@ export function renameSync(oldpath: string, newpath: string): void {
|
||||||
fbs.RenameSync.addOldpath(builder, _oldpath);
|
fbs.RenameSync.addOldpath(builder, _oldpath);
|
||||||
fbs.RenameSync.addNewpath(builder, _newpath);
|
fbs.RenameSync.addNewpath(builder, _newpath);
|
||||||
const msg = fbs.RenameSync.endRenameSync(builder);
|
const msg = fbs.RenameSync.endRenameSync(builder);
|
||||||
send(builder, fbs.Any.RenameSync, msg);
|
sendSync(builder, fbs.Any.RenameSync, msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { assert } from "./util";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
import * as fbs from "gen/msg_generated";
|
import * as fbs from "gen/msg_generated";
|
||||||
import { flatbuffers } from "flatbuffers";
|
import { flatbuffers } from "flatbuffers";
|
||||||
import { send, sendAsync } from "./fbs_util";
|
import { sendSync, sendAsync } from "./dispatch";
|
||||||
|
|
||||||
let nextTimerId = 1;
|
let nextTimerId = 1;
|
||||||
|
|
||||||
|
@ -93,6 +93,6 @@ export function clearTimer(id: number) {
|
||||||
fbs.TimerClear.startTimerClear(builder);
|
fbs.TimerClear.startTimerClear(builder);
|
||||||
fbs.TimerClear.addId(builder, id);
|
fbs.TimerClear.addId(builder, id);
|
||||||
const msg = fbs.TimerClear.endTimerClear(builder);
|
const msg = fbs.TimerClear.endTimerClear(builder);
|
||||||
const res = send(builder, fbs.Any.TimerClear, msg);
|
const res = sendSync(builder, fbs.Any.TimerClear, msg);
|
||||||
assert(res == null);
|
assert(res == null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
|
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
|
||||||
at maybeError (deno/js/errors.ts:[WILDCARD])
|
at maybeError (deno/js/errors.ts:[WILDCARD])
|
||||||
at maybeThrowError (deno/js/errors.ts:[WILDCARD])
|
at maybeThrowError (deno/js/errors.ts:[WILDCARD])
|
||||||
at send (deno/js/fbs_util.ts:[WILDCARD])
|
at sendSync (deno/js/dispatch.ts:[WILDCARD])
|
||||||
at Object.codeFetch (deno/js/os.ts:[WILDCARD])
|
at Object.codeFetch (deno/js/os.ts:[WILDCARD])
|
||||||
at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
|
at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
|
||||||
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
|
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]deno/tests/error_005_missing_dynamic_import.ts"
|
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]deno/tests/error_005_missing_dynamic_import.ts"
|
||||||
at maybeError (deno/js/errors.ts:[WILDCARD])
|
at maybeError (deno/js/errors.ts:[WILDCARD])
|
||||||
at maybeThrowError (deno/js/errors.ts:[WILDCARD])
|
at maybeThrowError (deno/js/errors.ts:[WILDCARD])
|
||||||
at send (deno/js/fbs_util.ts:[WILDCARD])
|
at sendSync (deno/js/dispatch.ts:[WILDCARD])
|
||||||
at Object.codeFetch (deno/js/os.ts:[WILDCARD])
|
at Object.codeFetch (deno/js/os.ts:[WILDCARD])
|
||||||
at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
|
at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
|
||||||
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
|
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
|
||||||
|
|
Loading…
Reference in a new issue