diff options
author | Yusuke Tanaka <yusuktan@maguro.dev> | 2021-07-26 20:52:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 13:52:59 +0200 |
commit | 865d9ddd51dcc8776bf8c3976057e2f29a1a5af2 (patch) | |
tree | ecaf2293a4534726c56722875c628ea14bfad559 | |
parent | df26a3563edd501380d5d5da5138eb67acb06645 (diff) |
refactor: use `primordials` in runtime, extensions and core (#11500)
-rw-r--r-- | core/error_builder_test.js | 1 | ||||
-rw-r--r-- | extensions/console/02_console.js | 1 | ||||
-rw-r--r-- | extensions/crypto/00_crypto.js | 3 | ||||
-rw-r--r-- | extensions/fetch/22_body.js | 1 | ||||
-rw-r--r-- | extensions/url/00_url.js | 4 | ||||
-rw-r--r-- | extensions/web/01_dom_exception.js | 10 | ||||
-rw-r--r-- | extensions/web/02_event.js | 1 | ||||
-rw-r--r-- | extensions/web/05_base64.js | 1 | ||||
-rw-r--r-- | extensions/web/06_streams.js | 49 | ||||
-rw-r--r-- | extensions/web/10_filereader.js | 1 | ||||
-rw-r--r-- | extensions/web/13_message_port.js | 15 | ||||
-rw-r--r-- | extensions/webidl/00_webidl.js | 85 | ||||
-rw-r--r-- | runtime/js/06_util.js | 10 | ||||
-rw-r--r-- | runtime/js/99_main.js | 2 |
14 files changed, 107 insertions, 77 deletions
diff --git a/core/error_builder_test.js b/core/error_builder_test.js index aae47c6cd..1ee092522 100644 --- a/core/error_builder_test.js +++ b/core/error_builder_test.js @@ -1,3 +1,4 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. const { core } = Deno; class DOMException { diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js index 10819cd6f..40ff2e25d 100644 --- a/extensions/console/02_console.js +++ b/extensions/console/02_console.js @@ -51,6 +51,7 @@ RegExpPrototypeToString, Set, SetPrototypeEntries, + Symbol, SymbolPrototypeToString, SymbolToStringTag, SymbolHasInstance, diff --git a/extensions/crypto/00_crypto.js b/extensions/crypto/00_crypto.js index 99e6864e7..97a8ed77e 100644 --- a/extensions/crypto/00_crypto.js +++ b/extensions/crypto/00_crypto.js @@ -17,6 +17,7 @@ ArrayPrototypeFind, ArrayBufferIsView, ArrayPrototypeIncludes, + BigInt64Array, StringPrototypeToUpperCase, Symbol, SymbolFor, @@ -187,7 +188,7 @@ return this[_algorithm]; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "CryptoKey"; } diff --git a/extensions/fetch/22_body.js b/extensions/fetch/22_body.js index 97ed57c8b..49da149c2 100644 --- a/extensions/fetch/22_body.js +++ b/extensions/fetch/22_body.js @@ -22,6 +22,7 @@ const { isReadableStreamDisturbed, errorReadableStream, createProxy } = globalThis.__bootstrap.streams; const { + ArrayBuffer, ArrayBufferIsView, ArrayPrototypePush, ArrayPrototypeMap, diff --git a/extensions/url/00_url.js b/extensions/url/00_url.js index 172a5f62d..f3c12d0c2 100644 --- a/extensions/url/00_url.js +++ b/extensions/url/00_url.js @@ -20,8 +20,10 @@ ObjectKeys, StringPrototypeSlice, Symbol, + SymbolFor, SymbolIterator, SymbolToStringTag, + TypeError, } = window.__bootstrap.primordials; const _list = Symbol("list"); @@ -280,7 +282,7 @@ this[_url] = parts; } - [Symbol.for("Deno.privateCustomInspect")](inspect) { + [SymbolFor("Deno.privateCustomInspect")](inspect) { const object = { href: this.href, origin: this.origin, diff --git a/extensions/web/01_dom_exception.js b/extensions/web/01_dom_exception.js index 3e282d969..c6f60ae2f 100644 --- a/extensions/web/01_dom_exception.js +++ b/extensions/web/01_dom_exception.js @@ -11,10 +11,12 @@ ((window) => { const { - Error, + ErrorPrototype, ObjectDefineProperty, ObjectEntries, ObjectSetPrototypeOf, + SymbolFor, + SymbolToStringTag, } = window.__bootstrap.primordials; const webidl = window.__bootstrap.webidl; const consoleInternal = window.__bootstrap.console; @@ -106,11 +108,11 @@ return this.#code; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "DOMException"; } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { if (this instanceof DOMException) { return `DOMException: ${this.#message}`; } else { @@ -127,7 +129,7 @@ } } - ObjectSetPrototypeOf(DOMException.prototype, Error.prototype); + ObjectSetPrototypeOf(DOMException.prototype, ErrorPrototype); webidl.configurePrototype(DOMException); diff --git a/extensions/web/02_event.js b/extensions/web/02_event.js index a8dd95dbd..4cca20e00 100644 --- a/extensions/web/02_event.js +++ b/extensions/web/02_event.js @@ -33,6 +33,7 @@ Symbol, SymbolFor, SymbolToStringTag, + TypeError, WeakMap, WeakMapPrototypeGet, WeakMapPrototypeSet, diff --git a/extensions/web/05_base64.js b/extensions/web/05_base64.js index 818815ecd..9c9c23b0f 100644 --- a/extensions/web/05_base64.js +++ b/extensions/web/05_base64.js @@ -21,6 +21,7 @@ ArrayPrototypeJoin, StringFromCharCode, TypedArrayFrom, + Uint8Array, } = window.__bootstrap.primordials; /** diff --git a/extensions/web/06_streams.js b/extensions/web/06_streams.js index ff6c9d7d8..a3dc9439a 100644 --- a/extensions/web/06_streams.js +++ b/extensions/web/06_streams.js @@ -28,7 +28,10 @@ PromiseReject, queueMicrotask, RangeError, + Symbol, SymbolAsyncIterator, + SymbolFor, + SymbolToStringTag, TypeError, Uint8Array, WeakMap, @@ -198,7 +201,7 @@ function transferArrayBuffer(O) { assert(!isDetachedBuffer(O)); const transferredIshVersion = O.slice(0); - Object.defineProperty(O, "byteLength", { + ObjectDefineProperty(O, "byteLength", { get() { return 0; }, @@ -3018,7 +3021,7 @@ return WeakMapPrototypeGet(byteSizeFunctionWeakMap, this[_globalObject]); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof ByteLengthQueuingStrategy, @@ -3029,7 +3032,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "ByteLengthQueuingStrategy"; } } @@ -3074,7 +3077,7 @@ return WeakMapPrototypeGet(countSizeFunctionWeakMap, this[_globalObject]); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof CountQueuingStrategy, @@ -3085,7 +3088,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "CountQueuingStrategy"; } } @@ -3333,11 +3336,11 @@ return iterator; } - [Symbol.for("Deno.privateCustomInspect")](inspect) { + [SymbolFor("Deno.privateCustomInspect")](inspect) { return `${this.constructor.name} ${inspect({ locked: this.locked })}`; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "ReadableStream"; } } @@ -3453,11 +3456,11 @@ return readableStreamReaderGenericCancel(this, reason); } - [Symbol.for("Deno.privateCustomInspect")](inspect) { + [SymbolFor("Deno.privateCustomInspect")](inspect) { return `${this.constructor.name} ${inspect({ closed: this.closed })}`; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "ReadableStreamDefaultReader"; } } @@ -3571,7 +3574,7 @@ readableByteStreamControllerError(this, e); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof ReadableByteStreamController, @@ -3579,7 +3582,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "ReadableByteStreamController"; } @@ -3696,7 +3699,7 @@ readableStreamDefaultControllerError(this, e); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof ReadableStreamDefaultController, @@ -3704,7 +3707,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "ReadableStreamDefaultController"; } @@ -3854,13 +3857,13 @@ return this[_writable]; } - [Symbol.for("Deno.privateCustomInspect")](inspect) { + [SymbolFor("Deno.privateCustomInspect")](inspect) { return `${this.constructor.name} ${ inspect({ readable: this.readable, writable: this.writable }) }`; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "TransformStream"; } } @@ -3919,7 +3922,7 @@ transformStreamDefaultControllerTerminate(this); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof TransformStreamDefaultController, @@ -3927,7 +3930,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "TransformStreamDefaultController"; } } @@ -4057,11 +4060,11 @@ return acquireWritableStreamDefaultWriter(this); } - [Symbol.for("Deno.privateCustomInspect")](inspect) { + [SymbolFor("Deno.privateCustomInspect")](inspect) { return `${this.constructor.name} ${inspect({ locked: this.locked })}`; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "WritableStream"; } } @@ -4198,7 +4201,7 @@ return writableStreamDefaultWriterWrite(this, chunk); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof WritableStreamDefaultWriter, @@ -4210,7 +4213,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "WritableStreamDefaultWriter"; } } @@ -4258,7 +4261,7 @@ writableStreamDefaultControllerError(this, e); } - [Symbol.for("Deno.customInspect")](inspect) { + [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, evaluate: this instanceof WritableStreamDefaultController, @@ -4266,7 +4269,7 @@ })); } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "WritableStreamDefaultController"; } diff --git a/extensions/web/10_filereader.js b/extensions/web/10_filereader.js index ad10e2831..13fe6af2d 100644 --- a/extensions/web/10_filereader.js +++ b/extensions/web/10_filereader.js @@ -28,6 +28,7 @@ MapPrototypeGet, MapPrototypeSet, ObjectDefineProperty, + queueMicrotask, StringFromCodePoint, Symbol, SymbolToStringTag, diff --git a/extensions/web/13_message_port.js b/extensions/web/13_message_port.js index 3bd7c692b..d111b5e01 100644 --- a/extensions/web/13_message_port.js +++ b/extensions/web/13_message_port.js @@ -14,6 +14,13 @@ const { setEventTargetData } = window.__bootstrap.eventTarget; const { defineEventHandler } = window.__bootstrap.event; const { DOMException } = window.__bootstrap.domException; + const { + ObjectSetPrototypeOf, + Symbol, + SymbolFor, + SymbolToStringTag, + TypeError, + } = window.__bootstrap.primordials; class MessageChannel { /** @type {MessagePort} */ @@ -40,13 +47,13 @@ return this.#port2; } - [Symbol.for("Deno.inspect")](inspect) { + [SymbolFor("Deno.inspect")](inspect) { return `MessageChannel ${ inspect({ port1: this.port1, port2: this.port2 }) }`; } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "MessageChannel"; } } @@ -62,7 +69,7 @@ */ function createMessagePort(id) { const port = core.createHostObject(); - Object.setPrototypeOf(port, MessagePort.prototype); + ObjectSetPrototypeOf(port, MessagePort.prototype); port[webidl.brand] = webidl.brand; setEventTargetData(port); port[_id] = id; @@ -155,7 +162,7 @@ } } - get [Symbol.toStringTag]() { + get [SymbolToStringTag]() { return "MessagePort"; } } diff --git a/extensions/webidl/00_webidl.js b/extensions/webidl/00_webidl.js index 16a6ab4a9..40250afe1 100644 --- a/extensions/webidl/00_webidl.js +++ b/extensions/webidl/00_webidl.js @@ -12,8 +12,10 @@ const { ArrayBuffer, ArrayBufferIsView, + ArrayPrototypeForEach, ArrayPrototypePush, ArrayPrototypeSort, + ArrayIteratorPrototype, BigInt, BigIntAsIntN, BigIntAsUintN, @@ -497,45 +499,48 @@ ObjectGetPrototypeOf(Uint8Array).prototype, SymbolToStringTag, ).get; - [ - Int8Array, - Int16Array, - Int32Array, - Uint8Array, - Uint16Array, - Uint32Array, - Uint8ClampedArray, - Float32Array, - Float64Array, - ].forEach((func) => { - const name = func.name; - const article = RegExpPrototypeTest(/^[AEIOU]/, name) ? "an" : "a"; - converters[name] = (V, opts = {}) => { - if (!ArrayBufferIsView(V) || typedArrayNameGetter.call(V) !== name) { - throw makeException( - TypeError, - `is not ${article} ${name} object`, - opts, - ); - } - if (!opts.allowShared && isSharedArrayBuffer(V.buffer)) { - throw makeException( - TypeError, - "is a view on a SharedArrayBuffer, which is not allowed", - opts, - ); - } - if (isArrayBufferDetached(V.buffer)) { - throw makeException( - TypeError, - "is a view on a detached ArrayBuffer", - opts, - ); - } + ArrayPrototypeForEach( + [ + Int8Array, + Int16Array, + Int32Array, + Uint8Array, + Uint16Array, + Uint32Array, + Uint8ClampedArray, + Float32Array, + Float64Array, + ], + (func) => { + const name = func.name; + const article = RegExpPrototypeTest(/^[AEIOU]/, name) ? "an" : "a"; + converters[name] = (V, opts = {}) => { + if (!ArrayBufferIsView(V) || typedArrayNameGetter.call(V) !== name) { + throw makeException( + TypeError, + `is not ${article} ${name} object`, + opts, + ); + } + if (!opts.allowShared && isSharedArrayBuffer(V.buffer)) { + throw makeException( + TypeError, + "is a view on a SharedArrayBuffer, which is not allowed", + opts, + ); + } + if (isArrayBufferDetached(V.buffer)) { + throw makeException( + TypeError, + "is a view on a detached ArrayBuffer", + opts, + ); + } - return V; - }; - }); + return V; + }; + }, + ); // Common definitions @@ -921,9 +926,7 @@ const _iteratorInternal = Symbol("iterator internal"); - const globalIteratorPrototype = ObjectGetPrototypeOf(ObjectGetPrototypeOf( - [][SymbolIterator](), - )); + const globalIteratorPrototype = ObjectGetPrototypeOf(ArrayIteratorPrototype); function mixinPairIterable(name, prototype, dataSymbol, keyKey, valueKey) { const iteratorPrototype = ObjectCreate(globalIteratorPrototype, { diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index 88c2edc74..b6a3c3438 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -2,8 +2,14 @@ "use strict"; ((window) => { - const { ObjectDefineProperty, StringPrototypeReplace, TypeError, Promise } = - window.__bootstrap.primordials; + const { + ObjectDefineProperty, + StringPrototypeReplace, + TypeError, + Promise, + decodeURIComponent, + Error, + } = window.__bootstrap.primordials; const { build } = window.__bootstrap.build; const { URL } = window.__bootstrap.url; let logDebug = false; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 834e692f6..a48105559 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -552,7 +552,7 @@ delete Object.prototype.__proto__; ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope); ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties); ObjectDefineProperties(globalThis, { name: util.readOnly(name) }); - Object.setPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype); + ObjectSetPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype); const consoleFromDeno = globalThis.console; wrapConsole(consoleFromDeno, consoleFromV8); |