提交 3afc0b84 编写于 作者: R Ryan Dahl

fbs_util.ts -> dispatch.ts

And send() -> sendSync()
上级 e2a285b8
......@@ -190,8 +190,8 @@ run_node("gen_declarations") {
"js/compiler.ts",
"js/console.ts",
"js/deno.ts",
"js/dispatch.ts",
"js/errors.ts",
"js/fbs_util.ts",
"js/fetch.ts",
"js/global-eval.ts",
"js/globals.ts",
......@@ -226,8 +226,8 @@ run_node("bundle") {
"js/assets.ts",
"js/compiler.ts",
"js/console.ts",
"js/dispatch.ts",
"js/errors.ts",
"js/fbs_util.ts",
"js/fetch.ts",
"js/fetch_types.d.ts",
"js/globals.ts",
......
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// TODO Rename this file to //js/dispatch.ts
import { libdeno } from "./libdeno";
import { flatbuffers } from "flatbuffers";
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) {
const bb = new flatbuffers.ByteBuffer(ui8);
const base = fbs.Base.getRootAsBase(bb);
const cmdId = base.cmdId();
const promise = promiseTable.get(cmdId);
util.assert(promise != null, `Expecting promise in table. ${cmdId}`);
......@@ -38,9 +36,8 @@ export function sendAsync(
return promise;
}
// TODO Rename to sendSync
// @internal
export function send(
export function sendSync(
builder: flatbuffers.Builder,
msgType: fbs.Any,
msg: flatbuffers.Offset
......
......@@ -8,7 +8,7 @@ import {
notImplemented
} from "./util";
import { flatbuffers } from "flatbuffers";
import { sendAsync } from "./fbs_util";
import { sendAsync } from "./dispatch";
import * as fbs from "gen/msg_generated";
import {
Headers,
......
......@@ -6,13 +6,13 @@ import * as os from "./os";
import { DenoCompiler } from "./compiler";
import { libdeno } from "./libdeno";
import { argv } from "./deno";
import { send, handleAsyncMsgFromRust } from "./fbs_util";
import { sendSync, handleAsyncMsgFromRust } from "./dispatch";
function sendStart(): fbs.StartRes {
const builder = new flatbuffers.Builder();
fbs.Start.startStart(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(fbs.Any.StartRes === baseRes!.msgType());
const startRes = new fbs.StartRes();
......
......@@ -4,14 +4,14 @@ import * as fbs from "gen/msg_generated";
import { assert } from "./util";
import * as util from "./util";
import { flatbuffers } from "flatbuffers";
import { send } from "./fbs_util";
import { sendSync } from "./dispatch";
export function exit(exitCode = 0): never {
const builder = new flatbuffers.Builder();
fbs.Exit.startExit(builder);
fbs.Exit.addCode(builder, exitCode);
const msg = fbs.Exit.endExit(builder);
send(builder, fbs.Any.Exit, msg);
sendSync(builder, fbs.Any.Exit, msg);
return util.unreachable();
}
......@@ -28,7 +28,7 @@ export function codeFetch(
fbs.CodeFetch.addModuleSpecifier(builder, moduleSpecifier_);
fbs.CodeFetch.addContainingFile(builder, containingFile_);
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(
fbs.Any.CodeFetchRes === baseRes!.msgType(),
......@@ -59,7 +59,7 @@ export function codeCache(
fbs.CodeCache.addSourceCode(builder, sourceCode_);
fbs.CodeCache.addOutputCode(builder, outputCode_);
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.
}
......@@ -97,7 +97,7 @@ export function makeTempDirSync({
fbs.MakeTempDir.addSuffix(builder, fbSuffix);
}
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(fbs.Any.MakeTempDirRes === baseRes!.msgType());
const res = new fbs.MakeTempDirRes();
......@@ -111,7 +111,7 @@ export function makeTempDirSync({
// and permission bits (before umask).
export function mkdirSync(path: string, mode = 0o777): void {
/* Ideally we could write:
const res = send({
const res = sendSync({
command: fbs.Command.MKDIR_SYNC,
mkdirSyncPath: path,
mkdirSyncMode: mode,
......@@ -123,7 +123,7 @@ export function mkdirSync(path: string, mode = 0o777): void {
fbs.MkdirSync.addPath(builder, path_);
fbs.MkdirSync.addMode(builder, mode);
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 {
/* Ideally we could write
const res = send({
const res = sendSync({
command: fbs.Command.READ_FILE_SYNC,
readFileSyncFilename: filename
});
......@@ -147,7 +147,7 @@ export function readFileSync(filename: string): Uint8Array {
fbs.ReadFileSync.startReadFileSync(builder);
fbs.ReadFileSync.addFilename(builder, filename_);
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(fbs.Any.ReadFileSyncRes === baseRes!.msgType());
const res = new fbs.ReadFileSyncRes();
......@@ -182,7 +182,7 @@ function setEnv(key: string, value: string): void {
fbs.SetEnv.addKey(builder, _key);
fbs.SetEnv.addValue(builder, _value);
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 } {
/* Ideally we could write
const res = send({
const res = sendSync({
command: fbs.Command.ENV,
});
*/
const builder = new flatbuffers.Builder();
fbs.Environ.startEnviron(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());
const res = new fbs.EnvironRes();
assert(baseRes.msg(res) != null);
......@@ -303,7 +303,7 @@ export function statSync(filename: string): FileInfo {
function statSyncInner(filename: string, lstat: boolean): FileInfo {
/* Ideally we could write
const res = send({
const res = sendSync({
command: fbs.Command.STAT_FILE_SYNC,
StatFilename: filename,
StatLStat: lstat,
......@@ -316,7 +316,7 @@ function statSyncInner(filename: string, lstat: boolean): FileInfo {
fbs.StatSync.addFilename(builder, filename_);
fbs.StatSync.addLstat(builder, lstat);
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(fbs.Any.StatSyncRes === baseRes!.msgType());
const res = new fbs.StatSyncRes();
......@@ -338,7 +338,7 @@ export function writeFileSync(
perm = 0o666
): void {
/* Ideally we could write:
const res = send({
const res = sendSync({
command: fbs.Command.WRITE_FILE_SYNC,
writeFileSyncFilename: filename,
writeFileSyncData: data,
......@@ -353,7 +353,7 @@ export function writeFileSync(
fbs.WriteFileSync.addData(builder, dataOffset);
fbs.WriteFileSync.addPerm(builder, perm);
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 {
/* Ideally we could write:
const res = send({
const res = sendSync({
command: fbs.Command.RENAME_SYNC,
renameOldPath: oldpath,
renameNewPath: newpath
......@@ -379,5 +379,5 @@ export function renameSync(oldpath: string, newpath: string): void {
fbs.RenameSync.addOldpath(builder, _oldpath);
fbs.RenameSync.addNewpath(builder, _newpath);
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 fbs from "gen/msg_generated";
import { flatbuffers } from "flatbuffers";
import { send, sendAsync } from "./fbs_util";
import { sendSync, sendAsync } from "./dispatch";
let nextTimerId = 1;
......@@ -93,6 +93,6 @@ export function clearTimer(id: number) {
fbs.TimerClear.startTimerClear(builder);
fbs.TimerClear.addId(builder, id);
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);
}
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
at maybeError (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 DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
......
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 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 DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD])
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册