diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-03-26 23:22:07 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-26 08:22:07 -0400 |
commit | c43cfedeba5d6ac96e1b1febed8549e750606e3f (patch) | |
tree | 7b3799259895acadf25294704ea03a9465051e9c /js | |
parent | ed2977d3c0e9ab3295a3bb47b844b2953d608197 (diff) |
namespace reorg: libdeno and DenoCore to Deno.core (#1998)
Diffstat (limited to 'js')
-rw-r--r-- | js/compiler.ts | 4 | ||||
-rw-r--r-- | js/console.ts | 4 | ||||
-rw-r--r-- | js/core.ts | 11 | ||||
-rw-r--r-- | js/deno.ts | 6 | ||||
-rw-r--r-- | js/dispatch.ts | 4 | ||||
-rw-r--r-- | js/event.ts | 4 | ||||
-rw-r--r-- | js/flatbuffers.ts | 2 | ||||
-rw-r--r-- | js/globals.ts | 5 | ||||
-rw-r--r-- | js/libdeno.ts | 42 | ||||
-rw-r--r-- | js/os.ts | 11 | ||||
-rw-r--r-- | js/repl.ts | 10 |
11 files changed, 25 insertions, 78 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index aefdf989d..8be78935f 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -4,7 +4,7 @@ import * as msg from "gen/msg_generated"; import { window } from "./window"; import { assetSourceCode } from "./assets"; import { Console } from "./console"; -import { libdeno } from "./libdeno"; +import { core } from "./core"; import * as os from "./os"; import { TextDecoder, TextEncoder } from "./text_encoding"; import { clearTimer, setTimeout } from "./timers"; @@ -16,7 +16,7 @@ const ASSETS = "$asset$"; const LIB_RUNTIME = `${ASSETS}/lib.deno_runtime.d.ts`; // An instance of console -const console = new Console(libdeno.print); +const console = new Console(core.print); /** The location that a module is being loaded from. This could be a directory, * like `.`, or it could be a module specifier like diff --git a/js/console.ts b/js/console.ts index b68794d3f..3669a1d3b 100644 --- a/js/console.ts +++ b/js/console.ts @@ -5,7 +5,7 @@ import { TextEncoder } from "./text_encoding"; import { File, stdout } from "./files"; import { cliTable } from "./console_table"; import { formatError } from "./format_error"; -import { libdeno } from "./libdeno"; +import { core } from "./core"; type ConsoleContext = Set<unknown>; type ConsoleOptions = Partial<{ @@ -323,7 +323,7 @@ function createObjectString( ...args: [ConsoleContext, number, number] ): string { if (value instanceof Error) { - const errorJSON = libdeno.errorToJSON(value); + const errorJSON = core.errorToJSON(value); return formatError(errorJSON); } else if (Array.isArray(value)) { return createArrayString(value, ...args); diff --git a/js/core.ts b/js/core.ts index 9e94ffdbb..03473ff3d 100644 --- a/js/core.ts +++ b/js/core.ts @@ -1,13 +1,4 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { window } from "./window"; -type MessageCallback = (msg: Uint8Array) => void; - -// Declared in core/shared_queue.js. -interface DenoCore { - setAsyncHandler(cb: MessageCallback): void; - dispatch(control: Uint8Array, zeroCopy?: Uint8Array): null | Uint8Array; -} - -// TODO(ry) Rename to Deno.core.shared and Deno.core.setAsyncHandler. -export const DenoCore = window.DenoCore as DenoCore; +export const core = window.Deno.core as DenoCore; diff --git a/js/deno.ts b/js/deno.ts index d663ca55c..ed42dc89a 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -49,7 +49,6 @@ export { statSync, lstatSync, stat, lstat } from "./stat"; export { symlinkSync, symlink } from "./symlink"; export { writeFileSync, writeFile, WriteFileOptions } from "./write_file"; export { ErrorKind, DenoError } from "./errors"; -export { libdeno } from "./libdeno"; export { permissions, revokePermission, @@ -67,6 +66,11 @@ export { build, platform, OperatingSystem, Arch } from "./build"; export { version } from "./version"; export const args: string[] = []; +// These are internal Deno APIs. We are marking them as internal so they do not +// appear in the runtime type library. +/** @internal */ +export { core } from "./core"; + // TODO Don't expose Console nor stringifyArgs. /** @internal */ export { Console, stringifyArgs } from "./console"; diff --git a/js/dispatch.ts b/js/dispatch.ts index 2e6cbf10f..3ca0cd799 100644 --- a/js/dispatch.ts +++ b/js/dispatch.ts @@ -1,5 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { window } from "./window"; +import { core } from "./core"; import * as flatbuffers from "./flatbuffers"; import * as msg from "gen/msg_generated"; import * as errors from "./errors"; @@ -39,7 +39,7 @@ function sendInternal( builder.finish(msg.Base.endBase(builder)); const control = builder.asUint8Array(); - const response = window.DenoCore.dispatch(control, zeroCopy); + const response = core.dispatch(control, zeroCopy); builder.inUse = false; return [cmdId, response]; diff --git a/js/event.ts b/js/event.ts index 61f21f2e7..8cd4d22d3 100644 --- a/js/event.ts +++ b/js/event.ts @@ -21,7 +21,7 @@ export class EventInit implements domTypes.EventInit { export class Event implements domTypes.Event { // Each event has the following associated flags private _canceledFlag = false; - private _dispatchedFlag = false; + private dispatchedFlag = false; private _initializedFlag = false; private _inPassiveListenerFlag = false; private _stopImmediatePropagationFlag = false; @@ -76,7 +76,7 @@ export class Event implements domTypes.Event { } get dispatched(): boolean { - return this._dispatchedFlag; + return this.dispatchedFlag; } get eventPhase(): number { diff --git a/js/flatbuffers.ts b/js/flatbuffers.ts index 73f3ceb82..f05bd1c55 100644 --- a/js/flatbuffers.ts +++ b/js/flatbuffers.ts @@ -17,7 +17,7 @@ globalBuilder.inUse = false; // This is a wrapper around the real Builder . // The purpose is to reuse a single ArrayBuffer for every message. // We can do this because the "control" messages sent to the privileged -// side are guaranteed to be used during the call to libdeno.send(). +// side are guaranteed to be used during the call to Deno.core.send(). export function createBuilder(): Builder { // eslint-disable-next-line @typescript-eslint/no-explicit-any const gb = globalBuilder as any; diff --git a/js/globals.ts b/js/globals.ts index af99ae7e0..5a0fb18ce 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -27,7 +27,7 @@ import * as performanceUtil from "./performance"; // These imports are not exposed and therefore are fine to just import the // symbols required. -import { libdeno } from "./libdeno"; +import { core } from "./core"; // During the build process, augmentations to the variable `window` in this // file are tracked and created as part of default library that is built into @@ -43,7 +43,6 @@ window.window = window; // This is the Deno namespace, it is handled differently from other window // properties when building the runtime type library, as the whole module // is flattened into a single namespace. - window.Deno = deno; Object.freeze(window.Deno); @@ -53,7 +52,7 @@ window.btoa = textEncoding.btoa; window.fetch = fetchTypes.fetch; window.clearTimeout = timers.clearTimer; window.clearInterval = timers.clearTimer; -window.console = new consoleTypes.Console(libdeno.print); +window.console = new consoleTypes.Console(core.print); window.setTimeout = timers.setTimeout; window.setInterval = timers.setInterval; window.location = (undefined as unknown) as domTypes.Location; diff --git a/js/libdeno.ts b/js/libdeno.ts deleted file mode 100644 index 485e67bb9..000000000 --- a/js/libdeno.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { window } from "./window"; - -// The libdeno functions are moved so that users can't access them. -type MessageCallback = (msg: Uint8Array) => void; - -interface EvalErrorInfo { - // Is the object thrown a native Error? - isNativeError: boolean; - // Was the error happened during compilation? - isCompileError: boolean; - // The actual thrown entity - // (might be an Error or anything else thrown by the user) - // If isNativeError is true, this is an Error - // eslint-disable-next-line @typescript-eslint/no-explicit-any - thrown: any; -} - -interface Libdeno { - recv(cb: MessageCallback): void; - - send( - control: null | ArrayBufferView, - data?: ArrayBufferView - ): null | Uint8Array; - - print(x: string, isErr?: boolean): void; - - shared: SharedArrayBuffer; - - /** Evaluate provided code in the current context. - * It differs from eval(...) in that it does not create a new context. - * Returns an array: [output, errInfo]. - * If an error occurs, `output` becomes null and `errInfo` is non-null. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - evalContext(code: string): [any, EvalErrorInfo | null]; - - errorToJSON: (e: Error) => string; -} - -export const libdeno = window.libdeno as Libdeno; @@ -1,6 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import * as msg from "gen/msg_generated"; -import { window } from "./window"; +import { core } from "./core"; import { handleAsyncMsgFromRust, sendSync } from "./dispatch"; import * as flatbuffers from "./flatbuffers"; import { TextDecoder } from "./text_encoding"; @@ -16,12 +16,7 @@ export let noColor: boolean; /** Path to the current deno process's executable file. */ export let execPath: string; -/** @internal */ -export function setGlobals( - pid_: number, - noColor_: boolean, - execPath_: string -): void { +function setGlobals(pid_: number, noColor_: boolean, execPath_: string): void { assert(!pid); pid = pid_; noColor = noColor_; @@ -169,7 +164,7 @@ function sendStart(): msg.StartRes { // the runtime and the compiler environments. // @internal export function start(source?: string): msg.StartRes { - window.DenoCore.setAsyncHandler(handleAsyncMsgFromRust); + core.setAsyncHandler(handleAsyncMsgFromRust); // 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 diff --git a/js/repl.ts b/js/repl.ts index c39a79a7d..068501873 100644 --- a/js/repl.ts +++ b/js/repl.ts @@ -6,7 +6,7 @@ import { close } from "./files"; import * as dispatch from "./dispatch"; import { exit } from "./os"; import { window } from "./window"; -import { libdeno } from "./libdeno"; +import { core } from "./core"; import { formatError } from "./format_error"; const helpMsg = [ @@ -90,7 +90,7 @@ function isRecoverableError(e: Error): boolean { // Returns true if code is consumed (no error/irrecoverable error). // Returns false if error is recoverable function evaluate(code: string): boolean { - const [result, errInfo] = libdeno.evalContext(code); + const [result, errInfo] = core.evalContext(code); if (!errInfo) { console.log(result); } else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) { @@ -99,7 +99,7 @@ function evaluate(code: string): boolean { } else { if (errInfo.isNativeError) { const formattedError = formatError( - libdeno.errorToJSON(errInfo.thrown as Error) + core.errorToJSON(errInfo.thrown as Error) ); console.error(formattedError); } else { @@ -140,7 +140,7 @@ export async function replLoop(): Promise<void> { if (err.message !== "Interrupted") { // e.g. this happens when we have deno.close(3). // We want to display the problem. - const formattedError = formatError(libdeno.errorToJSON(err)); + const formattedError = formatError(core.errorToJSON(err)); console.error(formattedError); } // Quit REPL anyways. @@ -162,7 +162,7 @@ export async function replLoop(): Promise<void> { } else { // e.g. this happens when we have deno.close(3). // We want to display the problem. - const formattedError = formatError(libdeno.errorToJSON(err)); + const formattedError = formatError(core.errorToJSON(err)); console.error(formattedError); quitRepl(1); } |