From f248e6f1778dc26db91d3322de2ecca5d1aa9866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 27 Jan 2022 16:27:22 +0100 Subject: [PATCH] Revert "refactor: update runtime code for primordial checks for "instanceof" (#13497)" (#13511) This reverts commit 884143218fad0e18f7553aaf079d52de703f7601. --- core/01_core.js | 4 - ext/broadcast_channel/01_broadcast_channel.js | 5 +- ext/console/02_console.js | 62 ++-- ext/crypto/00_crypto.js | 100 +++--- ext/crypto/01_webidl.js | 13 +- ext/fetch/20_headers.js | 7 +- ext/fetch/21_formdata.js | 34 +- ext/fetch/22_body.js | 105 ++---- ext/fetch/22_http_client.js | 2 - ext/fetch/23_request.js | 36 +- ext/fetch/23_response.js | 26 +- ext/fetch/26_fetch.js | 46 +-- ext/ffi/00_ffi.js | 8 +- ext/http/01_http.js | 57 +--- ext/net/01_net.js | 13 +- ext/timers/01_timers.js | 3 +- ext/timers/02_performance.js | 61 ++-- ext/url/00_url.js | 66 ++-- ext/url/01_urlpattern.js | 21 +- ext/web/01_dom_exception.js | 4 +- ext/web/02_event.js | 16 +- ext/web/02_structured_clone.js | 12 +- ext/web/03_abort_signal.js | 15 +- ext/web/06_streams.js | 235 +++++-------- ext/web/08_text_encoding.js | 42 +-- ext/web/09_file.js | 43 +-- ext/web/10_filereader.js | 28 +- ext/web/13_message_port.js | 39 +-- ext/web/14_compression.js | 10 +- ext/webgpu/01_webgpu.js | 314 ++++++++---------- ext/webgpu/02_idl_types.js | 68 ++-- ext/webidl/00_webidl.js | 24 +- ext/websocket/01_websocket.js | 62 ++-- ext/websocket/02_websocketstream.js | 31 +- ext/webstorage/01_webstorage.js | 14 +- runtime/js/06_util.js | 11 +- runtime/js/11_workers.js | 12 +- runtime/js/30_fs.js | 4 +- runtime/js/40_fs_events.js | 9 +- runtime/js/40_testing.js | 9 +- runtime/js/99_main.js | 15 +- 41 files changed, 658 insertions(+), 1028 deletions(-) diff --git a/core/01_core.js b/core/01_core.js index d9a110eea5..66530f7d57 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -195,7 +195,6 @@ this.name = "BadResource"; } } - const BadResourcePrototype = BadResource.prototype; class Interrupted extends Error { constructor(msg) { @@ -203,7 +202,6 @@ this.name = "Interrupted"; } } - const InterruptedPrototype = Interrupted.prototype; // Extra Deno.core.* exports const core = ObjectAssign(globalThis.Deno.core, { @@ -223,9 +221,7 @@ opresolve, syncOpsCache, BadResource, - BadResourcePrototype, Interrupted, - InterruptedPrototype, }); ObjectAssign(globalThis.__bootstrap, { core }); diff --git a/ext/broadcast_channel/01_broadcast_channel.js b/ext/broadcast_channel/01_broadcast_channel.js index dad94860d5..d89b19a1b9 100644 --- a/ext/broadcast_channel/01_broadcast_channel.js +++ b/ext/broadcast_channel/01_broadcast_channel.js @@ -98,7 +98,7 @@ } postMessage(message) { - webidl.assertBranded(this, BroadcastChannelPrototype); + webidl.assertBranded(this, BroadcastChannel); const prefix = "Failed to execute 'postMessage' on 'BroadcastChannel'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -121,7 +121,7 @@ } close() { - webidl.assertBranded(this, BroadcastChannelPrototype); + webidl.assertBranded(this, BroadcastChannel); this[_closed] = true; const index = ArrayPrototypeIndexOf(channels, this); @@ -134,7 +134,6 @@ defineEventHandler(BroadcastChannel.prototype, "message"); defineEventHandler(BroadcastChannel.prototype, "messageerror"); - const BroadcastChannelPrototype = BroadcastChannel.prototype; window.__bootstrap.broadcastChannel = { BroadcastChannel }; })(this); diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 4dab799b96..0ebf5a4d94 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -10,13 +10,12 @@ const { ArrayBufferIsView, isNaN, - DataViewPrototype, - DatePrototype, + DataView, + Date, DateNow, DatePrototypeGetTime, DatePrototypeToISOString, Boolean, - BooleanPrototype, BooleanPrototypeToString, ObjectKeys, ObjectCreate, @@ -28,11 +27,9 @@ ObjectGetOwnPropertyDescriptor, ObjectGetOwnPropertySymbols, ObjectPrototypeHasOwnProperty, - ObjectPrototypeIsPrototypeOf, ObjectPrototypePropertyIsEnumerable, - PromisePrototype, + Promise, String, - StringPrototype, StringPrototypeRepeat, StringPrototypeReplace, StringPrototypeReplaceAll, @@ -50,13 +47,11 @@ TypeError, NumberParseInt, RegExp, - RegExpPrototype, RegExpPrototypeTest, RegExpPrototypeToString, - SetPrototype, + Set, SetPrototypeEntries, Symbol, - SymbolPrototype, SymbolPrototypeToString, SymbolPrototypeValueOf, SymbolToStringTag, @@ -78,7 +73,6 @@ ArrayPrototypeFind, FunctionPrototypeBind, Map, - MapPrototype, MapPrototypeHas, MapPrototypeGet, MapPrototypeSet, @@ -86,7 +80,6 @@ MapPrototypeEntries, MapPrototypeForEach, Error, - ErrorPrototype, ErrorCaptureStackTrace, MathAbs, MathMax, @@ -95,17 +88,16 @@ MathRound, MathFloor, Number, - NumberPrototype, NumberPrototypeToString, NumberPrototypeValueOf, - BigIntPrototype, + BigInt, BigIntPrototypeToString, Proxy, ReflectGet, ReflectGetOwnPropertyDescriptor, ReflectGetPrototypeOf, - WeakMapPrototype, - WeakSetPrototype, + WeakMap, + WeakSet, } = window.__bootstrap.primordials; function isInvalidDate(x) { @@ -134,8 +126,7 @@ // Forked from Node's lib/internal/cli_table.js function isTypedArray(x) { - return ArrayBufferIsView(x) && - !ObjectPrototypeIsPrototypeOf(DataViewPrototype, x); + return ArrayBufferIsView(x) && !(x instanceof DataView); } const tableChars = { @@ -897,8 +888,7 @@ let err = value; while ( - ObjectPrototypeIsPrototypeOf(ErrorPrototype, err.cause) && - err.cause !== value && + err.cause instanceof Error && err.cause !== value && !ArrayPrototypeIncludes(causes, err.cause) // circular check ) { ArrayPrototypePush(causes, err.cause); @@ -1170,33 +1160,33 @@ // namespace is always enabled. return String(value[privateCustomInspect](inspect)); } - if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, value)) { + if (value instanceof Error) { return inspectError(value); } else if (ArrayIsArray(value)) { return inspectArray(value, level, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(NumberPrototype, value)) { + } else if (value instanceof Number) { return inspectNumberObject(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(BigIntPrototype, value)) { + } else if (value instanceof BigInt) { return inspectBigIntObject(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(BooleanPrototype, value)) { + } else if (value instanceof Boolean) { return inspectBooleanObject(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(StringPrototype, value)) { + } else if (value instanceof String) { return inspectStringObject(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(SymbolPrototype, value)) { + } else if (value instanceof Symbol) { return inspectSymbolObject(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(PromisePrototype, value)) { + } else if (value instanceof Promise) { return inspectPromise(value, level, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(RegExpPrototype, value)) { + } else if (value instanceof RegExp) { return inspectRegExp(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) { + } else if (value instanceof Date) { return inspectDate(value, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(SetPrototype, value)) { + } else if (value instanceof Set) { return inspectSet(value, level, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(MapPrototype, value)) { + } else if (value instanceof Map) { return inspectMap(value, level, inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(WeakSetPrototype, value)) { + } else if (value instanceof WeakSet) { return inspectWeakSet(inspectOptions); - } else if (ObjectPrototypeIsPrototypeOf(WeakMapPrototype, value)) { + } else if (value instanceof WeakMap) { return inspectWeakMap(inspectOptions); } else if (isTypedArray(value)) { return inspectTypedArray( @@ -1921,14 +1911,14 @@ const toTable = (header, body) => this.log(cliTable(header, body)); let resultData; - const isSet = ObjectPrototypeIsPrototypeOf(SetPrototype, data); - const isMap = ObjectPrototypeIsPrototypeOf(MapPrototype, data); + const isSet = data instanceof Set; + const isMap = data instanceof Map; const valuesKey = "Values"; const indexKey = isSet || isMap ? "(iter idx)" : "(idx)"; - if (isSet) { + if (data instanceof Set) { resultData = [...data]; - } else if (isMap) { + } else if (data instanceof Map) { let idx = 0; resultData = {}; diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index 5a42efbfd0..aa328d1d70 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -15,20 +15,18 @@ const { TextEncoder, TextDecoder } = window.__bootstrap.encoding; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypeEvery, ArrayPrototypeFind, ArrayPrototypeIncludes, - BigInt64ArrayPrototype, - BigUint64ArrayPrototype, - Int16ArrayPrototype, - Int32ArrayPrototype, - Int8ArrayPrototype, + BigInt64Array, + Int16Array, + Int32Array, + Int8Array, JSONParse, JSONStringify, ObjectAssign, - ObjectPrototypeIsPrototypeOf, StringPrototypeToLowerCase, StringPrototypeToUpperCase, Symbol, @@ -36,11 +34,10 @@ SyntaxError, TypedArrayPrototypeSlice, TypeError, - Uint16ArrayPrototype, - Uint32ArrayPrototype, + Uint16Array, + Uint32Array, Uint8Array, - Uint8ArrayPrototype, - Uint8ClampedArrayPrototype, + Uint8ClampedArray, WeakMap, WeakMapPrototypeGet, WeakMapPrototypeSet, @@ -289,26 +286,26 @@ /** @returns {string} */ get type() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); return this[_type]; } /** @returns {boolean} */ get extractable() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); return this[_extractable]; } /** @returns {string[]} */ get usages() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); // TODO(lucacasonato): return a SameObject copy return this[_usages]; } /** @returns {object} */ get algorithm() { - webidl.assertBranded(this, CryptoKeyPrototype); + webidl.assertBranded(this, CryptoKey); // TODO(lucacasonato): return a SameObject copy return this[_algorithm]; } @@ -326,7 +323,6 @@ } webidl.configurePrototype(CryptoKey); - const CryptoKeyPrototype = CryptoKey.prototype; /** * @param {string} type @@ -433,7 +429,7 @@ * @returns {Promise} */ async digest(algorithm, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'digest' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 2, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -465,7 +461,7 @@ * @returns {Promise} */ async encrypt(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'encrypt' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -513,7 +509,7 @@ * @returns {Promise} */ async decrypt(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'decrypt' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -709,7 +705,7 @@ * @returns {Promise} */ async sign(algorithm, key, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'sign' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -841,7 +837,7 @@ */ // deno-lint-ignore require-await async importKey(format, keyData, algorithm, extractable, keyUsages) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -867,19 +863,13 @@ // 2. if (format !== "jwk") { - if ( - ArrayBufferIsView(keyData) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, keyData) - ) { + if (ArrayBufferIsView(keyData) || keyData instanceof ArrayBuffer) { keyData = copyBuffer(keyData); } else { throw new TypeError("keyData is a JsonWebKey"); } } else { - if ( - ArrayBufferIsView(keyData) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, keyData) - ) { + if (ArrayBufferIsView(keyData) || keyData instanceof ArrayBuffer) { throw new TypeError("keyData is not a JsonWebKey"); } } @@ -959,7 +949,7 @@ */ // deno-lint-ignore require-await async exportKey(format, key) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'exportKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 2, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1009,7 +999,7 @@ * @returns {Promise} */ async deriveBits(algorithm, baseKey, length) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'deriveBits' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1057,7 +1047,7 @@ extractable, keyUsages, ) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'deriveKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 5, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1152,7 +1142,7 @@ * @returns {Promise} */ async verify(algorithm, key, signature, data) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'verify' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1273,7 +1263,7 @@ * @returns {Promise} */ async wrapKey(format, key, wrappingKey, wrapAlgorithm) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'wrapKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 4, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1406,7 +1396,7 @@ extractable, keyUsages, ) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'unwrapKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 7, { prefix }); format = webidl.converters.KeyFormat(format, { @@ -1564,7 +1554,7 @@ * @returns {Promise} */ async generateKey(algorithm, extractable, keyUsages) { - webidl.assertBranded(this, SubtleCryptoPrototype); + webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'generateKey' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 3, { prefix }); algorithm = webidl.converters.AlgorithmIdentifier(algorithm, { @@ -1590,14 +1580,12 @@ usages, ); - if (ObjectPrototypeIsPrototypeOf(CryptoKeyPrototype, result)) { + if (result instanceof CryptoKey) { const type = result[_type]; if ((type === "secret" || type === "private") && usages.length === 0) { throw new DOMException("Invalid key usages", "SyntaxError"); } - } else if ( - ObjectPrototypeIsPrototypeOf(CryptoKeyPrototype, result.privateKey) - ) { + } else if (result.privateKey instanceof CryptoKey) { if (result.privateKey[_usages].length === 0) { throw new DOMException("Invalid key usages", "SyntaxError"); } @@ -1606,7 +1594,6 @@ return result; } } - const SubtleCryptoPrototype = SubtleCrypto.prototype; async function generateKey(normalizedAlgorithm, extractable, usages) { const algorithmName = normalizedAlgorithm.name; @@ -3839,7 +3826,7 @@ } getRandomValues(arrayBufferView) { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); const prefix = "Failed to execute 'getRandomValues' on 'Crypto'"; webidl.requiredArguments(arguments.length, 1, { prefix }); arrayBufferView = webidl.converters.ArrayBufferView(arrayBufferView, { @@ -3848,21 +3835,15 @@ }); if ( !( - ObjectPrototypeIsPrototypeOf(Int8ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf( - Uint8ClampedArrayPrototype, - arrayBufferView, - ) || - ObjectPrototypeIsPrototypeOf(Int16ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint16ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Int32ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf(Uint32ArrayPrototype, arrayBufferView) || - ObjectPrototypeIsPrototypeOf( - BigInt64ArrayPrototype, - arrayBufferView, - ) || - ObjectPrototypeIsPrototypeOf(BigUint64ArrayPrototype, arrayBufferView) + arrayBufferView instanceof Int8Array || + arrayBufferView instanceof Uint8Array || + arrayBufferView instanceof Uint8ClampedArray || + arrayBufferView instanceof Int16Array || + arrayBufferView instanceof Uint16Array || + arrayBufferView instanceof Int32Array || + arrayBufferView instanceof Uint32Array || + arrayBufferView instanceof BigInt64Array || + arrayBufferView instanceof BigUint64Array ) ) { throw new DOMException( @@ -3880,12 +3861,12 @@ } randomUUID() { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); return core.opSync("op_crypto_random_uuid"); } get subtle() { - webidl.assertBranded(this, CryptoPrototype); + webidl.assertBranded(this, Crypto); return subtle; } @@ -3895,7 +3876,6 @@ } webidl.configurePrototype(Crypto); - const CryptoPrototype = Crypto.prototype; window.__bootstrap.crypto = { SubtleCrypto, diff --git a/ext/crypto/01_webidl.js b/ext/crypto/01_webidl.js index 7396487668..67156ce3a6 100644 --- a/ext/crypto/01_webidl.js +++ b/ext/crypto/01_webidl.js @@ -9,11 +9,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; const { CryptoKey } = window.__bootstrap.crypto; - const { - ArrayBufferIsView, - ArrayBufferPrototype, - ObjectPrototypeIsPrototypeOf, - } = window.__bootstrap.primordials; + const { ArrayBufferIsView, ArrayBuffer } = window.__bootstrap.primordials; webidl.converters.AlgorithmIdentifier = (V, opts) => { // Union for (object or DOMString) @@ -25,10 +21,7 @@ webidl.converters["BufferSource or JsonWebKey"] = (V, opts) => { // Union for (BufferSource or JsonWebKey) - if ( - ArrayBufferIsView(V) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) - ) { + if (ArrayBufferIsView(V) || V instanceof ArrayBuffer) { return webidl.converters.BufferSource(V, opts); } return webidl.converters.JsonWebKey(V, opts); @@ -467,7 +460,7 @@ webidl.converters.CryptoKey = webidl.createInterfaceConverter( "CryptoKey", - CryptoKey.prototype, + CryptoKey, ); const dictCryptoKeyPair = [ diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index 94f68df420..b1299fb1ba 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -263,7 +263,7 @@ * @param {string} value */ append(name, value) { - webidl.assertBranded(this, HeadersPrototype); + webidl.assertBranded(this, Headers); const prefix = "Failed to execute 'append' on 'Headers'"; webidl.requiredArguments(arguments.length, 2, { prefix }); name = webidl.converters["ByteString"](name, { @@ -354,7 +354,7 @@ * @param {string} value */ set(name, value) { - webidl.assertBranded(this, HeadersPrototype); + webidl.assertBranded(this, Headers); const prefix = "Failed to execute 'set' on 'Headers'"; webidl.requiredArguments(arguments.length, 2, { prefix }); name = webidl.converters["ByteString"](name, { @@ -411,7 +411,6 @@ webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1); webidl.configurePrototype(Headers); - const HeadersPrototype = Headers.prototype; webidl.converters["HeadersInit"] = (V, opts) => { // Union for (sequence> or record) @@ -429,7 +428,7 @@ }; webidl.converters["Headers"] = webidl.createInterfaceConverter( "Headers", - Headers.prototype, + Headers, ); /** diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js index a134fe5f73..cc338de729 100644 --- a/ext/fetch/21_formdata.js +++ b/ext/fetch/21_formdata.js @@ -13,8 +13,7 @@ ((window) => { const core = window.Deno.core; const webidl = globalThis.__bootstrap.webidl; - const { Blob, BlobPrototype, File, FilePrototype } = - globalThis.__bootstrap.file; + const { Blob, File } = globalThis.__bootstrap.file; const { ArrayPrototypeMap, ArrayPrototypePush, @@ -26,7 +25,6 @@ MapPrototypeGet, MapPrototypeSet, MathRandom, - ObjectPrototypeIsPrototypeOf, Symbol, StringFromCharCode, StringPrototypeTrim, @@ -50,16 +48,10 @@ * @returns {FormDataEntry} */ function createEntry(name, value, filename) { - if ( - ObjectPrototypeIsPrototypeOf(BlobPrototype, value) && - !ObjectPrototypeIsPrototypeOf(FilePrototype, value) - ) { + if (value instanceof Blob && !(value instanceof File)) { value = new File([value], "blob", { type: value.type }); } - if ( - ObjectPrototypeIsPrototypeOf(FilePrototype, value) && - filename !== undefined - ) { + if (value instanceof File && filename !== undefined) { value = new File([value], filename, { type: value.type, lastModified: value.lastModified, @@ -97,7 +89,7 @@ * @returns {void} */ append(name, valueOrBlobValue, filename) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'append' on 'FormData'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -105,7 +97,7 @@ prefix, context: "Argument 1", }); - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) { + if (valueOrBlobValue instanceof Blob) { valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, { prefix, context: "Argument 2", @@ -133,7 +125,7 @@ * @returns {void} */ delete(name) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'name' on 'FormData'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -156,7 +148,7 @@ * @returns {FormDataEntryValue | null} */ get(name) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'get' on 'FormData'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -176,7 +168,7 @@ * @returns {FormDataEntryValue[]} */ getAll(name) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'getAll' on 'FormData'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -197,7 +189,7 @@ * @returns {boolean} */ has(name) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'has' on 'FormData'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -219,7 +211,7 @@ * @returns {void} */ set(name, valueOrBlobValue, filename) { - webidl.assertBranded(this, FormDataPrototype); + webidl.assertBranded(this, FormData); const prefix = "Failed to execute 'set' on 'FormData'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -227,7 +219,7 @@ prefix, context: "Argument 1", }); - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, valueOrBlobValue)) { + if (valueOrBlobValue instanceof Blob) { valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, { prefix, context: "Argument 2", @@ -269,7 +261,6 @@ webidl.mixinPairIterable("FormData", FormData, entryList, "name", "value"); webidl.configurePrototype(FormData); - const FormDataPrototype = FormData.prototype; const escape = (str, isFilename) => StringPrototypeReplace( @@ -500,11 +491,10 @@ } webidl.converters["FormData"] = webidl - .createInterfaceConverter("FormData", FormDataPrototype); + .createInterfaceConverter("FormData", FormData); globalThis.__bootstrap.formData = { FormData, - FormDataPrototype, formDataToBlob, parseFormData, formDataFromEntries, diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index f33097033f..acfd06b0f7 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -16,35 +16,23 @@ const core = window.Deno.core; const webidl = globalThis.__bootstrap.webidl; const { parseUrlEncoded } = globalThis.__bootstrap.url; - const { URLSearchParamsPrototype } = globalThis.__bootstrap.url; - const { - parseFormData, - formDataFromEntries, - formDataToBlob, - FormDataPrototype, - } = globalThis.__bootstrap.formData; + const { parseFormData, formDataFromEntries, formDataToBlob } = + globalThis.__bootstrap.formData; const mimesniff = globalThis.__bootstrap.mimesniff; - const { BlobPrototype } = globalThis.__bootstrap.file; + const { isReadableStreamDisturbed, errorReadableStream, createProxy } = + globalThis.__bootstrap.streams; const { - isReadableStreamDisturbed, - errorReadableStream, - createProxy, - ReadableStreamPrototype, - } = globalThis.__bootstrap.streams; - const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypePush, ArrayPrototypeMap, JSONParse, ObjectDefineProperties, - ObjectPrototypeIsPrototypeOf, PromiseResolve, TypedArrayPrototypeSet, TypedArrayPrototypeSlice, TypeError, Uint8Array, - Uint8ArrayPrototype, } = window.__bootstrap.primordials; /** @@ -78,12 +66,7 @@ } get stream() { - if ( - !ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (!(this.streamOrStatic instanceof ReadableStream)) { const { body, consumed } = this.streamOrStatic; if (consumed) { this.streamOrStatic = new ReadableStream(); @@ -105,12 +88,7 @@ * @returns {boolean} */ unusable() { - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { return this.streamOrStatic.locked || isReadableStreamDisturbed(this.streamOrStatic); } @@ -121,12 +99,7 @@ * @returns {boolean} */ consumed() { - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { return isReadableStreamDisturbed(this.streamOrStatic); } return this.streamOrStatic.consumed; @@ -138,12 +111,7 @@ */ async consume() { if (this.unusable()) throw new TypeError("Body already consumed."); - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { const reader = this.stream.getReader(); /** @type {Uint8Array[]} */ const chunks = []; @@ -168,12 +136,7 @@ } cancel(error) { - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { this.streamOrStatic.cancel(error); } else { this.streamOrStatic.consumed = true; @@ -181,12 +144,7 @@ } error(error) { - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { errorReadableStream(this.streamOrStatic, error); } else { this.streamOrStatic.consumed = true; @@ -210,12 +168,7 @@ */ createProxy() { let proxyStreamOrStatic; - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - this.streamOrStatic, - ) - ) { + if (this.streamOrStatic instanceof ReadableStream) { proxyStreamOrStatic = createProxy(this.streamOrStatic); } else { proxyStreamOrStatic = { ...this.streamOrStatic }; @@ -329,7 +282,7 @@ enumerable: true, }, }; - return ObjectDefineProperties(prototype, mixin); + return ObjectDefineProperties(prototype.prototype, mixin); } /** @@ -388,21 +341,18 @@ let source = null; let length = null; let contentType = null; - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, object)) { + if (object instanceof Blob) { stream = object.stream(); source = object; length = object.size; if (object.type.length !== 0) { contentType = object.type; } - } else if (ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, object)) { + } else if (object instanceof Uint8Array) { // Fast(er) path for common case of Uint8Array const copy = TypedArrayPrototypeSlice(object, 0, object.byteLength); source = copy; - } else if ( - ArrayBufferIsView(object) || - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, object) - ) { + } else if (ArrayBufferIsView(object) || object instanceof ArrayBuffer) { const u8 = ArrayBufferIsView(object) ? new Uint8Array( object.buffer, @@ -412,28 +362,26 @@ : new Uint8Array(object); const copy = TypedArrayPrototypeSlice(u8, 0, u8.byteLength); source = copy; - } else if (ObjectPrototypeIsPrototypeOf(FormDataPrototype, object)) { + } else if (object instanceof FormData) { const res = formDataToBlob(object); stream = res.stream(); source = res; length = res.size; contentType = res.type; - } else if ( - ObjectPrototypeIsPrototypeOf(URLSearchParamsPrototype, object) - ) { + } else if (object instanceof URLSearchParams) { // TODO(@satyarohith): not sure what primordial here. source = object.toString(); contentType = "application/x-www-form-urlencoded;charset=UTF-8"; } else if (typeof object === "string") { source = object; contentType = "text/plain;charset=UTF-8"; - } else if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, object)) { + } else if (object instanceof ReadableStream) { stream = object; if (object.locked || isReadableStreamDisturbed(object)) { throw new TypeError("ReadableStream is locked or disturbed"); } } - if (ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, source)) { + if (source instanceof Uint8Array) { stream = { body: source, consumed: false }; length = source.byteLength; } else if (typeof source === "string") { @@ -451,22 +399,19 @@ webidl.converters["BodyInit_DOMString"] = (V, opts) => { // Union for (ReadableStream or Blob or ArrayBufferView or ArrayBuffer or FormData or URLSearchParams or USVString) - if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, V)) { + if (V instanceof ReadableStream) { // TODO(lucacasonato): ReadableStream is not branded return V; - } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { + } else if (V instanceof Blob) { return webidl.converters["Blob"](V, opts); - } else if (ObjectPrototypeIsPrototypeOf(FormDataPrototype, V)) { + } else if (V instanceof FormData) { return webidl.converters["FormData"](V, opts); - } else if (ObjectPrototypeIsPrototypeOf(URLSearchParamsPrototype, V)) { + } else if (V instanceof URLSearchParams) { // TODO(lucacasonato): URLSearchParams is not branded return V; } if (typeof V === "object") { - if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) - ) { + if (V instanceof ArrayBuffer || V instanceof SharedArrayBuffer) { return webidl.converters["ArrayBuffer"](V, opts); } if (ArrayBufferIsView(V)) { diff --git a/ext/fetch/22_http_client.js b/ext/fetch/22_http_client.js index 15690b7d4a..44159de07b 100644 --- a/ext/fetch/22_http_client.js +++ b/ext/fetch/22_http_client.js @@ -34,10 +34,8 @@ core.close(this.rid); } } - const HttpClientPrototype = HttpClient.prototype; window.__bootstrap.fetch ??= {}; window.__bootstrap.fetch.createHttpClient = createHttpClient; window.__bootstrap.fetch.HttpClient = HttpClient; - window.__bootstrap.fetch.HttpClientPrototype = HttpClientPrototype; })(globalThis); diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index 5294009ffb..5783cac9e4 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -26,7 +26,7 @@ fillHeaders, getDecodeSplitHeader, } = window.__bootstrap.headers; - const { HttpClientPrototype } = window.__bootstrap.fetch; + const { HttpClient } = window.__bootstrap.fetch; const abortSignal = window.__bootstrap.abortSignal; const { ArrayPrototypeMap, @@ -36,7 +36,6 @@ MapPrototypeGet, MapPrototypeSet, ObjectKeys, - ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, Symbol, SymbolFor, @@ -242,9 +241,7 @@ const parsedURL = new URL(input, baseURL); request = newInnerRequest("GET", parsedURL.href, [], null, true); } else { // 6. - if (!ObjectPrototypeIsPrototypeOf(RequestPrototype, input)) { - throw new TypeError("Unreachable"); - } + if (!(input instanceof Request)) throw new TypeError("Unreachable"); request = input[_request]; signal = input[_signal]; } @@ -271,10 +268,7 @@ // NOTE: non standard extension. This handles Deno.HttpClient parameter if (init.client !== undefined) { - if ( - init.client !== null && - !ObjectPrototypeIsPrototypeOf(HttpClientPrototype, init.client) - ) { + if (init.client !== null && !(init.client instanceof HttpClient)) { throw webidl.makeException( TypeError, "`client` must be a Deno.HttpClient", @@ -318,7 +312,7 @@ // 33. let inputBody = null; - if (ObjectPrototypeIsPrototypeOf(RequestPrototype, input)) { + if (input instanceof Request) { inputBody = input[_body]; } @@ -362,32 +356,32 @@ } get method() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); return this[_request].method; } get url() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); return this[_request].url(); } get headers() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); return this[_headers]; } get redirect() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); return this[_request].redirectMode; } get signal() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); return this[_signal]; } clone() { - webidl.assertBranded(this, RequestPrototype); + webidl.assertBranded(this, Request); if (this[_body] && this[_body].unusable()) { throw new TypeError("Body is unusable."); } @@ -404,7 +398,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(RequestPrototype, this), + evaluate: this instanceof Request, keys: [ "bodyUsed", "headers", @@ -416,18 +410,18 @@ } } + mixinBody(Request, _body, _mimeType); + webidl.configurePrototype(Request); - const RequestPrototype = Request.prototype; - mixinBody(RequestPrototype, _body, _mimeType); webidl.converters["Request"] = webidl.createInterfaceConverter( "Request", - RequestPrototype, + Request, ); webidl.converters["RequestInfo_DOMString"] = (V, opts) => { // Union for (Request or USVString) if (typeof V == "object") { - if (ObjectPrototypeIsPrototypeOf(RequestPrototype, V)) { + if (V instanceof Request) { return webidl.converters["Request"](V, opts); } } diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js index 14aadbaf24..e7b2054185 100644 --- a/ext/fetch/23_response.js +++ b/ext/fetch/23_response.js @@ -33,7 +33,6 @@ MapPrototypeHas, MapPrototypeGet, MapPrototypeSet, - ObjectPrototypeIsPrototypeOf, RangeError, RegExp, RegExpPrototypeTest, @@ -298,7 +297,7 @@ * @returns {"basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"} */ get type() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); return this[_response].type; } @@ -306,7 +305,7 @@ * @returns {string} */ get url() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); const url = this[_response].url(); if (url === null) return ""; const newUrl = new URL(url); @@ -318,7 +317,7 @@ * @returns {boolean} */ get redirected() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); return this[_response].urlList.length > 1; } @@ -326,7 +325,7 @@ * @returns {number} */ get status() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); return this[_response].status; } @@ -334,7 +333,7 @@ * @returns {boolean} */ get ok() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); const status = this[_response].status; return status >= 200 && status <= 299; } @@ -343,7 +342,7 @@ * @returns {string} */ get statusText() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); return this[_response].statusMessage; } @@ -351,7 +350,7 @@ * @returns {Headers} */ get headers() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); return this[_headers]; } @@ -359,7 +358,7 @@ * @returns {Response} */ clone() { - webidl.assertBranded(this, ResponsePrototype); + webidl.assertBranded(this, Response); if (this[_body] && this[_body].unusable()) { throw new TypeError("Body is unusable."); } @@ -376,7 +375,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(ResponsePrototype, this), + evaluate: this instanceof Response, keys: [ "body", "bodyUsed", @@ -391,13 +390,13 @@ } } + mixinBody(Response, _body, _mimeType); + webidl.configurePrototype(Response); - const ResponsePrototype = Response.prototype; - mixinBody(ResponsePrototype, _body, _mimeType); webidl.converters["Response"] = webidl.createInterfaceConverter( "Response", - ResponsePrototype, + Response, ); webidl.converters["ResponseInit"] = webidl.createDictionaryConverter( "ResponseInit", @@ -458,7 +457,6 @@ window.__bootstrap.fetch ??= {}; window.__bootstrap.fetch.Response = Response; - window.__bootstrap.fetch.ResponsePrototype = ResponsePrototype; window.__bootstrap.fetch.newInnerResponse = newInnerResponse; window.__bootstrap.fetch.toInnerResponse = toInnerResponse; window.__bootstrap.fetch.fromInnerResponse = fromInnerResponse; diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js index 0c58bbf97f..c6fc9197b2 100644 --- a/ext/fetch/26_fetch.js +++ b/ext/fetch/26_fetch.js @@ -15,9 +15,7 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { byteLowerCase } = window.__bootstrap.infra; - const { BlobPrototype } = window.__bootstrap.file; - const { errorReadableStream, ReadableStreamPrototype } = - window.__bootstrap.streams; + const { errorReadableStream } = window.__bootstrap.streams; const { InnerBody, extractBody } = window.__bootstrap.fetchBody; const { toInnerRequest, @@ -34,7 +32,6 @@ ArrayPrototypeSplice, ArrayPrototypeFilter, ArrayPrototypeIncludes, - ObjectPrototypeIsPrototypeOf, Promise, PromisePrototypeThen, PromisePrototypeCatch, @@ -44,7 +41,6 @@ TypedArrayPrototypeSubarray, TypeError, Uint8Array, - Uint8ArrayPrototype, WeakMap, WeakMapPrototypeDelete, WeakMapPrototypeGet, @@ -176,16 +172,8 @@ let reqBody = null; if (req.body !== null) { - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - req.body.streamOrStatic, - ) - ) { - if ( - req.body.length === null || - ObjectPrototypeIsPrototypeOf(BlobPrototype, req.body.source) - ) { + if (req.body.streamOrStatic instanceof ReadableStream) { + if (req.body.length === null || req.body.source instanceof Blob) { reqBody = req.body.stream; } else { const reader = req.body.stream.getReader(); @@ -208,19 +196,14 @@ } } - const { requestRid, requestBodyRid, cancelHandleRid } = opFetch( - { - method: req.method, - url: req.currentUrl(), - headers: req.headerList, - clientRid: req.clientRid, - hasBody: reqBody !== null, - bodyLength: req.body?.length, - }, - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, reqBody) - ? reqBody - : null, - ); + const { requestRid, requestBodyRid, cancelHandleRid } = opFetch({ + method: req.method, + url: req.currentUrl(), + headers: req.headerList, + clientRid: req.clientRid, + hasBody: reqBody !== null, + bodyLength: req.body?.length, + }, reqBody instanceof Uint8Array ? reqBody : null); function onAbort() { if (cancelHandleRid !== null) { @@ -233,10 +216,7 @@ terminator[abortSignal.add](onAbort); if (requestBodyRid !== null) { - if ( - reqBody === null || - !ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, reqBody) - ) { + if (reqBody === null || !(reqBody instanceof ReadableStream)) { throw new TypeError("Unreachable"); } const reader = reqBody.getReader(); @@ -251,7 +231,7 @@ }, ); if (done) break; - if (!ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, value)) { + if (!(value instanceof Uint8Array)) { await reader.cancel("value not a Uint8Array"); break; } diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index b979c73d42..abe806cc08 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -5,11 +5,10 @@ const core = window.Deno.core; const __bootstrap = window.__bootstrap; const { - ArrayBufferPrototype, + ArrayBuffer, Uint8Array, BigInt, Number, - ObjectPrototypeIsPrototypeOf, TypeError, } = window.__bootstrap.primordials; @@ -142,7 +141,6 @@ return this.value; } } - const UnsafePointerPrototype = UnsafePointer.prototype; function prepareArgs(types, args) { const parameters = []; @@ -154,12 +152,12 @@ if (type === "pointer") { if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, arg?.buffer) && + arg?.buffer instanceof ArrayBuffer && arg.byteLength !== undefined ) { parameters.push(buffers.length); buffers.push(arg); - } else if (ObjectPrototypeIsPrototypeOf(UnsafePointerPrototype, arg)) { + } else if (arg instanceof UnsafePointer) { parameters.push(packU64(arg.value)); buffers.push(undefined); } else if (arg === null) { diff --git a/ext/http/01_http.js b/ext/http/01_http.js index eae7429906..f04ba84948 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -5,9 +5,8 @@ const webidl = window.__bootstrap.webidl; const { InnerBody } = window.__bootstrap.fetchBody; const { setEventTargetData } = window.__bootstrap.eventTarget; - const { BlobPrototype } = window.__bootstrap.file; const { - ResponsePrototype, + Response, fromInnerRequest, toInnerResponse, newInnerRequest, @@ -15,9 +14,8 @@ fromInnerResponse, } = window.__bootstrap.fetch; const core = window.Deno.core; - const { BadResourcePrototype, InterruptedPrototype } = core; - const { ReadableStream, ReadableStreamPrototype } = - window.__bootstrap.streams; + const { BadResource, Interrupted } = core; + const { ReadableStream } = window.__bootstrap.streams; const abortSignal = window.__bootstrap.abortSignal; const { WebSocket, @@ -34,8 +32,7 @@ ArrayPrototypeIncludes, ArrayPrototypePush, ArrayPrototypeSome, - ObjectPrototypeIsPrototypeOf, - PromisePrototype, + Promise, Set, SetPrototypeAdd, SetPrototypeDelete, @@ -49,7 +46,6 @@ TypedArrayPrototypeSubarray, TypeError, Uint8Array, - Uint8ArrayPrototype, } = window.__bootstrap.primordials; const connErrorSymbol = Symbol("connError"); @@ -85,8 +81,8 @@ // those with it. this[connErrorSymbol] = error; if ( - ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error) || - ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error) || + error instanceof BadResource || + error instanceof Interrupted || StringPrototypeIncludes(error.message, "connection closed") ) { return null; @@ -162,11 +158,11 @@ function createRespondWith(httpConn, streamRid) { return async function respondWith(resp) { try { - if (ObjectPrototypeIsPrototypeOf(PromisePrototype, resp)) { + if (resp instanceof Promise) { resp = await resp; } - if (!(ObjectPrototypeIsPrototypeOf(ResponsePrototype, resp))) { + if (!(resp instanceof Response)) { throw new TypeError( "First argument to respondWith must be a Response or a promise resolving to a Response.", ); @@ -183,18 +179,10 @@ if (innerResp.body.unusable()) { throw new TypeError("Body is unusable."); } - if ( - ObjectPrototypeIsPrototypeOf( - ReadableStreamPrototype, - innerResp.body.streamOrStatic, - ) - ) { + if (innerResp.body.streamOrStatic instanceof ReadableStream) { if ( innerResp.body.length === null || - ObjectPrototypeIsPrototypeOf( - BlobPrototype, - innerResp.body.source, - ) + innerResp.body.source instanceof Blob ) { respBody = innerResp.body.stream; } else { @@ -216,8 +204,7 @@ respBody = new Uint8Array(0); } const isStreamingResponseBody = !( - typeof respBody === "string" || - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, respBody) + typeof respBody === "string" || respBody instanceof Uint8Array ); try { @@ -228,34 +215,25 @@ ); } catch (error) { const connError = httpConn[connErrorSymbol]; - if ( - ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error) && - connError != null - ) { + if (error instanceof BadResource && connError != null) { // deno-lint-ignore no-ex-assign error = new connError.constructor(connError.message); } - if ( - respBody !== null && - ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, respBody) - ) { + if (respBody !== null && respBody instanceof ReadableStream) { await respBody.cancel(error); } throw error; } if (isStreamingResponseBody) { - if ( - respBody === null || - !ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, respBody) - ) { + if (respBody === null || !(respBody instanceof ReadableStream)) { throw new TypeError("Unreachable"); } const reader = respBody.getReader(); while (true) { const { value, done } = await reader.read(); if (done) break; - if (!ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, value)) { + if (!(value instanceof Uint8Array)) { await reader.cancel(new TypeError("Value not a Uint8Array")); break; } @@ -263,10 +241,7 @@ await core.opAsync("op_http_write", streamRid, value); } catch (error) { const connError = httpConn[connErrorSymbol]; - if ( - ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error) && - connError != null - ) { + if (error instanceof BadResource && connError != null) { // deno-lint-ignore no-ex-assign error = new connError.constructor(connError.message); } diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 145a89b4f3..4a4005954b 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -3,9 +3,8 @@ ((window) => { const core = window.Deno.core; - const { BadResourcePrototype, InterruptedPrototype } = core; + const { BadResource, Interrupted } = core; const { - ObjectPrototypeIsPrototypeOf, PromiseResolve, SymbolAsyncIterator, Uint8Array, @@ -125,10 +124,7 @@ try { conn = await this.accept(); } catch (error) { - if ( - ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error) || - ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error) - ) { + if (error instanceof BadResource || error instanceof Interrupted) { return { value: undefined, done: true }; } throw error; @@ -195,10 +191,7 @@ try { yield await this.receive(); } catch (err) { - if ( - ObjectPrototypeIsPrototypeOf(BadResourcePrototype, err) || - ObjectPrototypeIsPrototypeOf(InterruptedPrototype, err) - ) { + if (err instanceof BadResource || err instanceof Interrupted) { break; } throw err; diff --git a/ext/timers/01_timers.js b/ext/timers/01_timers.js index caa490e614..6ef2e6654a 100644 --- a/ext/timers/01_timers.js +++ b/ext/timers/01_timers.js @@ -16,7 +16,6 @@ // deno-lint-ignore camelcase NumberPOSITIVE_INFINITY, PromisePrototypeThen, - ObjectPrototypeIsPrototypeOf, SymbolFor, TypeError, } = window.__bootstrap.primordials; @@ -288,7 +287,7 @@ } }, (err) => { - if (ObjectPrototypeIsPrototypeOf(core.InterruptedPrototype, err)) { + if (err instanceof core.Interrupted) { // The timer was cancelled. removeFromScheduledTimers(timerObject); } else { diff --git a/ext/timers/02_performance.js b/ext/timers/02_performance.js index c48a3d8882..ce04c8dccc 100644 --- a/ext/timers/02_performance.js +++ b/ext/timers/02_performance.js @@ -9,7 +9,6 @@ ArrayPrototypeReverse, ArrayPrototypeSlice, ObjectKeys, - ObjectPrototypeIsPrototypeOf, Symbol, SymbolFor, TypeError, @@ -128,22 +127,22 @@ [_duration] = 0; get name() { - webidl.assertBranded(this, PerformanceEntryPrototype); + webidl.assertBranded(this, PerformanceEntry); return this[_name]; } get entryType() { - webidl.assertBranded(this, PerformanceEntryPrototype); + webidl.assertBranded(this, PerformanceEntry); return this[_entryType]; } get startTime() { - webidl.assertBranded(this, PerformanceEntryPrototype); + webidl.assertBranded(this, PerformanceEntry); return this[_startTime]; } get duration() { - webidl.assertBranded(this, PerformanceEntryPrototype); + webidl.assertBranded(this, PerformanceEntry); return this[_duration]; } @@ -166,7 +165,7 @@ } toJSON() { - webidl.assertBranded(this, PerformanceEntryPrototype); + webidl.assertBranded(this, PerformanceEntry); return { name: this[_name], entryType: this[_entryType], @@ -178,10 +177,7 @@ [customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - PerformanceEntryPrototype, - this, - ), + evaluate: this instanceof PerformanceEntry, keys: [ "name", "entryType", @@ -192,19 +188,18 @@ } } webidl.configurePrototype(PerformanceEntry); - const PerformanceEntryPrototype = PerformanceEntry.prototype; const _detail = Symbol("[[detail]]"); class PerformanceMark extends PerformanceEntry { [_detail] = null; get detail() { - webidl.assertBranded(this, PerformanceMarkPrototype); + webidl.assertBranded(this, PerformanceMark); return this[_detail]; } get entryType() { - webidl.assertBranded(this, PerformanceMarkPrototype); + webidl.assertBranded(this, PerformanceMark); return "mark"; } @@ -236,7 +231,7 @@ } toJSON() { - webidl.assertBranded(this, PerformanceMarkPrototype); + webidl.assertBranded(this, PerformanceMark); return { name: this.name, entryType: this.entryType, @@ -249,7 +244,7 @@ [customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(PerformanceMarkPrototype, this), + evaluate: this instanceof PerformanceMark, keys: [ "name", "entryType", @@ -261,17 +256,17 @@ } } webidl.configurePrototype(PerformanceMark); - const PerformanceMarkPrototype = PerformanceMark.prototype; + class PerformanceMeasure extends PerformanceEntry { [_detail] = null; get detail() { - webidl.assertBranded(this, PerformanceMeasurePrototype); + webidl.assertBranded(this, PerformanceMeasure); return this[_detail]; } get entryType() { - webidl.assertBranded(this, PerformanceMeasurePrototype); + webidl.assertBranded(this, PerformanceMeasure); return "measure"; } @@ -292,7 +287,7 @@ } toJSON() { - webidl.assertBranded(this, PerformanceMeasurePrototype); + webidl.assertBranded(this, PerformanceMeasure); return { name: this.name, entryType: this.entryType, @@ -305,10 +300,7 @@ [customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - PerformanceMeasurePrototype, - this, - ), + evaluate: this instanceof PerformanceMeasure, keys: [ "name", "entryType", @@ -320,14 +312,14 @@ } } webidl.configurePrototype(PerformanceMeasure); - const PerformanceMeasurePrototype = PerformanceMeasure.prototype; + class Performance { constructor() { webidl.illegalConstructor(); } clearMarks(markName = undefined) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); if (markName !== undefined) { markName = webidl.converters.DOMString(markName, { prefix: "Failed to execute 'clearMarks' on 'Performance'", @@ -347,7 +339,7 @@ } clearMeasures(measureName = undefined) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); if (measureName !== undefined) { measureName = webidl.converters.DOMString(measureName, { prefix: "Failed to execute 'clearMeasures' on 'Performance'", @@ -368,7 +360,7 @@ } getEntries() { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); return filterByNameType(); } @@ -376,7 +368,7 @@ name, type = undefined, ) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -396,7 +388,7 @@ } getEntriesByType(type) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); const prefix = "Failed to execute 'getEntriesByName' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -412,7 +404,7 @@ markName, markOptions = {}, ) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); const prefix = "Failed to execute 'mark' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -440,7 +432,7 @@ startOrMeasureOptions = {}, endMark = undefined, ) { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); const prefix = "Failed to execute 'measure' on 'Performance'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -539,25 +531,24 @@ } now() { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); return now(); } toJSON() { - webidl.assertBranded(this, PerformancePrototype); + webidl.assertBranded(this, Performance); return {}; } [customInspect](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(PerformancePrototype, this), + evaluate: this instanceof Performance, keys: [], })); } } webidl.configurePrototype(Performance); - const PerformancePrototype = Performance.prototype; window.__bootstrap.performance = { PerformanceEntry, diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 110890b7fa..4bba06ce15 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -134,7 +134,7 @@ * @param {string} value */ append(name, value) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'append' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 2, { prefix }); name = webidl.converters.USVString(name, { @@ -153,7 +153,7 @@ * @param {string} name */ delete(name) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'append' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, { prefix }); name = webidl.converters.USVString(name, { @@ -177,7 +177,7 @@ * @returns {string[]} */ getAll(name) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'getAll' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, { prefix }); name = webidl.converters.USVString(name, { @@ -198,7 +198,7 @@ * @return {string | null} */ get(name) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'get' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, { prefix }); name = webidl.converters.USVString(name, { @@ -218,7 +218,7 @@ * @return {boolean} */ has(name) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'has' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 1, { prefix }); name = webidl.converters.USVString(name, { @@ -233,7 +233,7 @@ * @param {string} value */ set(name, value) { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); const prefix = "Failed to execute 'set' on 'URLSearchParams'"; webidl.requiredArguments(arguments.length, 2, { prefix }); name = webidl.converters.USVString(name, { @@ -276,7 +276,7 @@ } sort() { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); ArrayPrototypeSort( this[_list], (a, b) => (a[0] === b[0] ? 0 : a[0] > b[0] ? 1 : -1), @@ -288,7 +288,7 @@ * @return {string} */ toString() { - webidl.assertBranded(this, URLSearchParamsPrototype); + webidl.assertBranded(this, URLSearchParams); return core.opSync("op_url_stringify_search_params", this[_list]); } } @@ -296,7 +296,6 @@ webidl.mixinPairIterable("URLSearchParams", URLSearchParams, _list, 0, 1); webidl.configurePrototype(URLSearchParams); - const URLSearchParamsPrototype = URLSearchParams.prototype; const _url = Symbol("url"); @@ -351,13 +350,13 @@ /** @return {string} */ get hash() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].hash; } /** @param {string} value */ set hash(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'hash' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -373,13 +372,13 @@ /** @return {string} */ get host() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].host; } /** @param {string} value */ set host(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'host' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -395,13 +394,13 @@ /** @return {string} */ get hostname() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].hostname; } /** @param {string} value */ set hostname(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'hostname' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -417,13 +416,13 @@ /** @return {string} */ get href() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].href; } /** @param {string} value */ set href(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'href' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -436,19 +435,19 @@ /** @return {string} */ get origin() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].origin; } /** @return {string} */ get password() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].password; } /** @param {string} value */ set password(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'password' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -464,13 +463,13 @@ /** @return {string} */ get pathname() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].pathname; } /** @param {string} value */ set pathname(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'pathname' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -486,13 +485,13 @@ /** @return {string} */ get port() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].port; } /** @param {string} value */ set port(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'port' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -508,13 +507,13 @@ /** @return {string} */ get protocol() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].protocol; } /** @param {string} value */ set protocol(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'protocol' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -530,13 +529,13 @@ /** @return {string} */ get search() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].search; } /** @param {string} value */ set search(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'search' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -553,13 +552,13 @@ /** @return {string} */ get username() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].username; } /** @param {string} value */ set username(value) { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); const prefix = "Failed to set 'username' on 'URL'"; webidl.requiredArguments(arguments.length, 1, { prefix }); value = webidl.converters.DOMString(value, { @@ -584,19 +583,18 @@ /** @return {string} */ toString() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].href; } /** @return {string} */ toJSON() { - webidl.assertBranded(this, URLPrototype); + webidl.assertBranded(this, URL); return this[_url].href; } } webidl.configurePrototype(URL); - const URLPrototype = URL.prototype; /** * This function implements application/x-www-form-urlencoded parsing. @@ -624,9 +622,7 @@ window.__bootstrap.url = { URL, - URLPrototype, URLSearchParams, - URLSearchParamsPrototype, parseUrlEncoded, }; })(this); diff --git a/ext/url/01_urlpattern.js b/ext/url/01_urlpattern.js index 51968e68a4..19883311f1 100644 --- a/ext/url/01_urlpattern.js +++ b/ext/url/01_urlpattern.js @@ -85,42 +85,42 @@ } get protocol() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].protocol.patternString; } get username() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].username.patternString; } get password() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].password.patternString; } get hostname() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].hostname.patternString; } get port() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].port.patternString; } get pathname() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].pathname.patternString; } get search() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].search.patternString; } get hash() { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); return this[_components].hash.patternString; } @@ -130,7 +130,7 @@ * @returns {boolean} */ test(input, baseURL = undefined) { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); const prefix = "Failed to execute 'test' on 'URLPattern'"; webidl.requiredArguments(arguments.length, 1, { prefix }); input = webidl.converters.URLPatternInput(input, { @@ -170,7 +170,7 @@ * @returns {URLPatternResult | null} */ exec(input, baseURL = undefined) { - webidl.assertBranded(this, URLPatternPrototype); + webidl.assertBranded(this, URLPattern); const prefix = "Failed to execute 'exec' on 'URLPattern'"; webidl.requiredArguments(arguments.length, 1, { prefix }); input = webidl.converters.URLPatternInput(input, { @@ -241,7 +241,6 @@ } webidl.configurePrototype(URLPattern); - const URLPatternPrototype = URLPattern.prototype; webidl.converters.URLPatternInit = webidl .createDictionaryConverter("URLPatternInit", [ diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index a3beb30642..44aa72abe1 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -16,7 +16,6 @@ ErrorPrototype, ObjectDefineProperty, ObjectEntries, - ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, SymbolFor, } = window.__bootstrap.primordials; @@ -127,7 +126,7 @@ } [SymbolFor("Deno.customInspect")](inspect) { - if (ObjectPrototypeIsPrototypeOf(DOMExceptionPrototype, this)) { + if (this instanceof DOMException) { return `DOMException: ${this.#message}`; } else { return inspect(consoleInternal.createFilteredInspectProxy({ @@ -146,7 +145,6 @@ ObjectSetPrototypeOf(DOMException.prototype, ErrorPrototype); webidl.configurePrototype(DOMException); - const DOMExceptionPrototype = DOMException.prototype; for ( const [key, value] of ObjectEntries({ diff --git a/ext/web/02_event.js b/ext/web/02_event.js index b32bb01b85..7ba5afa276 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -29,7 +29,6 @@ ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, - ObjectPrototypeIsPrototypeOf, ReflectDefineProperty, Symbol, SymbolFor, @@ -175,7 +174,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(Event.prototype, this), + evaluate: this instanceof Event, keys: EVENT_PROPS, })); } @@ -1059,7 +1058,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(ErrorEvent.prototype, this), + evaluate: this instanceof ErrorEvent, keys: [ ...EVENT_PROPS, "message", @@ -1120,7 +1119,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(CloseEvent.prototype, this), + evaluate: this instanceof CloseEvent, keys: [ ...EVENT_PROPS, "wasClean", @@ -1152,7 +1151,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(MessageEvent.prototype, this), + evaluate: this instanceof MessageEvent, keys: [ ...EVENT_PROPS, "data", @@ -1185,7 +1184,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(CustomEvent.prototype, this), + evaluate: this instanceof CustomEvent, keys: [ ...EVENT_PROPS, "detail", @@ -1215,7 +1214,7 @@ [SymbolFor("Deno.privateCustomInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(ProgressEvent.prototype, this), + evaluate: this instanceof ProgressEvent, keys: [ ...EVENT_PROPS, "lengthComputable", @@ -1239,8 +1238,7 @@ if ( isSpecialErrorEventHandler && - ObjectPrototypeIsPrototypeOf(ErrorEvent.prototype, evt) && - evt.type === "error" + evt instanceof ErrorEvent && evt.type === "error" ) { const ret = FunctionPrototypeCall( wrappedHandler.handler, diff --git a/ext/web/02_structured_clone.js b/ext/web/02_structured_clone.js index 058390cfee..005b668af8 100644 --- a/ext/web/02_structured_clone.js +++ b/ext/web/02_structured_clone.js @@ -13,12 +13,10 @@ const { DOMException } = window.__bootstrap.domException; const { ArrayBuffer, - ArrayBufferPrototype, ArrayBufferIsView, - DataViewPrototype, - ObjectPrototypeIsPrototypeOf, + DataView, TypedArrayPrototypeSlice, - TypeErrorPrototype, + TypeError, WeakMap, WeakMapPrototypeSet, } = window.__bootstrap.primordials; @@ -44,7 +42,7 @@ function structuredClone(value) { // Performance optimization for buffers, otherwise // `serialize/deserialize` will allocate new buffer. - if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, value)) { + if (value instanceof ArrayBuffer) { const cloned = cloneArrayBuffer( value, 0, @@ -61,7 +59,7 @@ // only DataView has a length in bytes and TypedArrays use a length in // terms of elements, so we adjust for that. let length; - if (ObjectPrototypeIsPrototypeOf(DataViewPrototype, view)) { + if (value instanceof DataView) { length = value.byteLength; } else { length = value.length; @@ -76,7 +74,7 @@ try { return core.deserialize(core.serialize(value)); } catch (e) { - if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) { + if (e instanceof TypeError) { throw new DOMException("Uncloneable value", "DataCloneError"); } throw e; diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index 8b089d0317..cd9b11d4bd 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -77,17 +77,17 @@ } get aborted() { - webidl.assertBranded(this, AbortSignalPrototype); + webidl.assertBranded(this, AbortSignal); return this[abortReason] !== undefined; } get reason() { - webidl.assertBranded(this, AbortSignalPrototype); + webidl.assertBranded(this, AbortSignal); return this[abortReason]; } throwIfAborted() { - webidl.assertBranded(this, AbortSignalPrototype); + webidl.assertBranded(this, AbortSignal); if (this[abortReason] !== undefined) { throw this[abortReason]; } @@ -96,7 +96,6 @@ defineEventHandler(AbortSignal.prototype, "abort"); webidl.configurePrototype(AbortSignal); - const AbortSignalPrototype = AbortSignal.prototype; class AbortController { [signal] = new AbortSignal(illegalConstructorKey); @@ -106,22 +105,21 @@ } get signal() { - webidl.assertBranded(this, AbortControllerPrototype); + webidl.assertBranded(this, AbortController); return this[signal]; } abort(reason) { - webidl.assertBranded(this, AbortControllerPrototype); + webidl.assertBranded(this, AbortController); this[signal][signalAbort](reason); } } webidl.configurePrototype(AbortController); - const AbortControllerPrototype = AbortController.prototype; webidl.converters["AbortSignal"] = webidl.createInterfaceConverter( "AbortSignal", - AbortSignal.prototype, + AbortSignal, ); function newSignal() { @@ -144,7 +142,6 @@ window.AbortSignal = AbortSignal; window.AbortController = AbortController; window.__bootstrap.abortSignal = { - AbortSignalPrototype, add, signalAbort, remove, diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 777ad152b7..d32a72c6e0 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -9,22 +9,21 @@ ((window) => { const webidl = window.__bootstrap.webidl; - const { add, remove, signalAbort, newSignal, AbortSignalPrototype } = + const { add, remove, signalAbort, newSignal } = window.__bootstrap.abortSignal; const { ArrayBuffer, - ArrayBufferPrototype, ArrayBufferIsView, ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeShift, - BigInt64ArrayPrototype, - BigUint64ArrayPrototype, + BigInt64Array, + BigUint64Array, DataView, Error, - Int8ArrayPrototype, - Int16ArrayPrototype, - Int32ArrayPrototype, + Int8Array, + Int16Array, + Int32Array, NumberIsInteger, NumberIsNaN, MathMin, @@ -32,7 +31,6 @@ ObjectDefineProperties, ObjectDefineProperty, ObjectGetPrototypeOf, - ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, Promise, PromiseAll, @@ -48,10 +46,9 @@ SymbolFor, TypeError, Uint8Array, - Uint8ArrayPrototype, - Uint16ArrayPrototype, - Uint32ArrayPrototype, - Uint8ClampedArrayPrototype, + Uint16Array, + Uint32Array, + Uint8ClampedArray, WeakMap, WeakMapPrototypeGet, WeakMapPrototypeHas, @@ -137,7 +134,7 @@ /** @param {any} e */ function rethrowAssertionErrorRejection(e) { - if (e && ObjectPrototypeIsPrototypeOf(AssertionError.prototype, e)) { + if (e && e instanceof AssertionError) { queueMicrotask(() => { console.error(`Internal Error: ${e.stack}`); }); @@ -217,10 +214,7 @@ */ function canTransferArrayBuffer(O) { assert(typeof O === "object"); - assert( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, O) || - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, O), - ); + assert(O instanceof ArrayBuffer || O instanceof SharedArrayBuffer); if (isDetachedBuffer(O)) { return false; } @@ -1370,15 +1364,15 @@ let ctor = DataView; if ( - ObjectPrototypeIsPrototypeOf(Int8ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Uint8ClampedArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Int16ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Uint16ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Int32ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(Uint32ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(BigInt64ArrayPrototype, view) || - ObjectPrototypeIsPrototypeOf(BigUint64ArrayPrototype, view) + view instanceof Int8Array || + view instanceof Uint8Array || + view instanceof Uint8ClampedArray || + view instanceof Int16Array || + view instanceof Uint16Array || + view instanceof Int32Array || + view instanceof Uint32Array || + view instanceof BigInt64Array || + view instanceof BigUint64Array ) { elementSize = view.constructor.BYTES_PER_ELEMENT; ctor = view.constructor; @@ -1989,10 +1983,7 @@ typeof preventClose === "boolean" && typeof preventAbort === "boolean" && typeof preventCancel === "boolean", ); - assert( - signal === undefined || - ObjectPrototypeIsPrototypeOf(AbortSignalPrototype, signal), - ); + assert(signal === undefined || signal instanceof AbortSignal); assert(!isReadableStreamLocked(source)); assert(!isWritableStreamLocked(dest)); // We use acquireReadableStreamDefaultReader even in case of ReadableByteStreamController @@ -2336,12 +2327,7 @@ function readableStreamTee(stream, cloneForBranch2) { assert(isReadableStream(stream)); assert(typeof cloneForBranch2 === "boolean"); - if ( - ObjectPrototypeIsPrototypeOf( - ReadableByteStreamControllerPrototype, - stream[_controller], - ) - ) { + if (stream[_controller] instanceof ReadableByteStreamController) { return readableByteStreamTee(stream); } else { return readableStreamDefaultTee(stream, cloneForBranch2); @@ -2505,12 +2491,7 @@ */ function readableByteStreamTee(stream) { assert(isReadableStream(stream)); - assert( - ObjectPrototypeIsPrototypeOf( - ReadableByteStreamControllerPrototype, - stream[_controller], - ), - ); + assert(stream[_controller] instanceof ReadableByteStreamController); let reader = acquireReadableStreamDefaultReader(stream); let reading = false; let readAgainForBranch1 = false; @@ -3018,12 +2999,7 @@ if (isReadableStreamLocked(stream)) { throw new TypeError("ReadableStream is locked."); } - if ( - !(ObjectPrototypeIsPrototypeOf( - ReadableByteStreamControllerPrototype, - stream[_controller], - )) - ) { + if (!(stream[_controller] instanceof ReadableByteStreamController)) { throw new TypeError("Cannot use a BYOB reader with a non-byte stream"); } readableStreamReaderGenericInitialize(reader, stream); @@ -3056,7 +3032,7 @@ transformAlgorithm, flushAlgorithm, ) { - assert(ObjectPrototypeIsPrototypeOf(TransformStreamPrototype, stream)); + assert(stream instanceof TransformStream); assert(stream[_controller] === undefined); controller[_stream] = stream; stream[_controller] = controller; @@ -4198,13 +4174,13 @@ /** @returns {number} */ get highWaterMark() { - webidl.assertBranded(this, ByteLengthQueuingStrategyPrototype); + webidl.assertBranded(this, ByteLengthQueuingStrategy); return this[_highWaterMark]; } /** @returns {(chunk: ArrayBufferView) => number} */ get size() { - webidl.assertBranded(this, ByteLengthQueuingStrategyPrototype); + webidl.assertBranded(this, ByteLengthQueuingStrategy); initializeByteLengthSizeFunction(this[_globalObject]); return WeakMapPrototypeGet(byteSizeFunctionWeakMap, this[_globalObject]); } @@ -4212,10 +4188,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - ByteLengthQueuingStrategyPrototype, - this, - ), + evaluate: this instanceof ByteLengthQueuingStrategy, keys: [ "highWaterMark", "size", @@ -4225,8 +4198,6 @@ } webidl.configurePrototype(ByteLengthQueuingStrategy); - const ByteLengthQueuingStrategyPrototype = - ByteLengthQueuingStrategy.prototype; /** @type {WeakMap number>} */ const byteSizeFunctionWeakMap = new WeakMap(); @@ -4255,13 +4226,13 @@ /** @returns {number} */ get highWaterMark() { - webidl.assertBranded(this, CountQueuingStrategyPrototype); + webidl.assertBranded(this, CountQueuingStrategy); return this[_highWaterMark]; } /** @returns {(chunk: any) => 1} */ get size() { - webidl.assertBranded(this, CountQueuingStrategyPrototype); + webidl.assertBranded(this, CountQueuingStrategy); initializeCountSizeFunction(this[_globalObject]); return WeakMapPrototypeGet(countSizeFunctionWeakMap, this[_globalObject]); } @@ -4269,10 +4240,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - CountQueuingStrategyPrototype, - this, - ), + evaluate: this instanceof CountQueuingStrategy, keys: [ "highWaterMark", "size", @@ -4282,7 +4250,6 @@ } webidl.configurePrototype(CountQueuingStrategy); - const CountQueuingStrategyPrototype = CountQueuingStrategy.prototype; /** @type {WeakMap 1>} */ const countSizeFunctionWeakMap = new WeakMap(); @@ -4366,7 +4333,7 @@ /** @returns {boolean} */ get locked() { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); return isReadableStreamLocked(this); } @@ -4376,7 +4343,7 @@ */ cancel(reason = undefined) { try { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); if (reason !== undefined) { reason = webidl.converters.any(reason); } @@ -4396,7 +4363,7 @@ * @returns {ReadableStreamDefaultReader | ReadableStreamBYOBReader} */ getReader(options = {}) { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); const prefix = "Failed to execute 'getReader' on 'ReadableStream'"; options = webidl.converters.ReadableStreamGetReaderOptions(options, { prefix, @@ -4417,7 +4384,7 @@ * @returns {ReadableStream} */ pipeThrough(transform, options = {}) { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); const prefix = "Failed to execute 'pipeThrough' on 'ReadableStream'"; webidl.requiredArguments(arguments.length, 1, { prefix }); transform = webidl.converters.ReadableWritablePair(transform, { @@ -4455,7 +4422,7 @@ */ pipeTo(destination, options = {}) { try { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); const prefix = "Failed to execute 'pipeTo' on 'ReadableStream'"; webidl.requiredArguments(arguments.length, 1, { prefix }); destination = webidl.converters.WritableStream(destination, { @@ -4492,7 +4459,7 @@ /** @returns {[ReadableStream, ReadableStream]} */ tee() { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); return readableStreamTee(this, false); } @@ -4502,7 +4469,7 @@ * @returns {AsyncIterableIterator} */ values(options = {}) { - webidl.assertBranded(this, ReadableStreamPrototype); + webidl.assertBranded(this, ReadableStream); const prefix = "Failed to execute 'values' on 'ReadableStream'"; options = webidl.converters.ReadableStreamIteratorOptions(options, { prefix, @@ -4531,7 +4498,6 @@ }); webidl.configurePrototype(ReadableStream); - const ReadableStreamPrototype = ReadableStream.prototype; function errorReadableStream(stream, e) { readableStreamDefaultControllerError(stream[_controller], e); @@ -4561,7 +4527,7 @@ /** @returns {Promise>} */ read() { try { - webidl.assertBranded(this, ReadableStreamDefaultReaderPrototype); + webidl.assertBranded(this, ReadableStreamDefaultReader); } catch (err) { return PromiseReject(err); } @@ -4590,7 +4556,7 @@ /** @returns {void} */ releaseLock() { - webidl.assertBranded(this, ReadableStreamDefaultReaderPrototype); + webidl.assertBranded(this, ReadableStreamDefaultReader); if (this[_stream] === undefined) { return; } @@ -4599,7 +4565,7 @@ get closed() { try { - webidl.assertBranded(this, ReadableStreamDefaultReaderPrototype); + webidl.assertBranded(this, ReadableStreamDefaultReader); } catch (err) { return PromiseReject(err); } @@ -4612,7 +4578,7 @@ */ cancel(reason = undefined) { try { - webidl.assertBranded(this, ReadableStreamDefaultReaderPrototype); + webidl.assertBranded(this, ReadableStreamDefaultReader); if (reason !== undefined) { reason = webidl.converters.any(reason); } @@ -4634,8 +4600,6 @@ } webidl.configurePrototype(ReadableStreamDefaultReader); - const ReadableStreamDefaultReaderPrototype = - ReadableStreamDefaultReader.prototype; /** @template R */ class ReadableStreamBYOBReader { @@ -4664,7 +4628,7 @@ */ read(view) { try { - webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype); + webidl.assertBranded(this, ReadableStreamBYOBReader); const prefix = "Failed to execute 'read' on 'ReadableStreamBYOBReader'"; view = webidl.converters.ArrayBufferView(view, { prefix, @@ -4714,7 +4678,7 @@ /** @returns {void} */ releaseLock() { - webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype); + webidl.assertBranded(this, ReadableStreamBYOBReader); if (this[_stream] === undefined) { return; } @@ -4723,7 +4687,7 @@ get closed() { try { - webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype); + webidl.assertBranded(this, ReadableStreamBYOBReader); } catch (err) { return PromiseReject(err); } @@ -4736,7 +4700,7 @@ */ cancel(reason = undefined) { try { - webidl.assertBranded(this, ReadableStreamBYOBReaderPrototype); + webidl.assertBranded(this, ReadableStreamBYOBReader); if (reason !== undefined) { reason = webidl.converters.any(reason); } @@ -4758,7 +4722,6 @@ } webidl.configurePrototype(ReadableStreamBYOBReader); - const ReadableStreamBYOBReaderPrototype = ReadableStreamBYOBReader.prototype; class ReadableStreamBYOBRequest { /** @type {ReadableByteStreamController} */ @@ -4768,7 +4731,7 @@ /** @returns {ArrayBufferView | null} */ get view() { - webidl.assertBranded(this, ReadableStreamBYOBRequestPrototype); + webidl.assertBranded(this, ReadableStreamBYOBRequest); return this[_view]; } @@ -4777,7 +4740,7 @@ } respond(bytesWritten) { - webidl.assertBranded(this, ReadableStreamBYOBRequestPrototype); + webidl.assertBranded(this, ReadableStreamBYOBRequest); const prefix = "Failed to execute 'respond' on 'ReadableStreamBYOBRequest'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4801,7 +4764,7 @@ } respondWithNewView(view) { - webidl.assertBranded(this, ReadableStreamBYOBRequestPrototype); + webidl.assertBranded(this, ReadableStreamBYOBRequest); const prefix = "Failed to execute 'respondWithNewView' on 'ReadableStreamBYOBRequest'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4823,8 +4786,6 @@ } webidl.configurePrototype(ReadableStreamBYOBRequest); - const ReadableStreamBYOBRequestPrototype = - ReadableStreamBYOBRequest.prototype; class ReadableByteStreamController { /** @type {number | undefined} */ @@ -4860,19 +4821,19 @@ /** @returns {ReadableStreamBYOBRequest | null} */ get byobRequest() { - webidl.assertBranded(this, ReadableByteStreamControllerPrototype); + webidl.assertBranded(this, ReadableByteStreamController); return readableByteStreamControllerGetBYOBRequest(this); } /** @returns {number | null} */ get desiredSize() { - webidl.assertBranded(this, ReadableByteStreamControllerPrototype); + webidl.assertBranded(this, ReadableByteStreamController); return readableByteStreamControllerGetDesiredSize(this); } /** @returns {void} */ close() { - webidl.assertBranded(this, ReadableByteStreamControllerPrototype); + webidl.assertBranded(this, ReadableByteStreamController); if (this[_closeRequested] === true) { throw new TypeError("Closed already requested."); } @@ -4889,7 +4850,7 @@ * @returns {void} */ enqueue(chunk) { - webidl.assertBranded(this, ReadableByteStreamControllerPrototype); + webidl.assertBranded(this, ReadableByteStreamController); const prefix = "Failed to execute 'enqueue' on 'ReadableByteStreamController'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4929,7 +4890,7 @@ * @returns {void} */ error(e = undefined) { - webidl.assertBranded(this, ReadableByteStreamControllerPrototype); + webidl.assertBranded(this, ReadableByteStreamController); if (e !== undefined) { e = webidl.converters.any(e); } @@ -4939,10 +4900,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - ReadableByteStreamControllerPrototype, - this, - ), + evaluate: this instanceof ReadableByteStreamController, keys: ["desiredSize"], })); } @@ -5009,8 +4967,6 @@ } webidl.configurePrototype(ReadableByteStreamController); - const ReadableByteStreamControllerPrototype = - ReadableByteStreamController.prototype; /** @template R */ class ReadableStreamDefaultController { @@ -5043,13 +4999,13 @@ /** @returns {number | null} */ get desiredSize() { - webidl.assertBranded(this, ReadableStreamDefaultControllerPrototype); + webidl.assertBranded(this, ReadableStreamDefaultController); return readableStreamDefaultControllerGetDesiredSize(this); } /** @returns {void} */ close() { - webidl.assertBranded(this, ReadableStreamDefaultControllerPrototype); + webidl.assertBranded(this, ReadableStreamDefaultController); if (readableStreamDefaultControllerCanCloseOrEnqueue(this) === false) { throw new TypeError("The stream controller cannot close or enqueue."); } @@ -5061,7 +5017,7 @@ * @returns {void} */ enqueue(chunk = undefined) { - webidl.assertBranded(this, ReadableStreamDefaultControllerPrototype); + webidl.assertBranded(this, ReadableStreamDefaultController); if (chunk !== undefined) { chunk = webidl.converters.any(chunk); } @@ -5076,7 +5032,7 @@ * @returns {void} */ error(e = undefined) { - webidl.assertBranded(this, ReadableStreamDefaultControllerPrototype); + webidl.assertBranded(this, ReadableStreamDefaultController); if (e !== undefined) { e = webidl.converters.any(e); } @@ -5086,10 +5042,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - ReadableStreamDefaultController.prototype, - this, - ), + evaluate: this instanceof ReadableStreamDefaultController, keys: ["desiredSize"], })); } @@ -5132,8 +5085,6 @@ } webidl.configurePrototype(ReadableStreamDefaultController); - const ReadableStreamDefaultControllerPrototype = - ReadableStreamDefaultController.prototype; /** * @template I @@ -5235,13 +5186,13 @@ /** @returns {ReadableStream} */ get readable() { - webidl.assertBranded(this, TransformStreamPrototype); + webidl.assertBranded(this, TransformStream); return this[_readable]; } /** @returns {WritableStream} */ get writable() { - webidl.assertBranded(this, TransformStreamPrototype); + webidl.assertBranded(this, TransformStream); return this[_writable]; } @@ -5253,7 +5204,6 @@ } webidl.configurePrototype(TransformStream); - const TransformStreamPrototype = TransformStream.prototype; /** @template O */ class TransformStreamDefaultController { @@ -5270,7 +5220,7 @@ /** @returns {number | null} */ get desiredSize() { - webidl.assertBranded(this, TransformStreamDefaultController.prototype); + webidl.assertBranded(this, TransformStreamDefaultController); const readableController = this[_stream][_readable][_controller]; return readableStreamDefaultControllerGetDesiredSize( /** @type {ReadableStreamDefaultController} */ readableController, @@ -5282,7 +5232,7 @@ * @returns {void} */ enqueue(chunk = undefined) { - webidl.assertBranded(this, TransformStreamDefaultController.prototype); + webidl.assertBranded(this, TransformStreamDefaultController); if (chunk !== undefined) { chunk = webidl.converters.any(chunk); } @@ -5294,7 +5244,7 @@ * @returns {void} */ error(reason = undefined) { - webidl.assertBranded(this, TransformStreamDefaultController.prototype); + webidl.assertBranded(this, TransformStreamDefaultController); if (reason !== undefined) { reason = webidl.converters.any(reason); } @@ -5303,25 +5253,20 @@ /** @returns {void} */ terminate() { - webidl.assertBranded(this, TransformStreamDefaultControllerPrototype); + webidl.assertBranded(this, TransformStreamDefaultController); transformStreamDefaultControllerTerminate(this); } [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - TransformStreamDefaultController.prototype, - this, - ), + evaluate: this instanceof TransformStreamDefaultController, keys: ["desiredSize"], })); } } webidl.configurePrototype(TransformStreamDefaultController); - const TransformStreamDefaultControllerPrototype = - TransformStreamDefaultController.prototype; /** @template W */ class WritableStream { @@ -5391,7 +5336,7 @@ /** @returns {boolean} */ get locked() { - webidl.assertBranded(this, WritableStreamPrototype); + webidl.assertBranded(this, WritableStream); return isWritableStreamLocked(this); } @@ -5401,7 +5346,7 @@ */ abort(reason = undefined) { try { - webidl.assertBranded(this, WritableStreamPrototype); + webidl.assertBranded(this, WritableStream); } catch (err) { return PromiseReject(err); } @@ -5421,7 +5366,7 @@ /** @returns {Promise} */ close() { try { - webidl.assertBranded(this, WritableStreamPrototype); + webidl.assertBranded(this, WritableStream); } catch (err) { return PromiseReject(err); } @@ -5442,7 +5387,7 @@ /** @returns {WritableStreamDefaultWriter} */ getWriter() { - webidl.assertBranded(this, WritableStreamPrototype); + webidl.assertBranded(this, WritableStream); return acquireWritableStreamDefaultWriter(this); } @@ -5452,7 +5397,6 @@ } webidl.configurePrototype(WritableStream); - const WritableStreamPrototype = WritableStream.prototype; /** @template W */ class WritableStreamDefaultWriter { @@ -5482,7 +5426,7 @@ /** @returns {Promise} */ get closed() { try { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); } catch (err) { return PromiseReject(err); } @@ -5491,7 +5435,7 @@ /** @returns {number} */ get desiredSize() { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); if (this[_stream] === undefined) { throw new TypeError( "A writable stream is not associated with the writer.", @@ -5503,7 +5447,7 @@ /** @returns {Promise} */ get ready() { try { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); } catch (err) { return PromiseReject(err); } @@ -5516,7 +5460,7 @@ */ abort(reason = undefined) { try { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); } catch (err) { return PromiseReject(err); } @@ -5534,7 +5478,7 @@ /** @returns {Promise} */ close() { try { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); } catch (err) { return PromiseReject(err); } @@ -5554,7 +5498,7 @@ /** @returns {void} */ releaseLock() { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); const stream = this[_stream]; if (stream === undefined) { return; @@ -5569,7 +5513,7 @@ */ write(chunk = undefined) { try { - webidl.assertBranded(this, WritableStreamDefaultWriterPrototype); + webidl.assertBranded(this, WritableStreamDefaultWriter); if (chunk !== undefined) { chunk = webidl.converters.any(chunk); } @@ -5587,10 +5531,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - WritableStreamDefaultWriter.prototype, - this, - ), + evaluate: this instanceof WritableStreamDefaultWriter, keys: [ "closed", "desiredSize", @@ -5601,8 +5542,6 @@ } webidl.configurePrototype(WritableStreamDefaultWriter); - const WritableStreamDefaultWriterPrototype = - WritableStreamDefaultWriter.prototype; /** @template W */ class WritableStreamDefaultController { @@ -5628,7 +5567,7 @@ [_signal]; get signal() { - webidl.assertBranded(this, WritableStreamDefaultControllerPrototype); + webidl.assertBranded(this, WritableStreamDefaultController); return this[_signal]; } @@ -5641,7 +5580,7 @@ * @returns {void} */ error(e = undefined) { - webidl.assertBranded(this, WritableStreamDefaultControllerPrototype); + webidl.assertBranded(this, WritableStreamDefaultController); if (e !== undefined) { e = webidl.converters.any(e); } @@ -5655,10 +5594,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - WritableStreamDefaultController.prototype, - this, - ), + evaluate: this instanceof WritableStreamDefaultController, keys: [], })); } @@ -5679,8 +5615,6 @@ } webidl.configurePrototype(WritableStreamDefaultController); - const WritableStreamDefaultControllerPrototype = - WritableStreamDefaultController.prototype; /** * @param {ReadableStream} stream @@ -5690,9 +5624,9 @@ } webidl.converters.ReadableStream = webidl - .createInterfaceConverter("ReadableStream", ReadableStream.prototype); + .createInterfaceConverter("ReadableStream", ReadableStream); webidl.converters.WritableStream = webidl - .createInterfaceConverter("WritableStream", WritableStream.prototype); + .createInterfaceConverter("WritableStream", WritableStream); webidl.converters.ReadableStreamType = webidl.createEnumConverter( "ReadableStreamType", @@ -5853,7 +5787,6 @@ ByteLengthQueuingStrategy, CountQueuingStrategy, ReadableStream, - ReadableStreamPrototype, ReadableStreamDefaultReader, TransformStream, WritableStream, diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index 4f26089b1d..cf7b7e12f3 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -16,7 +16,6 @@ const webidl = window.__bootstrap.webidl; const { ArrayBufferIsView, - ObjectPrototypeIsPrototypeOf, PromiseReject, PromiseResolve, StringPrototypeCharCodeAt, @@ -60,19 +59,19 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextDecoderPrototype); + webidl.assertBranded(this, TextDecoder); return this.#encoding; } /** @returns {boolean} */ get fatal() { - webidl.assertBranded(this, TextDecoderPrototype); + webidl.assertBranded(this, TextDecoder); return this.#fatal; } /** @returns {boolean} */ get ignoreBOM() { - webidl.assertBranded(this, TextDecoderPrototype); + webidl.assertBranded(this, TextDecoder); return this.#ignoreBOM; } @@ -81,7 +80,7 @@ * @param {TextDecodeOptions} options */ decode(input = new Uint8Array(), options = {}) { - webidl.assertBranded(this, TextDecoderPrototype); + webidl.assertBranded(this, TextDecoder); const prefix = "Failed to execute 'decode' on 'TextDecoder'"; if (input !== undefined) { input = webidl.converters.BufferSource(input, { @@ -120,12 +119,7 @@ // If the buffer is detached, just create a new empty Uint8Array. input = new Uint8Array(); } - if ( - ObjectPrototypeIsPrototypeOf( - SharedArrayBuffer.prototype, - input.buffer, - ) - ) { + if (input.buffer instanceof SharedArrayBuffer) { // We clone the data into a non-shared ArrayBuffer so we can pass it // to Rust. // `input` is now a Uint8Array, and calling the TypedArray constructor @@ -146,7 +140,6 @@ } webidl.configurePrototype(TextDecoder); - const TextDecoderPrototype = TextDecoder.prototype; class TextEncoder { constructor() { @@ -155,7 +148,7 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextEncoderPrototype); + webidl.assertBranded(this, TextEncoder); return "utf-8"; } @@ -164,7 +157,7 @@ * @returns {Uint8Array} */ encode(input = "") { - webidl.assertBranded(this, TextEncoderPrototype); + webidl.assertBranded(this, TextEncoder); const prefix = "Failed to execute 'encode' on 'TextEncoder'"; // The WebIDL type of `input` is `USVString`, but `core.encode` already // converts lone surrogates to the replacement character. @@ -181,7 +174,7 @@ * @returns {TextEncoderEncodeIntoResult} */ encodeInto(source, destination) { - webidl.assertBranded(this, TextEncoderPrototype); + webidl.assertBranded(this, TextEncoder); const prefix = "Failed to execute 'encodeInto' on 'TextEncoder'"; // The WebIDL type of `source` is `USVString`, but the ops bindings // already convert lone surrogates to the replacement character. @@ -199,7 +192,6 @@ } webidl.configurePrototype(TextEncoder); - const TextEncoderPrototype = TextEncoder.prototype; class TextDecoderStream { /** @type {TextDecoder} */ @@ -256,37 +248,36 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextDecoderStreamPrototype); + webidl.assertBranded(this, TextDecoderStream); return this.#decoder.encoding; } /** @returns {boolean} */ get fatal() { - webidl.assertBranded(this, TextDecoderStreamPrototype); + webidl.assertBranded(this, TextDecoderStream); return this.#decoder.fatal; } /** @returns {boolean} */ get ignoreBOM() { - webidl.assertBranded(this, TextDecoderStreamPrototype); + webidl.assertBranded(this, TextDecoderStream); return this.#decoder.ignoreBOM; } /** @returns {ReadableStream} */ get readable() { - webidl.assertBranded(this, TextDecoderStreamPrototype); + webidl.assertBranded(this, TextDecoderStream); return this.#transform.readable; } /** @returns {WritableStream} */ get writable() { - webidl.assertBranded(this, TextDecoderStreamPrototype); + webidl.assertBranded(this, TextDecoderStream); return this.#transform.writable; } } webidl.configurePrototype(TextDecoderStream); - const TextDecoderStreamPrototype = TextDecoderStream.prototype; class TextEncoderStream { /** @type {string | null} */ @@ -341,25 +332,24 @@ /** @returns {string} */ get encoding() { - webidl.assertBranded(this, TextEncoderStreamPrototype); + webidl.assertBranded(this, TextEncoderStream); return "utf-8"; } /** @returns {ReadableStream} */ get readable() { - webidl.assertBranded(this, TextEncoderStreamPrototype); + webidl.assertBranded(this, TextEncoderStream); return this.#transform.readable; } /** @returns {WritableStream} */ get writable() { - webidl.assertBranded(this, TextEncoderStreamPrototype); + webidl.assertBranded(this, TextEncoderStream); return this.#transform.writable; } } webidl.configurePrototype(TextEncoderStream); - const TextEncoderStreamPrototype = TextEncoderStream.prototype; webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter( "TextDecoderOptions", diff --git a/ext/web/09_file.js b/ext/web/09_file.js index fbc00326ef..289db22ecd 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -15,7 +15,7 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferPrototypeSlice, ArrayBufferIsView, ArrayPrototypePush, @@ -23,7 +23,6 @@ DatePrototypeGetTime, MathMax, MathMin, - ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, StringPrototypeCharAt, StringPrototypeToLowerCase, @@ -110,7 +109,7 @@ const processedParts = []; let size = 0; for (const element of parts) { - if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) { + if (element instanceof ArrayBuffer) { const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0)); ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); size += element.byteLength; @@ -122,7 +121,7 @@ ); size += element.byteLength; ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); - } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, element)) { + } else if (element instanceof Blob) { ArrayPrototypePush(processedParts, element); size += element.size; } else if (typeof element === "string") { @@ -158,7 +157,7 @@ */ function getParts(blob, bag = []) { for (const part of blob[_parts]) { - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) { + if (part instanceof Blob) { getParts(part, bag); } else { ArrayPrototypePush(bag, part._id); @@ -205,13 +204,13 @@ /** @returns {number} */ get size() { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); return this[_size]; } /** @returns {string} */ get type() { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); return this[_type]; } @@ -222,7 +221,7 @@ * @returns {Blob} */ slice(start = undefined, end = undefined, contentType = undefined) { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); const prefix = "Failed to execute 'slice' on 'Blob'"; if (start !== undefined) { start = webidl.converters["long long"](start, { @@ -317,7 +316,7 @@ * @returns {ReadableStream} */ stream() { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); const partIterator = toIterator(this[_parts]); const stream = new ReadableStream({ type: "bytes", @@ -339,7 +338,7 @@ * @returns {Promise} */ async text() { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); const buffer = await this.arrayBuffer(); return core.decode(new Uint8Array(buffer)); } @@ -348,7 +347,7 @@ * @returns {Promise} */ async arrayBuffer() { - webidl.assertBranded(this, BlobPrototype); + webidl.assertBranded(this, Blob); const stream = this.stream(); const bytes = new Uint8Array(this.size); let offset = 0; @@ -362,7 +361,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: ObjectPrototypeIsPrototypeOf(BlobPrototype, this), + evaluate: this instanceof Blob, keys: [ "size", "type", @@ -372,22 +371,15 @@ } webidl.configurePrototype(Blob); - const BlobPrototype = Blob.prototype; - webidl.converters["Blob"] = webidl.createInterfaceConverter( - "Blob", - Blob.prototype, - ); + webidl.converters["Blob"] = webidl.createInterfaceConverter("Blob", Blob); webidl.converters["BlobPart"] = (V, opts) => { // Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString) if (typeof V == "object") { - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { + if (V instanceof Blob) { return webidl.converters["Blob"](V, opts); } - if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) - ) { + if (V instanceof ArrayBuffer || V instanceof SharedArrayBuffer) { return webidl.converters["ArrayBuffer"](V, opts); } if (ArrayBufferIsView(V)) { @@ -466,19 +458,18 @@ /** @returns {string} */ get name() { - webidl.assertBranded(this, FilePrototype); + webidl.assertBranded(this, File); return this[_Name]; } /** @returns {number} */ get lastModified() { - webidl.assertBranded(this, FilePrototype); + webidl.assertBranded(this, File); return this[_LastModified]; } } webidl.configurePrototype(File); - const FilePrototype = File.prototype; webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter( "FilePropertyBag", @@ -602,8 +593,6 @@ blobFromObjectUrl, getParts, Blob, - BlobPrototype, File, - FilePrototype, }; })(this); diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index 039d3395d4..294d96ebd8 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -28,14 +28,12 @@ MapPrototypeGet, MapPrototypeSet, ObjectDefineProperty, - ObjectPrototypeIsPrototypeOf, queueMicrotask, StringFromCodePoint, Symbol, TypedArrayPrototypeSet, TypeError, Uint8Array, - Uint8ArrayPrototype, } = window.__bootstrap.primordials; const state = Symbol("[[state]]"); @@ -118,10 +116,7 @@ // 4. If chunkPromise is fulfilled with an object whose done property is false // and whose value property is a Uint8Array object, run these steps: - if ( - !chunk.done && - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk.value) - ) { + if (!chunk.done && chunk.value instanceof Uint8Array) { ArrayPrototypePush(chunks, chunk.value); // TODO(bartlomieju): (only) If roughly 50ms have passed since last progress @@ -265,7 +260,7 @@ } #getEventHandlerFor(name) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); const maybeMap = this[handlerSymbol]; if (!maybeMap) return null; @@ -274,7 +269,7 @@ } #setEventHandlerFor(name, value) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); if (!this[handlerSymbol]) { this[handlerSymbol] = new Map(); @@ -297,7 +292,7 @@ /** @returns {number} */ get readyState() { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); switch (this[state]) { case "empty": return FileReader.EMPTY; @@ -311,17 +306,17 @@ } get result() { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); return this[result]; } get error() { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); return this[error]; } abort() { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); // If context object's state is "empty" or if context object's state is "done" set context object's result to null and terminate this algorithm. if ( this[state] === "empty" || @@ -354,7 +349,7 @@ /** @param {Blob} blob */ readAsArrayBuffer(blob) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); const prefix = "Failed to execute 'readAsArrayBuffer' on 'FileReader'"; webidl.requiredArguments(arguments.length, 1, { prefix }); this.#readOperation(blob, { kind: "ArrayBuffer" }); @@ -362,7 +357,7 @@ /** @param {Blob} blob */ readAsBinaryString(blob) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); const prefix = "Failed to execute 'readAsBinaryString' on 'FileReader'"; webidl.requiredArguments(arguments.length, 1, { prefix }); // alias for readAsArrayBuffer @@ -371,7 +366,7 @@ /** @param {Blob} blob */ readAsDataURL(blob) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); const prefix = "Failed to execute 'readAsDataURL' on 'FileReader'"; webidl.requiredArguments(arguments.length, 1, { prefix }); // alias for readAsArrayBuffer @@ -383,7 +378,7 @@ * @param {string} [encoding] */ readAsText(blob, encoding = undefined) { - webidl.assertBranded(this, FileReaderPrototype); + webidl.assertBranded(this, FileReader); const prefix = "Failed to execute 'readAsText' on 'FileReader'"; webidl.requiredArguments(arguments.length, 1, { prefix }); if (encoding !== undefined) { @@ -440,7 +435,6 @@ } webidl.configurePrototype(FileReader); - const FileReaderPrototype = FileReader.prototype; ObjectDefineProperty(FileReader, "EMPTY", { writable: false, diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 8242f85f3e..ef332dd7af 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -10,21 +10,19 @@ ((window) => { const core = window.Deno.core; - const { InterruptedPrototype } = core; + const { Interrupted } = core; const webidl = window.__bootstrap.webidl; const { setEventTargetData } = window.__bootstrap.eventTarget; const { defineEventHandler } = window.__bootstrap.event; const { DOMException } = window.__bootstrap.domException; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayPrototypeFilter, ArrayPrototypeIncludes, ArrayPrototypePush, - ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, Symbol, SymbolFor, - SymbolIterator, TypeError, WeakSet, WeakSetPrototypeAdd, @@ -47,12 +45,12 @@ } get port1() { - webidl.assertBranded(this, MessageChannelPrototype); + webidl.assertBranded(this, MessageChannel); return this.#port1; } get port2() { - webidl.assertBranded(this, MessageChannelPrototype); + webidl.assertBranded(this, MessageChannel); return this.#port2; } @@ -64,7 +62,6 @@ } webidl.configurePrototype(MessageChannel); - const MessageChannelPrototype = MessageChannel.prototype; const _id = Symbol("id"); const _enabled = Symbol("enabled"); @@ -75,7 +72,7 @@ */ function createMessagePort(id) { const port = core.createHostObject(); - ObjectSetPrototypeOf(port, MessagePortPrototype); + ObjectSetPrototypeOf(port, MessagePort.prototype); port[webidl.brand] = webidl.brand; setEventTargetData(port); port[_id] = id; @@ -98,7 +95,7 @@ * @param {object[] | StructuredSerializeOptions} transferOrOptions */ postMessage(message, transferOrOptions = {}) { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); const prefix = "Failed to execute 'postMessage' on 'MessagePort'"; webidl.requiredArguments(arguments.length, 1, { prefix }); message = webidl.converters.any(message); @@ -106,7 +103,7 @@ if ( webidl.type(transferOrOptions) === "Object" && transferOrOptions !== undefined && - transferOrOptions[SymbolIterator] !== undefined + transferOrOptions[Symbol.iterator] !== undefined ) { const transfer = webidl.converters["sequence"]( transferOrOptions, @@ -132,7 +129,7 @@ } start() { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); if (this[_enabled]) return; (async () => { this[_enabled] = true; @@ -145,7 +142,7 @@ this[_id], ); } catch (err) { - if (ObjectPrototypeIsPrototypeOf(InterruptedPrototype, err)) break; + if (err instanceof Interrupted) break; throw err; } if (data === null) break; @@ -163,7 +160,7 @@ data: message, ports: ArrayPrototypeFilter( transferables, - (t) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t), + (t) => t instanceof MessagePort, ), }); this.dispatchEvent(event); @@ -173,7 +170,7 @@ } close() { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); if (this[_id] !== null) { core.close(this[_id]); this[_id] = null; @@ -187,7 +184,6 @@ defineEventHandler(MessagePort.prototype, "messageerror"); webidl.configurePrototype(MessagePort); - const MessagePortPrototype = MessagePort.prototype; /** * @returns {[number, number]} @@ -249,7 +245,7 @@ function serializeJsMessageData(data, transferables) { const transferedArrayBuffers = ArrayPrototypeFilter( transferables, - (a) => ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, a), + (a) => a instanceof ArrayBuffer, ); for (const arrayBuffer of transferedArrayBuffers) { @@ -270,7 +266,7 @@ serializedData = core.serialize(data, { hostObjects: ArrayPrototypeFilter( transferables, - (a) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, a), + (a) => a instanceof MessagePort, ), transferedArrayBuffers, }); @@ -283,8 +279,8 @@ let arrayBufferI = 0; for (const transferable of transferables) { - if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) { - webidl.assertBranded(transferable, MessagePortPrototype); + if (transferable instanceof MessagePort) { + webidl.assertBranded(transferable, MessagePort); const id = transferable[_id]; if (id === null) { throw new DOMException( @@ -297,9 +293,7 @@ kind: "messagePort", data: id, }); - } else if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, transferable) - ) { + } else if (transferable instanceof ArrayBuffer) { ArrayPrototypePush(serializedTransferables, { kind: "arrayBuffer", data: transferedArrayBuffers[arrayBufferI], @@ -345,7 +339,6 @@ window.__bootstrap.messagePort = { MessageChannel, MessagePort, - MessagePortPrototype, deserializeJsMessageData, serializeJsMessageData, structuredClone, diff --git a/ext/web/14_compression.js b/ext/web/14_compression.js index 0814958949..1a0f77e665 100644 --- a/ext/web/14_compression.js +++ b/ext/web/14_compression.js @@ -53,18 +53,17 @@ } get readable() { - webidl.assertBranded(this, CompressionStreamPrototype); + webidl.assertBranded(this, CompressionStream); return this.#transform.readable; } get writable() { - webidl.assertBranded(this, CompressionStreamPrototype); + webidl.assertBranded(this, CompressionStream); return this.#transform.writable; } } webidl.configurePrototype(CompressionStream); - const CompressionStreamPrototype = CompressionStream.prototype; class DecompressionStream { #transform; @@ -99,12 +98,12 @@ } get readable() { - webidl.assertBranded(this, DecompressionStreamPrototype); + webidl.assertBranded(this, DecompressionStream); return this.#transform.readable; } get writable() { - webidl.assertBranded(this, DecompressionStreamPrototype); + webidl.assertBranded(this, DecompressionStream); return this.#transform.writable; } } @@ -116,7 +115,6 @@ } webidl.configurePrototype(DecompressionStream); - const DecompressionStreamPrototype = DecompressionStream.prototype; window.__bootstrap.compression = { CompressionStream, diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index cd1a6e5ad7..45d910c1a2 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -25,7 +25,6 @@ MathMax, ObjectDefineProperty, ObjectFreeze, - ObjectPrototypeIsPrototypeOf, Promise, PromiseAll, PromisePrototypeCatch, @@ -43,7 +42,6 @@ SymbolIterator, TypeError, Uint32Array, - Uint32ArrayPrototype, Uint8Array, } = window.__bootstrap.primordials; @@ -159,7 +157,6 @@ super("device out of memory"); } } - const GPUOutOfMemoryErrorPrototype = GPUOutOfMemoryError.prototype; class GPUValidationError extends Error { name = "GPUValidationError"; @@ -186,7 +183,7 @@ * @param {GPURequestAdapterOptions} options */ async requestAdapter(options = {}) { - webidl.assertBranded(this, GPUPrototype); + webidl.assertBranded(this, GPU); options = webidl.converters.GPURequestAdapterOptions(options, { prefix: "Failed to execute 'requestAdapter' on 'GPU'", context: "Argument 1", @@ -208,7 +205,6 @@ return `${this.constructor.name} ${inspect({})}`; } } - const GPUPrototype = GPU.prototype; const _name = Symbol("[[name]]"); const _adapter = Symbol("[[adapter]]"); @@ -247,17 +243,17 @@ /** @returns {string} */ get name() { - webidl.assertBranded(this, GPUAdapterPrototype); + webidl.assertBranded(this, GPUAdapter); return this[_name]; } /** @returns {GPUSupportedFeatures} */ get features() { - webidl.assertBranded(this, GPUAdapterPrototype); + webidl.assertBranded(this, GPUAdapter); return this[_adapter].features; } /** @returns {GPUSupportedLimits} */ get limits() { - webidl.assertBranded(this, GPUAdapterPrototype); + webidl.assertBranded(this, GPUAdapter); return this[_adapter].limits; } /** @returns {boolean} */ @@ -274,7 +270,7 @@ * @returns {Promise} */ async requestDevice(descriptor = {}) { - webidl.assertBranded(this, GPUAdapterPrototype); + webidl.assertBranded(this, GPUAdapter); const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'"; descriptor = webidl.converters.GPUDeviceDescriptor(descriptor, { prefix, @@ -324,7 +320,6 @@ }`; } } - const GPUAdapterPrototype = GPUAdapter.prototype; const _limits = Symbol("[[limits]]"); @@ -373,107 +368,107 @@ } get maxTextureDimension1D() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxTextureDimension1D; } get maxTextureDimension2D() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxTextureDimension2D; } get maxTextureDimension3D() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxTextureDimension3D; } get maxTextureArrayLayers() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxTextureArrayLayers; } get maxBindGroups() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxBindGroups; } get maxDynamicUniformBuffersPerPipelineLayout() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxDynamicUniformBuffersPerPipelineLayout; } get maxDynamicStorageBuffersPerPipelineLayout() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxDynamicStorageBuffersPerPipelineLayout; } get maxSampledTexturesPerShaderStage() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxSampledTexturesPerShaderStage; } get maxSamplersPerShaderStage() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxSamplersPerShaderStage; } get maxStorageBuffersPerShaderStage() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxStorageBuffersPerShaderStage; } get maxStorageTexturesPerShaderStage() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxStorageTexturesPerShaderStage; } get maxUniformBuffersPerShaderStage() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxUniformBuffersPerShaderStage; } get maxUniformBufferBindingSize() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxUniformBufferBindingSize; } get maxStorageBufferBindingSize() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxStorageBufferBindingSize; } get minUniformBufferOffsetAlignment() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].minUniformBufferOffsetAlignment; } get minStorageBufferOffsetAlignment() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].minStorageBufferOffsetAlignment; } get maxVertexBuffers() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxVertexBuffers; } get maxVertexAttributes() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxVertexAttributes; } get maxVertexBufferArrayStride() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxVertexBufferArrayStride; } get maxInterStageShaderComponents() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxInterStageShaderComponents; } get maxComputeWorkgroupStorageSize() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeWorkgroupStorageSize; } get maxComputeInvocationsPerWorkgroup() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeInvocationsPerWorkgroup; } get maxComputeWorkgroupSizeX() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeWorkgroupSizeX; } get maxComputeWorkgroupSizeY() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeWorkgroupSizeY; } get maxComputeWorkgroupSizeZ() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeWorkgroupSizeZ; } get maxComputeWorkgroupsPerDimension() { - webidl.assertBranded(this, GPUSupportedLimitsPrototype); + webidl.assertBranded(this, GPUSupportedLimits); return this[_limits].maxComputeWorkgroupsPerDimension; } @@ -481,7 +476,6 @@ return `${this.constructor.name} ${inspect(this[_limits])}`; } } - const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype; const _features = Symbol("[[features]]"); @@ -502,42 +496,42 @@ /** @return {IterableIterator<[string, string]>} */ entries() { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return SetPrototypeEntries(this[_features]); } /** @return {void} */ forEach(callbackfn, thisArg) { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); SetPrototypeForEach(this[_features], callbackfn, thisArg); } /** @return {boolean} */ has(value) { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return SetPrototypeHas(this[_features], value); } /** @return {IterableIterator} */ keys() { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return SetPrototypeKeys(this[_features]); } /** @return {IterableIterator} */ values() { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return SetPrototypeValues(this[_features]); } /** @return {number} */ get size() { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return this[_features].size; } [SymbolIterator]() { - webidl.assertBranded(this, GPUSupportedFeaturesPrototype); + webidl.assertBranded(this, GPUSupportedFeatures); return this[_features][SymbolIterator](); } @@ -546,8 +540,6 @@ } } - const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype; - const _reason = Symbol("[[reason]]"); const _message = Symbol("[[message]]"); @@ -575,11 +567,11 @@ } get reason() { - webidl.assertBranded(this, GPUDeviceLostInfoPrototype); + webidl.assertBranded(this, GPUDeviceLostInfo); return this[_reason]; } get message() { - webidl.assertBranded(this, GPUDeviceLostInfoPrototype); + webidl.assertBranded(this, GPUDeviceLostInfo); return this[_message]; } @@ -590,8 +582,6 @@ } } - const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype; - const _label = Symbol("[[label]]"); /** @@ -605,14 +595,14 @@ * @return {string | null} */ get() { - webidl.assertBranded(this, type.prototype); + webidl.assertBranded(this, type); return this[_label]; }, /** * @param {string | null} label */ set(label) { - webidl.assertBranded(this, type.prototype); + webidl.assertBranded(this, type); label = webidl.converters["UVString?"](label, { prefix: `Failed to set 'label' on '${name}'`, context: "Argument 1", @@ -715,9 +705,7 @@ const validationFilteredPromise = PromisePrototypeCatch( operation, (err) => { - if (ObjectPrototypeIsPrototypeOf.prototype(GPUValidationError, err)) { - return PromiseReject(err); - } + if (err instanceof GPUValidationError) return PromiseReject(err); return PromiseResolve(); }, ); @@ -740,9 +728,7 @@ ); const oomScope = oomStack[oomStack.length - 1]; const oomFilteredPromise = PromisePrototypeCatch(operation, (err) => { - if (ObjectPrototypeIsPrototypeOf(GPUOutOfMemoryErrorPrototype, err)) { - return PromiseReject(err); - } + if (err instanceof GPUOutOfMemoryError) return PromiseReject(err); return PromiseResolve(); }); if (oomScope) { @@ -798,15 +784,15 @@ } get features() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); return this[_device].features; } get limits() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); return this[_device].limits; } get queue() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); return this[_queue]; } @@ -816,7 +802,7 @@ } destroy() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); this[_cleanup](); } @@ -825,7 +811,7 @@ * @returns {GPUBuffer} */ createBuffer(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createBuffer' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUBufferDescriptor(descriptor, { @@ -872,7 +858,7 @@ * @returns {GPUTexture} */ createTexture(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createTexture' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUTextureDescriptor(descriptor, { @@ -901,7 +887,7 @@ * @returns {GPUSampler} */ createSampler(descriptor = {}) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createSampler' on 'GPUDevice'"; descriptor = webidl.converters.GPUSamplerDescriptor(descriptor, { prefix, @@ -928,7 +914,7 @@ * @returns {GPUBindGroupLayout} */ createBindGroupLayout(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createBindGroupLayout' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUBindGroupLayoutDescriptor(descriptor, { @@ -971,7 +957,7 @@ * @returns {GPUPipelineLayout} */ createPipelineLayout(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createPipelineLayout' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUPipelineLayoutDescriptor(descriptor, { @@ -1013,7 +999,7 @@ * @returns {GPUBindGroup} */ createBindGroup(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createBindGroup' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUBindGroupDescriptor(descriptor, { @@ -1033,7 +1019,7 @@ const entries = ArrayPrototypeMap(descriptor.entries, (entry, i) => { const context = `entry ${i + 1}`; const resource = entry.resource; - if (ObjectPrototypeIsPrototypeOf(GPUSamplerPrototype, resource)) { + if (resource instanceof GPUSampler) { const rid = assertResource(resource, { prefix, context, @@ -1048,9 +1034,7 @@ kind: "GPUSampler", resource: rid, }; - } else if ( - ObjectPrototypeIsPrototypeOf(GPUTextureViewPrototype, resource) - ) { + } else if (resource instanceof GPUTextureView) { const rid = assertResource(resource, { prefix, context, @@ -1107,7 +1091,7 @@ * @param {GPUShaderModuleDescriptor} descriptor */ createShaderModule(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createShaderModule' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUShaderModuleDescriptor(descriptor, { @@ -1140,7 +1124,7 @@ * @returns {GPUComputePipeline} */ createComputePipeline(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createComputePipeline' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUComputePipelineDescriptor(descriptor, { @@ -1197,7 +1181,7 @@ * @returns {GPURenderPipeline} */ createRenderPipeline(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createRenderPipeline' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPURenderPipelineDescriptor(descriptor, { @@ -1282,7 +1266,7 @@ * @returns {GPUCommandEncoder} */ createCommandEncoder(descriptor = {}) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createCommandEncoder' on 'GPUDevice'"; descriptor = webidl.converters.GPUCommandEncoderDescriptor(descriptor, { prefix, @@ -1309,7 +1293,7 @@ * @returns {GPURenderBundleEncoder} */ createRenderBundleEncoder(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createRenderBundleEncoder' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -1344,7 +1328,7 @@ * @returns {GPUQuerySet} */ createQuerySet(descriptor) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'createQuerySet' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); descriptor = webidl.converters.GPUQuerySetDescriptor( @@ -1372,7 +1356,7 @@ } get lost() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const device = this[_device]; if (!device) { return PromiseResolve(true); @@ -1387,7 +1371,7 @@ * @param {GPUErrorFilter} filter */ pushErrorScope(filter) { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'pushErrorScope' on 'GPUDevice'"; webidl.requiredArguments(arguments.length, 1, { prefix }); filter = webidl.converters.GPUErrorFilter(filter, { @@ -1403,7 +1387,7 @@ */ // deno-lint-ignore require-await async popErrorScope() { - webidl.assertBranded(this, GPUDevicePrototype); + webidl.assertBranded(this, GPUDevice); const prefix = "Failed to execute 'popErrorScope' on 'GPUDevice'"; const device = assertDevice(this, { prefix, context: "this" }); if (device.isLost) { @@ -1436,7 +1420,6 @@ } } GPUObjectBaseMixin("GPUDevice", GPUDevice); - const GPUDevicePrototype = GPUDevice.prototype; /** * @param {string | null} label @@ -1463,7 +1446,7 @@ * @param {GPUCommandBuffer[]} commandBuffers */ submit(commandBuffers) { - webidl.assertBranded(this, GPUQueue.prototype); + webidl.assertBranded(this, GPUQueue); const prefix = "Failed to execute 'submit' on 'GPUQueue'"; webidl.requiredArguments(arguments.length, 1, { prefix, @@ -1494,7 +1477,7 @@ } onSubmittedWorkDone() { - webidl.assertBranded(this, GPUQueue.prototype); + webidl.assertBranded(this, GPUQueue); return PromiseResolve(); } @@ -1506,7 +1489,7 @@ * @param {number} [size] */ writeBuffer(buffer, bufferOffset, data, dataOffset = 0, size) { - webidl.assertBranded(this, GPUQueue.prototype); + webidl.assertBranded(this, GPUQueue); const prefix = "Failed to execute 'writeBuffer' on 'GPUQueue'"; webidl.requiredArguments(arguments.length, 3, { prefix }); buffer = webidl.converters["GPUBuffer"](buffer, { @@ -1562,7 +1545,7 @@ * @param {GPUExtent3D} size */ writeTexture(destination, data, dataLayout, size) { - webidl.assertBranded(this, GPUQueue.prototype); + webidl.assertBranded(this, GPUQueue); const prefix = "Failed to execute 'writeTexture' on 'GPUQueue'"; webidl.requiredArguments(arguments.length, 4, { prefix }); destination = webidl.converters.GPUImageCopyTexture(destination, { @@ -1719,7 +1702,7 @@ * @param {number} [size] */ async mapAsync(mode, offset = 0, size) { - webidl.assertBranded(this, GPUBuffer.prototype); + webidl.assertBranded(this, GPUBuffer); const prefix = "Failed to execute 'mapAsync' on 'GPUBuffer'"; webidl.requiredArguments(arguments.length, 1, { prefix }); mode = webidl.converters.GPUMapModeFlags(mode, { @@ -1821,7 +1804,7 @@ * @param {number} size */ getMappedRange(offset = 0, size) { - webidl.assertBranded(this, GPUBuffer.prototype); + webidl.assertBranded(this, GPUBuffer); const prefix = "Failed to execute 'getMappedRange' on 'GPUBuffer'"; offset = webidl.converters.GPUSize64(offset, { prefix, @@ -1878,7 +1861,7 @@ } unmap() { - webidl.assertBranded(this, GPUBuffer.prototype); + webidl.assertBranded(this, GPUBuffer); const prefix = "Failed to execute 'unmap' on 'GPUBuffer'"; const device = assertDevice(this, { prefix, context: "this" }); const bufferRid = assertResource(this, { prefix, context: "this" }); @@ -1934,7 +1917,7 @@ } destroy() { - webidl.assertBranded(this, GPUBuffer.prototype); + webidl.assertBranded(this, GPUBuffer); this[_cleanup](); } @@ -2048,7 +2031,7 @@ * @param {GPUTextureViewDescriptor} descriptor */ createView(descriptor = {}) { - webidl.assertBranded(this, GPUTexture.prototype); + webidl.assertBranded(this, GPUTexture); const prefix = "Failed to execute 'createView' on 'GPUTexture'"; webidl.requiredArguments(arguments.length, 0, { prefix }); descriptor = webidl.converters.GPUTextureViewDescriptor(descriptor, { @@ -2073,7 +2056,7 @@ } destroy() { - webidl.assertBranded(this, GPUTexture.prototype); + webidl.assertBranded(this, GPUTexture); this[_cleanup](); } @@ -2153,7 +2136,7 @@ } } GPUObjectBaseMixin("GPUTextureView", GPUTextureView); - const GPUTextureViewPrototype = GPUTextureView.prototype; + /** * @param {string | null} label * @param {InnerGPUDevice} device @@ -2196,7 +2179,7 @@ } } GPUObjectBaseMixin("GPUSampler", GPUSampler); - const GPUSamplerPrototype = GPUSampler.prototype; + /** * @param {string | null} label * @param {InnerGPUDevice} device @@ -2429,7 +2412,7 @@ * @returns {GPUBindGroupLayout} */ getBindGroupLayout(index) { - webidl.assertBranded(this, GPUComputePipelinePrototype); + webidl.assertBranded(this, GPUComputePipeline); const prefix = "Failed to execute 'getBindGroupLayout' on 'GPUComputePipeline'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -2466,7 +2449,6 @@ } } GPUObjectBaseMixin("GPUComputePipeline", GPUComputePipeline); - const GPUComputePipelinePrototype = GPUComputePipeline.prototype; /** * @param {string | null} label @@ -2505,7 +2487,7 @@ * @param {number} index */ getBindGroupLayout(index) { - webidl.assertBranded(this, GPURenderPipelinePrototype); + webidl.assertBranded(this, GPURenderPipeline); const prefix = "Failed to execute 'getBindGroupLayout' on 'GPURenderPipeline'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -2542,7 +2524,6 @@ } } GPUObjectBaseMixin("GPURenderPipeline", GPURenderPipeline); - const GPURenderPipelinePrototype = GPURenderPipeline.prototype; class GPUColorWrite { constructor() { @@ -2616,7 +2597,7 @@ * @return {GPURenderPassEncoder} */ beginRenderPass(descriptor) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'beginRenderPass' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -2766,7 +2747,7 @@ * @param {GPUComputePassDescriptor} descriptor */ beginComputePass(descriptor = {}) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'beginComputePass' on 'GPUCommandEncoder'"; descriptor = webidl.converters.GPUComputePassDescriptor(descriptor, { @@ -2811,7 +2792,7 @@ destinationOffset, size, ) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'copyBufferToBuffer' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 5, { prefix }); @@ -2879,7 +2860,7 @@ * @param {GPUExtent3D} copySize */ copyBufferToTexture(source, destination, copySize) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'copyBufferToTexture' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 3, { prefix }); @@ -2947,7 +2928,7 @@ * @param {GPUExtent3D} copySize */ copyTextureToBuffer(source, destination, copySize) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'copyTextureToBuffer' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 3, { prefix }); @@ -3014,7 +2995,7 @@ * @param {GPUExtent3D} copySize */ copyTextureToTexture(source, destination, copySize) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'copyTextureToTexture' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 3, { prefix }); @@ -3085,7 +3066,7 @@ * @param {GPUSize64} size */ clearBuffer(destination, destinationOffset, size) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'clearBuffer' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 3, { prefix }); destination = webidl.converters.GPUBuffer(destination, { @@ -3125,7 +3106,7 @@ * @param {string} groupLabel */ pushDebugGroup(groupLabel) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'pushDebugGroup' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3149,7 +3130,7 @@ } popDebugGroup() { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'popDebugGroup' on 'GPUCommandEncoder'"; const device = assertDevice(this, { prefix, context: "this" }); const commandEncoderRid = assertResource(this, { @@ -3169,7 +3150,7 @@ * @param {string} markerLabel */ insertDebugMarker(markerLabel) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'insertDebugMarker' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3197,7 +3178,7 @@ * @param {number} queryIndex */ writeTimestamp(querySet, queryIndex) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'writeTimestamp' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -3248,7 +3229,7 @@ destination, destinationOffset, ) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'resolveQuerySet' on 'GPUCommandEncoder'"; webidl.requiredArguments(arguments.length, 5, { prefix }); @@ -3314,7 +3295,7 @@ * @returns {GPUCommandBuffer} */ finish(descriptor = {}) { - webidl.assertBranded(this, GPUCommandEncoderPrototype); + webidl.assertBranded(this, GPUCommandEncoder); const prefix = "Failed to execute 'finish' on 'GPUCommandEncoder'"; descriptor = webidl.converters.GPUCommandBufferDescriptor(descriptor, { prefix, @@ -3351,7 +3332,6 @@ } } GPUObjectBaseMixin("GPUCommandEncoder", GPUCommandEncoder); - const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype; const _encoder = Symbol("[[encoder]]"); @@ -3398,7 +3378,7 @@ * @param {number} maxDepth */ setViewport(x, y, width, height, minDepth, maxDepth) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setViewport' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 6, { prefix }); @@ -3444,7 +3424,7 @@ * @param {number} height */ setScissorRect(x, y, width, height) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setScissorRect' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 4, { prefix }); @@ -3486,7 +3466,7 @@ * @param {GPUColor} color */ setBlendConstant(color) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setBlendConstant' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3513,7 +3493,7 @@ * @param {number} reference */ setStencilReference(reference) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setStencilReference' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3549,7 +3529,7 @@ * @param {number} queryIndex */ beginPipelineStatisticsQuery(querySet, queryIndex) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'beginPipelineStatisticsQuery' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -3587,7 +3567,7 @@ } endPipelineStatisticsQuery() { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'endPipelineStatisticsQuery' on 'GPURenderPassEncoder'"; assertDevice(this[_encoder], { @@ -3609,7 +3589,7 @@ * @param {number} queryIndex */ writeTimestamp(querySet, queryIndex) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'writeTimestamp' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -3650,7 +3630,7 @@ * @param {GPURenderBundle[]} bundles */ executeBundles(bundles) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'executeBundles' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3684,7 +3664,7 @@ } endPass() { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'endPass' on 'GPURenderPassEncoder'"; const device = assertDevice(this[_encoder], { prefix, @@ -3711,7 +3691,7 @@ dynamicOffsetsDataStart, dynamicOffsetsDataLength, ) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setBindGroup' on 'GPURenderPassEncoder'"; const device = assertDevice(this[_encoder], { @@ -3732,12 +3712,7 @@ resourceContext: "Argument 2", selfContext: "this", }); - if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) - ) { + if (!(dynamicOffsetsData instanceof Uint32Array)) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; @@ -3756,7 +3731,7 @@ * @param {string} groupLabel */ pushDebugGroup(groupLabel) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'pushDebugGroup' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3780,7 +3755,7 @@ } popDebugGroup() { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'popDebugGroup' on 'GPURenderPassEncoder'"; assertDevice(this[_encoder], { @@ -3801,7 +3776,7 @@ * @param {string} markerLabel */ insertDebugMarker(markerLabel) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'insertDebugMarker' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3828,7 +3803,7 @@ * @param {GPURenderPipeline} pipeline */ setPipeline(pipeline) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setPipeline' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -3867,7 +3842,7 @@ * @param {number} size */ setIndexBuffer(buffer, indexFormat, offset = 0, size) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setIndexBuffer' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -3923,7 +3898,7 @@ * @param {number} size */ setVertexBuffer(slot, buffer, offset = 0, size) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'setVertexBuffer' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -3979,7 +3954,7 @@ * @param {number} firstInstance */ draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'draw' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); vertexCount = webidl.converters.GPUSize32(vertexCount, { @@ -4030,7 +4005,7 @@ baseVertex = 0, firstInstance = 0, ) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'drawIndexed' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4078,7 +4053,7 @@ * @param {number} indirectOffset */ drawIndirect(indirectBuffer, indirectOffset) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'drawIndirect' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4120,7 +4095,7 @@ * @param {number} indirectOffset */ drawIndexedIndirect(indirectBuffer, indirectOffset) { - webidl.assertBranded(this, GPURenderPassEncoderPrototype); + webidl.assertBranded(this, GPURenderPassEncoder); const prefix = "Failed to execute 'drawIndirect' on 'GPURenderPassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4166,7 +4141,6 @@ } } GPUObjectBaseMixin("GPURenderPassEncoder", GPURenderPassEncoder); - const GPURenderPassEncoderPrototype = GPURenderPassEncoder.prototype; /** * @param {string | null} label @@ -4207,7 +4181,7 @@ * @param {GPUComputePipeline} pipeline */ setPipeline(pipeline) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'setPipeline' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4245,7 +4219,7 @@ * @param {number} z */ dispatch(x, y = 1, z = 1) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'dispatch' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); x = webidl.converters.GPUSize32(x, { prefix, context: "Argument 1" }); @@ -4273,7 +4247,7 @@ * @param {number} indirectOffset */ dispatchIndirect(indirectBuffer, indirectOffset) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'dispatchIndirect' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4315,7 +4289,7 @@ * @param {number} queryIndex */ beginPipelineStatisticsQuery(querySet, queryIndex) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'beginPipelineStatisticsQuery' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4356,7 +4330,7 @@ } endPipelineStatisticsQuery() { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'endPipelineStatisticsQuery' on 'GPUComputePassEncoder'"; assertDevice(this[_encoder], { @@ -4378,7 +4352,7 @@ * @param {number} queryIndex */ writeTimestamp(querySet, queryIndex) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'writeTimestamp' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4416,7 +4390,7 @@ } endPass() { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'endPass' on 'GPUComputePassEncoder'"; const device = assertDevice(this[_encoder], { prefix, @@ -4443,7 +4417,7 @@ dynamicOffsetsDataStart, dynamicOffsetsDataLength, ) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'"; const device = assertDevice(this[_encoder], { @@ -4464,12 +4438,7 @@ resourceContext: "Argument 2", selfContext: "this", }); - if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) - ) { + if (!(dynamicOffsetsData instanceof Uint32Array)) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; @@ -4488,7 +4457,7 @@ * @param {string} groupLabel */ pushDebugGroup(groupLabel) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'pushDebugGroup' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4512,7 +4481,7 @@ } popDebugGroup() { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'popDebugGroup' on 'GPUComputePassEncoder'"; assertDevice(this[_encoder], { @@ -4533,7 +4502,7 @@ * @param {string} markerLabel */ insertDebugMarker(markerLabel) { - webidl.assertBranded(this, GPUComputePassEncoderPrototype); + webidl.assertBranded(this, GPUComputePassEncoder); const prefix = "Failed to execute 'insertDebugMarker' on 'GPUComputePassEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4565,7 +4534,6 @@ } } GPUObjectBaseMixin("GPUComputePassEncoder", GPUComputePassEncoder); - const GPUComputePassEncoderPrototype = GPUComputePassEncoder.prototype; /** * @param {string | null} label @@ -4649,7 +4617,7 @@ * @param {GPURenderBundleDescriptor} descriptor */ finish(descriptor = {}) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'finish' on 'GPURenderBundleEncoder'"; descriptor = webidl.converters.GPURenderBundleDescriptor(descriptor, { prefix, @@ -4687,7 +4655,7 @@ dynamicOffsetsDataStart, dynamicOffsetsDataLength, ) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'setBindGroup' on 'GPURenderBundleEncoder'"; const device = assertDevice(this, { prefix, context: "this" }); @@ -4704,12 +4672,7 @@ resourceContext: "Argument 2", selfContext: "this", }); - if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) - ) { + if (!(dynamicOffsetsData instanceof Uint32Array)) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; @@ -4728,7 +4691,7 @@ * @param {string} groupLabel */ pushDebugGroup(groupLabel) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'pushDebugGroup' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4748,7 +4711,7 @@ } popDebugGroup() { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'popDebugGroup' on 'GPURenderBundleEncoder'"; assertDevice(this, { prefix, context: "this" }); @@ -4765,7 +4728,7 @@ * @param {string} markerLabel */ insertDebugMarker(markerLabel) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'insertDebugMarker' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4788,7 +4751,7 @@ * @param {GPURenderPipeline} pipeline */ setPipeline(pipeline) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'setPipeline' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -4823,7 +4786,7 @@ * @param {number} size */ setIndexBuffer(buffer, indexFormat, offset = 0, size = 0) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'setIndexBuffer' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4873,7 +4836,7 @@ * @param {number} size */ setVertexBuffer(slot, buffer, offset = 0, size = 0) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'setVertexBuffer' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -4923,7 +4886,7 @@ * @param {number} firstInstance */ draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'draw' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); vertexCount = webidl.converters.GPUSize32(vertexCount, { @@ -4970,7 +4933,7 @@ baseVertex = 0, firstInstance = 0, ) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'drawIndexed' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 1, { prefix }); @@ -5014,7 +4977,7 @@ * @param {number} indirectOffset */ drawIndirect(indirectBuffer, indirectOffset) { - webidl.assertBranded(this, GPURenderBundleEncoder.prototype); + webidl.assertBranded(this, GPURenderBundleEncoder); const prefix = "Failed to execute 'drawIndirect' on 'GPURenderBundleEncoder'"; webidl.requiredArguments(arguments.length, 2, { prefix }); @@ -5145,7 +5108,7 @@ } destroy() { - webidl.assertBranded(this, GPUQuerySetPrototype); + webidl.assertBranded(this, GPUQuerySet); this[_cleanup](); } @@ -5158,7 +5121,6 @@ } } GPUObjectBaseMixin("GPUQuerySet", GPUQuerySet); - const GPUQuerySetPrototype = GPUQuerySet.prototype; window.__bootstrap.webgpu = { gpu: webidl.createBranded(GPU), diff --git a/ext/webgpu/02_idl_types.js b/ext/webgpu/02_idl_types.js index dd19f40271..bc92bebab0 100644 --- a/ext/webgpu/02_idl_types.js +++ b/ext/webgpu/02_idl_types.js @@ -56,13 +56,13 @@ // INTERFACE: GPUSupportedLimits webidl.converters.GPUSupportedLimits = webidl.createInterfaceConverter( "GPUSupportedLimits", - GPUSupportedLimits.prototype, + GPUSupportedLimits, ); // INTERFACE: GPUSupportedFeatures webidl.converters.GPUSupportedFeatures = webidl.createInterfaceConverter( "GPUSupportedFeatures", - GPUSupportedFeatures.prototype, + GPUSupportedFeatures, ); // ENUM: GPUPredefinedColorSpace @@ -72,7 +72,7 @@ ); // INTERFACE: GPU - webidl.converters.GPU = webidl.createInterfaceConverter("GPU", GPU.prototype); + webidl.converters.GPU = webidl.createInterfaceConverter("GPU", GPU); // ENUM: GPUPowerPreference webidl.converters["GPUPowerPreference"] = webidl.createEnumConverter( @@ -104,7 +104,7 @@ // INTERFACE: GPUAdapter webidl.converters.GPUAdapter = webidl.createInterfaceConverter( "GPUAdapter", - GPUAdapter.prototype, + GPUAdapter, ); // ENUM: GPUFeatureName @@ -178,13 +178,13 @@ // INTERFACE: GPUDevice webidl.converters.GPUDevice = webidl.createInterfaceConverter( "GPUDevice", - GPUDevice.prototype, + GPUDevice, ); // INTERFACE: GPUBuffer webidl.converters.GPUBuffer = webidl.createInterfaceConverter( "GPUBuffer", - GPUBuffer.prototype, + GPUBuffer, ); // TYPEDEF: GPUSize64 @@ -218,7 +218,7 @@ // INTERFACE: GPUBufferUsage webidl.converters.GPUBufferUsage = webidl.createInterfaceConverter( "GPUBufferUsage", - GPUBufferUsage.prototype, + GPUBufferUsage, ); // TYPEDEF: GPUMapModeFlags @@ -228,13 +228,13 @@ // INTERFACE: GPUMapMode webidl.converters.GPUMapMode = webidl.createInterfaceConverter( "GPUMapMode", - GPUMapMode.prototype, + GPUMapMode, ); // INTERFACE: GPUTexture webidl.converters.GPUTexture = webidl.createInterfaceConverter( "GPUTexture", - GPUTexture.prototype, + GPUTexture, ); // TYPEDEF: GPUIntegerCoordinate @@ -444,13 +444,13 @@ // INTERFACE: GPUTextureUsage webidl.converters.GPUTextureUsage = webidl.createInterfaceConverter( "GPUTextureUsage", - GPUTextureUsage.prototype, + GPUTextureUsage, ); // INTERFACE: GPUTextureView webidl.converters.GPUTextureView = webidl.createInterfaceConverter( "GPUTextureView", - GPUTextureView.prototype, + GPUTextureView, ); // ENUM: GPUTextureViewDimension @@ -517,7 +517,7 @@ // INTERFACE: GPUSampler webidl.converters.GPUSampler = webidl.createInterfaceConverter( "GPUSampler", - GPUSampler.prototype, + GPUSampler, ); // ENUM: GPUAddressMode @@ -613,7 +613,7 @@ // INTERFACE: GPUBindGroupLayout webidl.converters.GPUBindGroupLayout = webidl.createInterfaceConverter( "GPUBindGroupLayout", - GPUBindGroupLayout.prototype, + GPUBindGroupLayout, ); // TYPEDEF: GPUIndex32 @@ -796,13 +796,13 @@ // INTERFACE: GPUShaderStage webidl.converters.GPUShaderStage = webidl.createInterfaceConverter( "GPUShaderStage", - GPUShaderStage.prototype, + GPUShaderStage, ); // INTERFACE: GPUBindGroup webidl.converters.GPUBindGroup = webidl.createInterfaceConverter( "GPUBindGroup", - GPUBindGroup.prototype, + GPUBindGroup, ); // DICTIONARY: GPUBufferBinding @@ -871,7 +871,7 @@ // INTERFACE: GPUPipelineLayout webidl.converters.GPUPipelineLayout = webidl.createInterfaceConverter( "GPUPipelineLayout", - GPUPipelineLayout.prototype, + GPUPipelineLayout, ); // DICTIONARY: GPUPipelineLayoutDescriptor @@ -894,7 +894,7 @@ // INTERFACE: GPUShaderModule webidl.converters.GPUShaderModule = webidl.createInterfaceConverter( "GPUShaderModule", - GPUShaderModule.prototype, + GPUShaderModule, ); // DICTIONARY: GPUShaderModuleDescriptor @@ -926,13 +926,13 @@ // // INTERFACE: GPUCompilationMessage // webidl.converters.GPUCompilationMessage = webidl.createInterfaceConverter( // "GPUCompilationMessage", - // GPUCompilationMessage.prototype, + // GPUCompilationMessage, // ); // // INTERFACE: GPUCompilationInfo // webidl.converters.GPUCompilationInfo = webidl.createInterfaceConverter( // "GPUCompilationInfo", - // GPUCompilationInfo.prototype, + // GPUCompilationInfo, // ); // DICTIONARY: GPUPipelineDescriptorBase @@ -981,7 +981,7 @@ // INTERFACE: GPUComputePipeline webidl.converters.GPUComputePipeline = webidl.createInterfaceConverter( "GPUComputePipeline", - GPUComputePipeline.prototype, + GPUComputePipeline, ); // DICTIONARY: GPUComputePipelineDescriptor @@ -1003,7 +1003,7 @@ // INTERFACE: GPURenderPipeline webidl.converters.GPURenderPipeline = webidl.createInterfaceConverter( "GPURenderPipeline", - GPURenderPipeline.prototype, + GPURenderPipeline, ); // ENUM: GPUVertexStepMode @@ -1476,13 +1476,13 @@ // INTERFACE: GPUColorWrite webidl.converters.GPUColorWrite = webidl.createInterfaceConverter( "GPUColorWrite", - GPUColorWrite.prototype, + GPUColorWrite, ); // INTERFACE: GPUCommandBuffer webidl.converters.GPUCommandBuffer = webidl.createInterfaceConverter( "GPUCommandBuffer", - GPUCommandBuffer.prototype, + GPUCommandBuffer, ); webidl.converters["sequence"] = webidl .createSequenceConverter(webidl.converters["GPUCommandBuffer"]); @@ -1499,7 +1499,7 @@ // INTERFACE: GPUCommandEncoder webidl.converters.GPUCommandEncoder = webidl.createInterfaceConverter( "GPUCommandEncoder", - GPUCommandEncoder.prototype, + GPUCommandEncoder, ); // DICTIONARY: GPUCommandEncoderDescriptor @@ -1654,7 +1654,7 @@ // INTERFACE: GPUComputePassEncoder webidl.converters.GPUComputePassEncoder = webidl.createInterfaceConverter( "GPUComputePassEncoder", - GPUComputePassEncoder.prototype, + GPUComputePassEncoder, ); // DICTIONARY: GPUComputePassDescriptor @@ -1669,7 +1669,7 @@ // INTERFACE: GPURenderPassEncoder webidl.converters.GPURenderPassEncoder = webidl.createInterfaceConverter( "GPURenderPassEncoder", - GPURenderPassEncoder.prototype, + GPURenderPassEncoder, ); // ENUM: GPULoadOp @@ -1787,7 +1787,7 @@ // INTERFACE: GPUQuerySet webidl.converters.GPUQuerySet = webidl.createInterfaceConverter( "GPUQuerySet", - GPUQuerySet.prototype, + GPUQuerySet, ); // DICTIONARY: GPURenderPassDescriptor @@ -1815,7 +1815,7 @@ // INTERFACE: GPURenderBundle webidl.converters.GPURenderBundle = webidl.createInterfaceConverter( "GPURenderBundle", - GPURenderBundle.prototype, + GPURenderBundle, ); webidl.converters["sequence"] = webidl .createSequenceConverter(webidl.converters["GPURenderBundle"]); @@ -1832,7 +1832,7 @@ // INTERFACE: GPURenderBundleEncoder webidl.converters.GPURenderBundleEncoder = webidl.createInterfaceConverter( "GPURenderBundleEncoder", - GPURenderBundleEncoder.prototype, + GPURenderBundleEncoder, ); // DICTIONARY: GPURenderPassLayout @@ -1885,7 +1885,7 @@ // INTERFACE: GPUQueue webidl.converters.GPUQueue = webidl.createInterfaceConverter( "GPUQueue", - GPUQueue.prototype, + GPUQueue, ); // ENUM: GPUQueryType @@ -1945,7 +1945,7 @@ // // INTERFACE: GPUDeviceLostInfo // webidl.converters.GPUDeviceLostInfo = webidl.createInterfaceConverter( // "GPUDeviceLostInfo", - // GPUDeviceLostInfo.prototype, + // GPUDeviceLostInfo, // ); // ENUM: GPUErrorFilter @@ -1960,13 +1960,13 @@ // INTERFACE: GPUOutOfMemoryError webidl.converters.GPUOutOfMemoryError = webidl.createInterfaceConverter( "GPUOutOfMemoryError", - GPUOutOfMemoryError.prototype, + GPUOutOfMemoryError, ); // INTERFACE: GPUValidationError webidl.converters.GPUValidationError = webidl.createInterfaceConverter( "GPUValidationError", - GPUValidationError.prototype, + GPUValidationError, ); // TYPEDEF: GPUError @@ -1975,7 +1975,7 @@ // // INTERFACE: GPUUncapturedErrorEvent // webidl.converters.GPUUncapturedErrorEvent = webidl.createInterfaceConverter( // "GPUUncapturedErrorEvent", - // GPUUncapturedErrorEvent.prototype, + // GPUUncapturedErrorEvent, // ); // DICTIONARY: GPUUncapturedErrorEventInit diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index de3221081b..668c141cb0 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -11,7 +11,7 @@ ((window) => { const core = window.Deno.core; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypeForEach, ArrayPrototypePush, @@ -20,6 +20,7 @@ BigInt, BigIntAsIntN, BigIntAsUintN, + DataView, Float32Array, Float64Array, FunctionPrototypeBind, @@ -49,7 +50,6 @@ ObjectGetOwnPropertyDescriptors, ObjectGetPrototypeOf, ObjectPrototypeHasOwnProperty, - ObjectPrototypeIsPrototypeOf, ObjectIs, PromisePrototypeThen, PromiseReject, @@ -434,11 +434,11 @@ } function isNonSharedArrayBuffer(V) { - return ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V); + return V instanceof ArrayBuffer; } function isSharedArrayBuffer(V) { - return ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V); + return V instanceof SharedArrayBuffer; } converters.ArrayBuffer = (V, opts = {}) => { @@ -457,7 +457,7 @@ }; converters.DataView = (V, opts = {}) => { - if (!(ObjectPrototypeIsPrototypeOf(DataViewPrototype, V))) { + if (!(V instanceof DataView)) { throw makeException(TypeError, "is not a DataView", opts); } @@ -862,7 +862,7 @@ function createInterfaceConverter(name, prototype) { return (V, opts) => { - if (!ObjectPrototypeIsPrototypeOf(prototype, V) || V[brand] !== brand) { + if (!(V instanceof prototype) || V[brand] !== brand) { throw makeException(TypeError, `is not of type ${name}.`, opts); } return V; @@ -877,9 +877,7 @@ } function assertBranded(self, prototype) { - if ( - !ObjectPrototypeIsPrototypeOf(prototype, self) || self[brand] !== brand - ) { + if (!(self instanceof prototype) || self[brand] !== brand) { throw new TypeError("Illegal invocation"); } } @@ -946,7 +944,7 @@ } function entries() { - assertBranded(this, prototype.prototype); + assertBranded(this, prototype); return createDefaultIterator(this, "key+value"); } @@ -965,7 +963,7 @@ }, keys: { value: function keys() { - assertBranded(this, prototype.prototype); + assertBranded(this, prototype); return createDefaultIterator(this, "key"); }, writable: true, @@ -974,7 +972,7 @@ }, values: { value: function values() { - assertBranded(this, prototype.prototype); + assertBranded(this, prototype); return createDefaultIterator(this, "value"); }, writable: true, @@ -983,7 +981,7 @@ }, forEach: { value: function forEach(idlCallback, thisArg = undefined) { - assertBranded(this, prototype.prototype); + assertBranded(this, prototype); const prefix = `Failed to execute 'forEach' on '${name}'`; requiredArguments(arguments.length, 1, { prefix }); idlCallback = converters["Function"](idlCallback, { diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 2c6337eef9..d04d7dab36 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -10,31 +10,29 @@ const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra; const { DOMException } = window.__bootstrap.domException; const { defineEventHandler } = window.__bootstrap.event; - const { Blob, BlobPrototype } = globalThis.__bootstrap.file; + const { Blob } = globalThis.__bootstrap.file; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypeJoin, - ArrayPrototypeMap, - ArrayPrototypeSome, DataView, ErrorPrototypeToString, - ObjectDefineProperties, - ObjectPrototypeIsPrototypeOf, - PromisePrototypeThen, - RegExpPrototypeTest, Set, - String, - StringPrototypeEndsWith, - StringPrototypeToLowerCase, Symbol, - SymbolIterator, + String, + StringPrototypeToLowerCase, + StringPrototypeEndsWith, + RegExpPrototypeTest, + ObjectDefineProperties, + ArrayPrototypeMap, + ArrayPrototypeSome, + PromisePrototypeThen, } = window.__bootstrap.primordials; webidl.converters["sequence or DOMString"] = (V, opts) => { // Union for (sequence or DOMString) if (webidl.type(V) === "Object" && V !== null) { - if (V[SymbolIterator] !== undefined) { + if (V[Symbol.iterator] !== undefined) { return webidl.converters["sequence"](V, opts); } } @@ -43,15 +41,12 @@ webidl.converters["WebSocketSend"] = (V, opts) => { // Union for (Blob or ArrayBufferView or ArrayBuffer or USVString) - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { + if (V instanceof Blob) { return webidl.converters["Blob"](V, opts); } if (typeof V === "object") { // TODO(littledivy): use primordial for SharedArrayBuffer - if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) - ) { + if (V instanceof ArrayBuffer || V instanceof SharedArrayBuffer) { return webidl.converters["ArrayBuffer"](V, opts); } if (ArrayBufferIsView(V)) { @@ -84,52 +79,52 @@ [_readyState] = CONNECTING; get readyState() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_readyState]; } get CONNECTING() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CONNECTING; } get OPEN() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return OPEN; } get CLOSING() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CLOSING; } get CLOSED() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CLOSED; } [_extensions] = ""; get extensions() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_extensions]; } [_protocol] = ""; get protocol() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_protocol]; } [_url] = ""; get url() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_url]; } [_binaryType] = "blob"; get binaryType() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_binaryType]; } set binaryType(value) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); value = webidl.converters.DOMString(value, { prefix: "Failed to set 'binaryType' on 'WebSocket'", }); @@ -140,7 +135,7 @@ [_bufferedAmount] = 0; get bufferedAmount() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_bufferedAmount]; } @@ -272,7 +267,7 @@ } send(data) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); const prefix = "Failed to execute 'send' on 'WebSocket'"; webidl.requiredArguments(arguments.length, 1, { @@ -300,14 +295,14 @@ ); }; - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) { + if (data instanceof Blob) { PromisePrototypeThen( data.slice().arrayBuffer(), (ab) => sendTypedArray(new DataView(ab)), ); } else if (ArrayBufferIsView(data)) { sendTypedArray(data); - } else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) { + } else if (data instanceof ArrayBuffer) { sendTypedArray(new DataView(data)); } else { const string = String(data); @@ -326,7 +321,7 @@ } close(code = undefined, reason = undefined) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); const prefix = "Failed to execute 'close' on 'WebSocket'"; if (code !== undefined) { @@ -519,7 +514,6 @@ defineEventHandler(WebSocket.prototype, "open"); webidl.configurePrototype(WebSocket); - const WebSocketPrototype = WebSocket.prototype; window.__bootstrap.webSocket = { WebSocket, diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index 0f4cecaa5d..0a14657e9b 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -11,19 +11,18 @@ const { add, remove } = window.__bootstrap.abortSignal; const { - ArrayPrototypeJoin, - ArrayPrototypeMap, - Error, - ObjectPrototypeIsPrototypeOf, - PromisePrototypeCatch, - PromisePrototypeThen, - Set, StringPrototypeEndsWith, StringPrototypeToLowerCase, Symbol, SymbolFor, + Set, + ArrayPrototypeMap, + ArrayPrototypeJoin, + PromisePrototypeThen, + PromisePrototypeCatch, + Uint8Array, TypeError, - Uint8ArrayPrototype, + Error, } = window.__bootstrap.primordials; webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter( @@ -71,7 +70,7 @@ [_url]; get url() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_url]; } @@ -196,9 +195,7 @@ kind: "text", value: chunk, }); - } else if ( - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk) - ) { + } else if (chunk instanceof Uint8Array) { await core.opAsync("op_ws_send", this[_rid], { kind: "binary", value: chunk, @@ -299,7 +296,7 @@ } }, (err) => { - if (ObjectPrototypeIsPrototypeOf(core.InterruptedPrototype, err)) { + if (err instanceof core.Interrupted) { // The signal was aborted. err = options.signal.reason; } else { @@ -314,19 +311,19 @@ [_connection] = new Deferred(); get connection() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_connection].promise; } [_earlyClose] = false; [_closed] = new Deferred(); get closed() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_closed].promise; } close(closeInfo) { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); closeInfo = webidl.converters.WebSocketCloseInfo(closeInfo, { prefix: "Failed to execute 'close' on 'WebSocketStream'", context: "Argument 1", @@ -384,7 +381,5 @@ } } - const WebSocketStreamPrototype = WebSocketStream.prototype; - window.__bootstrap.webSocket.WebSocketStream = WebSocketStream; })(this); diff --git a/ext/webstorage/01_webstorage.js b/ext/webstorage/01_webstorage.js index 7ed7b6618a..e71aafade9 100644 --- a/ext/webstorage/01_webstorage.js +++ b/ext/webstorage/01_webstorage.js @@ -25,12 +25,12 @@ } get length() { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); return core.opSync("op_webstorage_length", this[_persistent]); } key(index) { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); const prefix = "Failed to execute 'key' on 'Storage'"; webidl.requiredArguments(arguments.length, 1, { prefix }); index = webidl.converters["unsigned long"](index, { @@ -42,7 +42,7 @@ } setItem(key, value) { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); const prefix = "Failed to execute 'setItem' on 'Storage'"; webidl.requiredArguments(arguments.length, 2, { prefix }); key = webidl.converters.DOMString(key, { @@ -61,7 +61,7 @@ } getItem(key) { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); const prefix = "Failed to execute 'getItem' on 'Storage'"; webidl.requiredArguments(arguments.length, 1, { prefix }); key = webidl.converters.DOMString(key, { @@ -73,7 +73,7 @@ } removeItem(key) { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); const prefix = "Failed to execute 'removeItem' on 'Storage'"; webidl.requiredArguments(arguments.length, 1, { prefix }); key = webidl.converters.DOMString(key, { @@ -85,13 +85,11 @@ } clear() { - webidl.assertBranded(this, StoragePrototype); + webidl.assertBranded(this, Storage); core.opSync("op_webstorage_clear", this[_persistent]); } } - const StoragePrototype = Storage.prototype; - function createStorage(persistent) { const storage = webidl.createBranded(Storage); storage[_persistent] = persistent; diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index e934c4f0e9..9b255615ee 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -3,15 +3,14 @@ ((window) => { const { - decodeURIComponent, - Error, - ObjectPrototypeIsPrototypeOf, - Promise, StringPrototypeReplace, TypeError, + Promise, + decodeURIComponent, + Error, } = window.__bootstrap.primordials; const { build } = window.__bootstrap.build; - const { URLPrototype } = window.__bootstrap.url; + const { URL } = window.__bootstrap.url; let logDebug = false; let logSource = "JS"; @@ -94,7 +93,7 @@ } function pathFromURL(pathOrUrl) { - if (ObjectPrototypeIsPrototypeOf(URLPrototype, pathOrUrl)) { + if (pathOrUrl instanceof URL) { if (pathOrUrl.protocol != "file:") { throw new TypeError("Must be a file URL."); } diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js index 80e85a3a15..4510004d69 100644 --- a/runtime/js/11_workers.js +++ b/runtime/js/11_workers.js @@ -5,7 +5,6 @@ const core = window.Deno.core; const { Error, - ObjectPrototypeIsPrototypeOf, StringPrototypeStartsWith, String, SymbolIterator, @@ -17,11 +16,8 @@ const { serializePermissions } = window.__bootstrap.permissions; const { log } = window.__bootstrap.util; const { defineEventHandler } = window.__bootstrap.event; - const { - deserializeJsMessageData, - serializeJsMessageData, - MessagePortPrototype, - } = window.__bootstrap.messagePort; + const { deserializeJsMessageData, serializeJsMessageData } = + window.__bootstrap.messagePort; function createWorker( specifier, @@ -203,9 +199,7 @@ const event = new MessageEvent("message", { cancelable: false, data: message, - ports: transferables.filter((t) => - ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t) - ), + ports: transferables.filter((t) => t instanceof MessagePort), }); this.dispatchEvent(event); } diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js index 51f2c411e2..bdd575f19f 100644 --- a/runtime/js/30_fs.js +++ b/runtime/js/30_fs.js @@ -5,9 +5,7 @@ const core = window.Deno.core; const { Date, - DatePrototype, MathTrunc, - ObjectPrototypeIsPrototypeOf, SymbolAsyncIterator, SymbolIterator, } = window.__bootstrap.primordials; @@ -279,7 +277,7 @@ } function toUnixTimeFromEpoch(value) { - if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) { + if (value instanceof Date) { const time = value.valueOf(); const seconds = MathTrunc(time / 1e3); const nanoseconds = MathTrunc(time - (seconds * 1e3)) * 1e6; diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js index 939d3ac7b5..27825eaacf 100644 --- a/runtime/js/40_fs_events.js +++ b/runtime/js/40_fs_events.js @@ -3,10 +3,9 @@ ((window) => { const core = window.Deno.core; - const { BadResourcePrototype, InterruptedPrototype } = core; + const { errors } = window.__bootstrap.errors; const { ArrayIsArray, - ObjectPrototypeIsPrototypeOf, PromiseResolve, SymbolAsyncIterator, } = window.__bootstrap.primordials; @@ -29,11 +28,9 @@ ? { value, done: false } : { value: undefined, done: true }; } catch (error) { - if (ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error)) { + if (error instanceof errors.BadResource) { return { value: undefined, done: true }; - } else if ( - ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error) - ) { + } else if (error instanceof errors.Interrupted) { return { value: undefined, done: true }; } throw error; diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 62eb1e9a98..5979a523ee 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -9,15 +9,14 @@ const { serializePermissions } = window.__bootstrap.permissions; const { assert } = window.__bootstrap.util; const { - AggregateErrorPrototype, + AggregateError, ArrayPrototypeFilter, ArrayPrototypePush, ArrayPrototypeShift, ArrayPrototypeSome, DateNow, Error, - FunctionPrototype, - ObjectPrototypeIsPrototypeOf, + Function, Number, ObjectKeys, Promise, @@ -531,7 +530,7 @@ finishing test case.`; } function formatError(error) { - if (ObjectPrototypeIsPrototypeOf(AggregateErrorPrototype, error)) { + if (error instanceof AggregateError) { const message = error .errors .map((error) => @@ -985,7 +984,7 @@ finishing test case.`; /** @returns {TestStepDefinition} */ function getDefinition() { if (typeof nameOrTestDefinition === "string") { - if (!(ObjectPrototypeIsPrototypeOf(FunctionPrototype, fn))) { + if (!(fn instanceof Function)) { throw new TypeError("Expected function for second argument."); } return { diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 5a4d7e9894..ba2b367053 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -16,7 +16,6 @@ delete Object.prototype.__proto__; ObjectDefineProperty, ObjectDefineProperties, ObjectFreeze, - ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, PromiseResolve, Symbol, @@ -143,9 +142,7 @@ delete Object.prototype.__proto__; const msgEvent = new MessageEvent("message", { cancelable: false, data: message, - ports: transferables.filter((t) => - ObjectPrototypeIsPrototypeOf(messagePort.MessagePortPrototype, t) - ), + ports: transferables.filter((t) => t instanceof MessagePort), }); try { @@ -314,7 +311,7 @@ delete Object.prototype.__proto__; configurable: true, enumerable: true, get() { - webidl.assertBranded(this, NavigatorPrototype); + webidl.assertBranded(this, Navigator); return webgpu.gpu; }, }, @@ -322,12 +319,11 @@ delete Object.prototype.__proto__; configurable: true, enumerable: true, get() { - webidl.assertBranded(this, NavigatorPrototype); + webidl.assertBranded(this, Navigator); return numCpus; }, }, }); - const NavigatorPrototype = Navigator.prototype; class WorkerNavigator { constructor() { @@ -346,7 +342,7 @@ delete Object.prototype.__proto__; configurable: true, enumerable: true, get() { - webidl.assertBranded(this, WorkerNavigatorPrototype); + webidl.assertBranded(this, WorkerNavigator); return webgpu.gpu; }, }, @@ -354,12 +350,11 @@ delete Object.prototype.__proto__; configurable: true, enumerable: true, get() { - webidl.assertBranded(this, WorkerNavigatorPrototype); + webidl.assertBranded(this, WorkerNavigator); return numCpus; }, }, }); - const WorkerNavigatorPrototype = WorkerNavigator.prototype; // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope const windowOrWorkerGlobalScope = {