diff options
Diffstat (limited to 'cli/rt')
-rw-r--r-- | cli/rt/01_errors.js | 96 | ||||
-rw-r--r-- | cli/rt/10_dispatch_json.js | 3 | ||||
-rw-r--r-- | cli/rt/10_dispatch_minimal.js | 13 | ||||
-rw-r--r-- | cli/rt/99_main.js | 29 |
4 files changed, 37 insertions, 104 deletions
diff --git a/cli/rt/01_errors.js b/cli/rt/01_errors.js index 8390dd803..fb2bb78c2 100644 --- a/cli/rt/01_errors.js +++ b/cli/rt/01_errors.js @@ -1,101 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. ((window) => { - // Warning! The values in this enum are duplicated in cli/op_error.rs - // Update carefully! - const ErrorKind = { - 1: "NotFound", - 2: "PermissionDenied", - 3: "ConnectionRefused", - 4: "ConnectionReset", - 5: "ConnectionAborted", - 6: "NotConnected", - 7: "AddrInUse", - 8: "AddrNotAvailable", - 9: "BrokenPipe", - 10: "AlreadyExists", - 13: "InvalidData", - 14: "TimedOut", - 15: "Interrupted", - 16: "WriteZero", - 17: "UnexpectedEof", - 18: "BadResource", - 19: "Http", - 20: "URIError", - 21: "TypeError", - 22: "Other", - 23: "Busy", - - NotFound: 1, - PermissionDenied: 2, - ConnectionRefused: 3, - ConnectionReset: 4, - ConnectionAborted: 5, - NotConnected: 6, - AddrInUse: 7, - AddrNotAvailable: 8, - BrokenPipe: 9, - AlreadyExists: 10, - InvalidData: 13, - TimedOut: 14, - Interrupted: 15, - WriteZero: 16, - UnexpectedEof: 17, - BadResource: 18, - Http: 19, - URIError: 20, - TypeError: 21, - Other: 22, - Busy: 23, - }; - - function getErrorClass(kind) { - switch (kind) { - case ErrorKind.TypeError: - return TypeError; - case ErrorKind.Other: - return Error; - case ErrorKind.URIError: - return URIError; - case ErrorKind.NotFound: - return NotFound; - case ErrorKind.PermissionDenied: - return PermissionDenied; - case ErrorKind.ConnectionRefused: - return ConnectionRefused; - case ErrorKind.ConnectionReset: - return ConnectionReset; - case ErrorKind.ConnectionAborted: - return ConnectionAborted; - case ErrorKind.NotConnected: - return NotConnected; - case ErrorKind.AddrInUse: - return AddrInUse; - case ErrorKind.AddrNotAvailable: - return AddrNotAvailable; - case ErrorKind.BrokenPipe: - return BrokenPipe; - case ErrorKind.AlreadyExists: - return AlreadyExists; - case ErrorKind.InvalidData: - return InvalidData; - case ErrorKind.TimedOut: - return TimedOut; - case ErrorKind.Interrupted: - return Interrupted; - case ErrorKind.WriteZero: - return WriteZero; - case ErrorKind.UnexpectedEof: - return UnexpectedEof; - case ErrorKind.BadResource: - return BadResource; - case ErrorKind.Http: - return Http; - case ErrorKind.Busy: - return Busy; - } - } - class NotFound extends Error { constructor(msg) { super(msg); @@ -245,6 +150,5 @@ window.__bootstrap.errors = { errors, - getErrorClass, }; })(this); diff --git a/cli/rt/10_dispatch_json.js b/cli/rt/10_dispatch_json.js index 3d19ea62a..05b4d46ed 100644 --- a/cli/rt/10_dispatch_json.js +++ b/cli/rt/10_dispatch_json.js @@ -3,7 +3,6 @@ ((window) => { const core = window.Deno.core; const util = window.__bootstrap.util; - const getErrorClass = window.__bootstrap.errors.getErrorClass; // Using an object without a prototype because `Map` was causing GC problems. const promiseTable = Object.create(null); let _nextPromiseId = 1; @@ -22,7 +21,7 @@ function unwrapResponse(res) { if (res.err != null) { - throw new (getErrorClass(res.err.kind))(res.err.message); + throw new (core.getErrorClass(res.err.kind))(res.err.message); } util.assert(res.ok != null); return res.ok; diff --git a/cli/rt/10_dispatch_minimal.js b/cli/rt/10_dispatch_minimal.js index 6137449f4..0a0a4f99f 100644 --- a/cli/rt/10_dispatch_minimal.js +++ b/cli/rt/10_dispatch_minimal.js @@ -3,7 +3,6 @@ ((window) => { const core = window.Deno.core; const util = window.__bootstrap.util; - const errorNs = window.__bootstrap.errors; // Using an object without a prototype because `Map` was causing GC problems. const promiseTableMin = Object.create(null); @@ -32,11 +31,13 @@ let err; if (arg < 0) { - const kind = result; - const message = decoder.decode(ui8.subarray(12)); - err = { kind, message }; + const codeLen = result; + const codeAndMessage = decoder.decode(ui8.subarray(12)); + const errorCode = codeAndMessage.slice(0, codeLen); + const message = codeAndMessage.slice(codeLen); + err = { kind: errorCode, message }; } else if (ui8.length != 12) { - throw new errorNs.errors.InvalidData("BadMessage"); + throw new TypeError("Malformed response message"); } return { @@ -49,7 +50,7 @@ function unwrapResponse(res) { if (res.err != null) { - throw new (errorNs.getErrorClass(res.err.kind))(res.err.message); + throw new (core.getErrorClass(res.err.kind))(res.err.message); } return res.result; } diff --git a/cli/rt/99_main.js b/cli/rt/99_main.js index 325881b5a..873e42291 100644 --- a/cli/rt/99_main.js +++ b/cli/rt/99_main.js @@ -34,6 +34,7 @@ delete Object.prototype.__proto__; const fetch = window.__bootstrap.fetch; const denoNs = window.__bootstrap.denoNs; const denoNsUnstable = window.__bootstrap.denoNsUnstable; + const errors = window.__bootstrap.errors.errors; let windowIsClosing = false; @@ -175,6 +176,30 @@ delete Object.prototype.__proto__; return s; } + function registerErrors() { + core.registerErrorClass("NotFound", errors.NotFound); + core.registerErrorClass("PermissionDenied", errors.PermissionDenied); + core.registerErrorClass("ConnectionRefused", errors.ConnectionRefused); + core.registerErrorClass("ConnectionReset", errors.ConnectionReset); + core.registerErrorClass("ConnectionAborted", errors.ConnectionAborted); + core.registerErrorClass("NotConnected", errors.NotConnected); + core.registerErrorClass("AddrInUse", errors.AddrInUse); + core.registerErrorClass("AddrNotAvailable", errors.AddrNotAvailable); + core.registerErrorClass("BrokenPipe", errors.BrokenPipe); + core.registerErrorClass("AlreadyExists", errors.AlreadyExists); + core.registerErrorClass("InvalidData", errors.InvalidData); + core.registerErrorClass("TimedOut", errors.TimedOut); + core.registerErrorClass("Interrupted", errors.Interrupted); + core.registerErrorClass("WriteZero", errors.WriteZero); + core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof); + core.registerErrorClass("BadResource", errors.BadResource); + core.registerErrorClass("Http", errors.Http); + core.registerErrorClass("URIError", URIError); + core.registerErrorClass("TypeError", TypeError); + core.registerErrorClass("Other", Error); + core.registerErrorClass("Busy", errors.Busy); + } + // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope const windowOrWorkerGlobalScopeMethods = { atob: util.writable(atob), @@ -290,6 +315,8 @@ delete Object.prototype.__proto__; const { args, cwd, noColor, pid, ppid, repl, unstableFlag } = runtimeStart(); + registerErrors(); + const finalDenoNs = { core, internal: internalSymbol, @@ -347,6 +374,8 @@ delete Object.prototype.__proto__; internalName ?? name, ); + registerErrors(); + const finalDenoNs = { core, internal: internalSymbol, |