summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/compiler.ts27
-rw-r--r--js/dispatch_json.ts6
-rw-r--r--js/errors.ts58
-rw-r--r--js/flatbuffers.ts56
4 files changed, 72 insertions, 75 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 60fe49701..e10dc50db 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -17,8 +17,14 @@ import { window } from "./window";
import { postMessage, workerClose, workerMain } from "./workers";
import { writeFileSync } from "./write_file";
-// TODO(ry) msg_generated import will be removed soon.
-import * as msg from "gen/cli/msg_generated";
+// Warning! The values in this enum are duplicated in cli/msg.rs
+// Update carefully!
+enum MediaType {
+ JavaScript = 0,
+ TypeScript = 1,
+ Json = 2,
+ Unknown = 3
+}
// Startup boilerplate. This is necessary because the compiler has its own
// snapshot. (It would be great if we could remove these things or centralize
@@ -112,7 +118,7 @@ const ignoredCompilerOptions: ReadonlyArray<string> = [
interface SourceFile {
moduleName: string | undefined;
filename: string | undefined;
- mediaType: msg.MediaType;
+ mediaType: MediaType;
sourceCode: string | undefined;
typeDirectives?: Record<string, string>;
}
@@ -173,18 +179,15 @@ function emitBundle(fileName: string, data: string): void {
}
/** Returns the TypeScript Extension enum for a given media type. */
-function getExtension(
- fileName: string,
- mediaType: msg.MediaType
-): ts.Extension {
+function getExtension(fileName: string, mediaType: MediaType): ts.Extension {
switch (mediaType) {
- case msg.MediaType.JavaScript:
+ case MediaType.JavaScript:
return ts.Extension.Js;
- case msg.MediaType.TypeScript:
+ case MediaType.TypeScript:
return fileName.endsWith(".d.ts") ? ts.Extension.Dts : ts.Extension.Ts;
- case msg.MediaType.Json:
+ case MediaType.Json:
return ts.Extension.Json;
- case msg.MediaType.Unknown:
+ case MediaType.Unknown:
default:
throw TypeError("Cannot resolve extension.");
}
@@ -224,7 +227,7 @@ class Host implements ts.CompilerHost {
const sourceFile = {
moduleName,
filename: specifier,
- mediaType: msg.MediaType.TypeScript,
+ mediaType: MediaType.TypeScript,
sourceCode
};
this._sourceFileCache[moduleName] = sourceFile;
diff --git a/js/dispatch_json.ts b/js/dispatch_json.ts
index e8c976164..bde2b7cb1 100644
--- a/js/dispatch_json.ts
+++ b/js/dispatch_json.ts
@@ -1,12 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-// Do not add flatbuffer dependencies to this module.
-// TODO(ry) Currently ErrorKind enum is defined in FlatBuffers. Therefore
-// we must still reference the msg_generated.ts. This should be removed!
-import { ErrorKind } from "gen/cli/msg_generated";
import * as util from "./util";
import { TextEncoder, TextDecoder } from "./text_encoding";
import { core } from "./core";
-import { DenoError } from "./errors";
+import { ErrorKind, DenoError } from "./errors";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Ok = any;
diff --git a/js/errors.ts b/js/errors.ts
index 717015589..02ddfa2f2 100644
--- a/js/errors.ts
+++ b/js/errors.ts
@@ -1,6 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { ErrorKind } from "gen/cli/msg_generated";
-export { ErrorKind } from "gen/cli/msg_generated";
/** A Deno specific error. The `kind` property is set to a specific error code
* which can be used to in application logic.
@@ -23,3 +21,59 @@ export class DenoError<T extends ErrorKind> extends Error {
this.name = ErrorKind[kind];
}
}
+
+// Warning! The values in this enum are duplicated in cli/msg.rs
+// Update carefully!
+export enum ErrorKind {
+ NoError = 0,
+ NotFound = 1,
+ PermissionDenied = 2,
+ ConnectionRefused = 3,
+ ConnectionReset = 4,
+ ConnectionAborted = 5,
+ NotConnected = 6,
+ AddrInUse = 7,
+ AddrNotAvailable = 8,
+ BrokenPipe = 9,
+ AlreadyExists = 10,
+ WouldBlock = 11,
+ InvalidInput = 12,
+ InvalidData = 13,
+ TimedOut = 14,
+ Interrupted = 15,
+ WriteZero = 16,
+ Other = 17,
+ UnexpectedEof = 18,
+ BadResource = 19,
+ CommandFailed = 20,
+ EmptyHost = 21,
+ IdnaError = 22,
+ InvalidPort = 23,
+ InvalidIpv4Address = 24,
+ InvalidIpv6Address = 25,
+ InvalidDomainCharacter = 26,
+ RelativeUrlWithoutBase = 27,
+ RelativeUrlWithCannotBeABaseBase = 28,
+ SetHostOnCannotBeABaseUrl = 29,
+ Overflow = 30,
+ HttpUser = 31,
+ HttpClosed = 32,
+ HttpCanceled = 33,
+ HttpParse = 34,
+ HttpOther = 35,
+ TooLarge = 36,
+ InvalidUri = 37,
+ InvalidSeekMode = 38,
+ OpNotAvailable = 39,
+ WorkerInitFailed = 40,
+ UnixError = 41,
+ NoAsyncSupport = 42,
+ NoSyncSupport = 43,
+ ImportMapError = 44,
+ InvalidPath = 45,
+ ImportPrefixMissing = 46,
+ UnsupportedFetchScheme = 47,
+ TooManyRedirects = 48,
+ Diagnostic = 49,
+ JSError = 50
+}
diff --git a/js/flatbuffers.ts b/js/flatbuffers.ts
deleted file mode 100644
index f05bd1c55..000000000
--- a/js/flatbuffers.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { flatbuffers } from "flatbuffers";
-import * as util from "./util";
-
-/* eslint-disable @typescript-eslint/camelcase */
-
-// Re-export some types.
-export type Offset = flatbuffers.Offset;
-export class ByteBuffer extends flatbuffers.ByteBuffer {}
-export interface Builder extends flatbuffers.Builder {
- inUse: boolean;
-}
-
-const globalBuilder = new flatbuffers.Builder() as Builder;
-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 Deno.core.send().
-export function createBuilder(): Builder {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const gb = globalBuilder as any;
- util.assert(!gb.inUse);
-
- let bb = globalBuilder.dataBuffer();
- // Only create a new backing ArrayBuffer if the previous one had grown very
- // large in capacity. This should only happen rarely.
- if (bb.capacity() > 1024) {
- util.log(`realloc flatbuffer ArrayBuffer because it was ${bb.capacity()}`);
- bb = ByteBuffer.allocate(1024);
- }
- gb.bb = bb;
- // Remaining space in the ByteBuffer.
- gb.space = globalBuilder.dataBuffer().capacity();
- // Minimum alignment encountered so far.
- gb.minalign = 1;
- // The vtable for the current table.
- gb.vtable = null;
- // The amount of fields we're actually using.
- gb.vtable_in_use = 0;
- // Whether we are currently serializing a table.
- gb.isNested = false;
- // Starting offset of the current struct/table.
- gb.object_start = 0;
- // List of offsets of all vtables.
- gb.vtables = [];
- // For the current vector being built.
- gb.vector_num_elems = 0;
- // False omits default values from the serialized data
- gb.force_defaults = false;
-
- gb.inUse = true;
-
- return gb as Builder;
-}