diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-03-19 13:57:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 13:57:37 +0100 |
commit | e55dee7fd894f705a0268a4734b00197021f0617 (patch) | |
tree | f6232128259430ba943da2c1d9ade6ad17697adc /ext | |
parent | ad8e2383487e8ef4f15e7b86df80f6dc98fdcc79 (diff) |
refactor: cleanup assert() & AssertionError definitions (#13859)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/web/00_infra.js | 21 | ||||
-rw-r--r-- | ext/web/02_timers.js | 21 | ||||
-rw-r--r-- | ext/web/06_streams.js | 20 |
3 files changed, 23 insertions, 39 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js index a250dd69b..f46316bfe 100644 --- a/ext/web/00_infra.js +++ b/ext/web/00_infra.js @@ -11,6 +11,7 @@ ((window) => { const core = Deno.core; const { + Error, RegExp, ArrayPrototypeMap, StringPrototypeCharCodeAt, @@ -275,6 +276,24 @@ return StringPrototypeMatch(s, HTTP_BETWEEN_WHITESPACE)?.[1] ?? ""; } + class AssertionError extends Error { + constructor(msg) { + super(msg); + this.name = "AssertionError"; + } + } + + /** + * @param {unknown} cond + * @param {string=} msg + * @returns {asserts cond} + */ + function assert(cond, msg = "Assertion failed.") { + if (!cond) { + throw new AssertionError(msg); + } + } + window.__bootstrap.infra = { collectSequenceOfCodepoints, ASCII_DIGIT, @@ -299,5 +318,7 @@ collectHttpQuotedString, forgivingBase64Encode, forgivingBase64Decode, + AssertionError, + assert, }; })(globalThis); diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index a0b1deb45..808d99563 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -6,7 +6,6 @@ const { ArrayPrototypePush, ArrayPrototypeShift, - Error, FunctionPrototypeCall, Map, MapPrototypeDelete, @@ -22,25 +21,7 @@ TypeError, } = window.__bootstrap.primordials; const { webidl } = window.__bootstrap; - - // Shamelessly cribbed from extensions/fetch/11_streams.js - class AssertionError extends Error { - constructor(msg) { - super(msg); - this.name = "AssertionError"; - } - } - - /** - * @param {unknown} cond - * @param {string=} msg - * @returns {asserts cond} - */ - function assert(cond, msg = "Assertion failed.") { - if (!cond) { - throw new AssertionError(msg); - } - } + const { assert } = window.__bootstrap.infra; function opNow() { return core.opSync("op_now"); diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 777ad152b..7ef5a6131 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -21,7 +21,6 @@ BigInt64ArrayPrototype, BigUint64ArrayPrototype, DataView, - Error, Int8ArrayPrototype, Int16ArrayPrototype, Int32ArrayPrototype, @@ -58,24 +57,7 @@ WeakMapPrototypeSet, } = globalThis.__bootstrap.primordials; const consoleInternal = window.__bootstrap.console; - - class AssertionError extends Error { - constructor(msg) { - super(msg); - this.name = "AssertionError"; - } - } - - /** - * @param {unknown} cond - * @param {string=} msg - * @returns {asserts cond} - */ - function assert(cond, msg = "Assertion failed.") { - if (!cond) { - throw new AssertionError(msg); - } - } + const { AssertionError, assert } = window.__bootstrap.infra; /** @template T */ class Deferred { |