diff --git a/lib/web/cache/cache.js b/lib/web/cache/cache.js index 1f41a66a01b..44f3addafa3 100644 --- a/lib/web/cache/cache.js +++ b/lib/web/cache/cache.js @@ -41,7 +41,7 @@ class Cache { } async match (request, options = {}) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.match' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -59,7 +59,7 @@ class Cache { } async matchAll (request = undefined, options = {}) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.matchAll' if (request !== undefined) request = webidl.converters.RequestInfo(request) @@ -69,7 +69,7 @@ class Cache { } async add (request) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.add' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -87,7 +87,7 @@ class Cache { } async addAll (requests) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.addAll' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -257,7 +257,7 @@ class Cache { } async put (request, response) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.put' webidl.argumentLengthCheck(arguments, 2, prefix) @@ -388,7 +388,7 @@ class Cache { } async delete (request, options = {}) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.delete' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -454,7 +454,7 @@ class Cache { * @returns {Promise} */ async keys (request = undefined, options = {}) { - webidl.brandCheck(this, Cache) + webidl.brandCheck(this, webidl.is.Cache) const prefix = 'Cache.keys' @@ -804,6 +804,12 @@ class Cache { // 6. return Object.freeze(responseList) } + + static { + webidl.is.Cache = (arg) => { + return arg != null && typeof arg === 'object' && #relevantRequestResponseList in arg + } + } } Object.defineProperties(Cache.prototype, { diff --git a/lib/web/cache/cachestorage.js b/lib/web/cache/cachestorage.js index c49b1e82ec1..8602dc32b6f 100644 --- a/lib/web/cache/cachestorage.js +++ b/lib/web/cache/cachestorage.js @@ -21,7 +21,7 @@ class CacheStorage { } async match (request, options = {}) { - webidl.brandCheck(this, CacheStorage) + webidl.brandCheck(this, webidl.is.CacheStorage) webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match') request = webidl.converters.RequestInfo(request) @@ -58,7 +58,7 @@ class CacheStorage { * @returns {Promise} */ async has (cacheName) { - webidl.brandCheck(this, CacheStorage) + webidl.brandCheck(this, webidl.is.CacheStorage) const prefix = 'CacheStorage.has' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -76,7 +76,7 @@ class CacheStorage { * @returns {Promise} */ async open (cacheName) { - webidl.brandCheck(this, CacheStorage) + webidl.brandCheck(this, webidl.is.CacheStorage) const prefix = 'CacheStorage.open' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -110,7 +110,7 @@ class CacheStorage { * @returns {Promise} */ async delete (cacheName) { - webidl.brandCheck(this, CacheStorage) + webidl.brandCheck(this, webidl.is.CacheStorage) const prefix = 'CacheStorage.delete' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -125,7 +125,7 @@ class CacheStorage { * @returns {Promise} */ async keys () { - webidl.brandCheck(this, CacheStorage) + webidl.brandCheck(this, webidl.is.CacheStorage) // 2.1 const keys = this.#caches.keys() @@ -133,6 +133,12 @@ class CacheStorage { // 2.2 return [...keys] } + + static { + webidl.is.CacheStorage = (arg) => { + return arg != null && typeof arg === 'object' && #caches in arg + } + } } Object.defineProperties(CacheStorage.prototype, { diff --git a/lib/web/cookies/index.js b/lib/web/cookies/index.js index 8ebff2b1a4c..a612ca86f73 100644 --- a/lib/web/cookies/index.js +++ b/lib/web/cookies/index.js @@ -3,9 +3,19 @@ const { parseSetCookie } = require('./parse') const { stringify } = require('./util') const { webidl } = require('../webidl') -const { Headers } = require('../fetch/headers') -const brandChecks = webidl.brandCheckMultiple([Headers, globalThis.Headers].filter(Boolean)) +const globalHeadersBrandCheck = (arg) => webidl.brandCheck(arg, webidl.util.MakeTypeAssertion(globalThis.Headers)) +const undiciHeadersBrandCheck = (arg) => webidl.brandCheck(arg, webidl.is.Headers) + +function brandCheckHeaders (arg) { + try { + undiciHeadersBrandCheck(arg) + return + } catch { + } + + globalHeadersBrandCheck(arg) +} /** * @typedef {Object} Cookie @@ -28,7 +38,7 @@ const brandChecks = webidl.brandCheckMultiple([Headers, globalThis.Headers].filt function getCookies (headers) { webidl.argumentLengthCheck(arguments, 1, 'getCookies') - brandChecks(headers) + brandCheckHeaders(headers) const cookie = headers.get('cookie') @@ -57,7 +67,7 @@ function getCookies (headers) { * @returns {void} */ function deleteCookie (headers, name, attributes) { - brandChecks(headers) + brandCheckHeaders(headers) const prefix = 'deleteCookie' webidl.argumentLengthCheck(arguments, 2, prefix) @@ -82,7 +92,7 @@ function deleteCookie (headers, name, attributes) { function getSetCookies (headers) { webidl.argumentLengthCheck(arguments, 1, 'getSetCookies') - brandChecks(headers) + brandCheckHeaders(headers) const cookies = headers.getSetCookie() @@ -111,7 +121,7 @@ function parseCookie (cookie) { function setCookie (headers, cookie) { webidl.argumentLengthCheck(arguments, 2, 'setCookie') - brandChecks(headers) + brandCheckHeaders(headers) cookie = webidl.converters.Cookie(cookie) diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index 657c0643ca8..93fb1f23436 100644 --- a/lib/web/eventsource/eventsource.js +++ b/lib/web/eventsource/eventsource.js @@ -191,6 +191,8 @@ class EventSource extends EventTarget { * @readonly */ get readyState () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#readyState } @@ -200,6 +202,8 @@ class EventSource extends EventTarget { * @returns {string} */ get url () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#url } @@ -208,6 +212,8 @@ class EventSource extends EventTarget { * instantiated with CORS credentials set (true), or not (false, the default). */ get withCredentials () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#withCredentials } @@ -363,7 +369,7 @@ class EventSource extends EventTarget { * CLOSED. */ close () { - webidl.brandCheck(this, EventSource) + webidl.brandCheck(this, webidl.is.EventSource) if (this.#readyState === CLOSED) return this.#readyState = CLOSED @@ -372,10 +378,14 @@ class EventSource extends EventTarget { } get onopen () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#events.open } set onopen (fn) { + webidl.brandCheck(this, webidl.is.EventSource) + if (this.#events.open) { this.removeEventListener('open', this.#events.open) } @@ -391,10 +401,14 @@ class EventSource extends EventTarget { } get onmessage () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#events.message } set onmessage (fn) { + webidl.brandCheck(this, webidl.is.EventSource) + if (this.#events.message) { this.removeEventListener('message', this.#events.message) } @@ -410,10 +424,14 @@ class EventSource extends EventTarget { } get onerror () { + webidl.brandCheck(this, webidl.is.EventSource) + return this.#events.error } set onerror (fn) { + webidl.brandCheck(this, webidl.is.EventSource) + if (this.#events.error) { this.removeEventListener('error', this.#events.error) } @@ -427,6 +445,12 @@ class EventSource extends EventTarget { this.#events.error = null } } + + static { + webidl.is.EventSource = (arg) => { + return arg != null && typeof arg === 'object' && #events in arg + } + } } const constantsPropertyDescriptors = { diff --git a/lib/web/fetch/body.js b/lib/web/fetch/body.js index a81ddfba437..6209c12d76b 100644 --- a/lib/web/fetch/body.js +++ b/lib/web/fetch/body.js @@ -293,7 +293,7 @@ function cloneBody (body) { } } -function bodyMixinMethods (instance, getInternalState) { +function bodyMixinMethods (brandCheck, getInternalState) { const methods = { blob () { // The blob() method steps are to return the result of @@ -313,7 +313,7 @@ function bodyMixinMethods (instance, getInternalState) { // Return a Blob whose contents are bytes and type attribute // is mimeType. return new Blob([bytes], { type: mimeType }) - }, instance, getInternalState) + }, brandCheck, getInternalState) }, arrayBuffer () { @@ -323,19 +323,19 @@ function bodyMixinMethods (instance, getInternalState) { // whose contents are bytes. return consumeBody(this, (bytes) => { return new Uint8Array(bytes).buffer - }, instance, getInternalState) + }, brandCheck, getInternalState) }, text () { // The text() method steps are to return the result of running // consume body with this and UTF-8 decode. - return consumeBody(this, utf8DecodeBytes, instance, getInternalState) + return consumeBody(this, utf8DecodeBytes, brandCheck, getInternalState) }, json () { // The json() method steps are to return the result of running // consume body with this and parse JSON from bytes. - return consumeBody(this, parseJSONFromBytes, instance, getInternalState) + return consumeBody(this, parseJSONFromBytes, brandCheck, getInternalState) }, formData () { @@ -383,7 +383,7 @@ function bodyMixinMethods (instance, getInternalState) { throw new TypeError( 'Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".' ) - }, instance, getInternalState) + }, brandCheck, getInternalState) }, bytes () { @@ -392,7 +392,7 @@ function bodyMixinMethods (instance, getInternalState) { // result of creating a Uint8Array from bytes in this’s relevant realm. return consumeBody(this, (bytes) => { return new Uint8Array(bytes) - }, instance, getInternalState) + }, brandCheck, getInternalState) }, textStream () { @@ -442,20 +442,20 @@ function bodyMixinMethods (instance, getInternalState) { return methods } -function mixinBody (prototype, getInternalState) { - Object.assign(prototype.prototype, bodyMixinMethods(prototype, getInternalState)) +function mixinBody (prototype, getInternalState, brandCheck) { + Object.assign(prototype.prototype, bodyMixinMethods(brandCheck, getInternalState)) } /** * @see https://fetch.spec.whatwg.org/#concept-body-consume-body * @param {any} object internal state * @param {(value: unknown) => unknown} convertBytesToJSValue - * @param {any} instance + * @param {import('../../../types/webidl').WebidlIsFunction} brandCheck * @param {(target: any) => any} getInternalState */ -function consumeBody (object, convertBytesToJSValue, instance, getInternalState) { +function consumeBody (object, convertBytesToJSValue, brandCheck, getInternalState) { try { - webidl.brandCheck(object, instance) + webidl.brandCheck(object, brandCheck) } catch (e) { return Promise.reject(e) } diff --git a/lib/web/fetch/formdata.js b/lib/web/fetch/formdata.js index 226bd329587..e7b8c4c3fb2 100644 --- a/lib/web/fetch/formdata.js +++ b/lib/web/fetch/formdata.js @@ -10,6 +10,8 @@ const random = runtimeFeatures.has('crypto') ? require('node:crypto').randomInt : (max) => Math.floor(Math.random() * max) +let getFormDataState, setFormDataState, getFormDataBoundary + // https://xhr.spec.whatwg.org/#formdata class FormData { #state = [] @@ -28,7 +30,7 @@ class FormData { } append (name, value, filename = undefined) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.append' webidl.argumentLengthCheck(arguments, 2, prefix) @@ -56,7 +58,7 @@ class FormData { } delete (name) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.delete' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -69,7 +71,7 @@ class FormData { } get (name) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.get' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -89,7 +91,7 @@ class FormData { } getAll (name) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.getAll' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -106,7 +108,7 @@ class FormData { } has (name) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.has' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -119,7 +121,7 @@ class FormData { } set (name, value, filename = undefined) { - webidl.brandCheck(this, FormData) + webidl.brandCheck(this, webidl.is.FormData) const prefix = 'FormData.set' webidl.argumentLengthCheck(arguments, 2, prefix) @@ -184,40 +186,34 @@ class FormData { return `FormData ${output.slice(output.indexOf(']') + 2)}` } - /** - * @param {FormData} formData - */ - static getFormDataState (formData) { - return formData.#state - } + static { + /** @param {FormData} formData */ + getFormDataState = (formData) => formData.#state - /** - * @param {FormData} formData - * @param {any[]} newState - */ - static setFormDataState (formData, newState) { - formData.#state = newState - } + /** + * @param {FormData} formData + * @param {any[]} newState + */ + setFormDataState = (formData, newState) => { + formData.#state = newState + } - /** - * @param {FormData} formData - * @returns {string | null} - */ - static getFormDataBoundary (formData) { - const boundary = formData.#boundary - if (boundary != null) return boundary + /** + * @param {FormData} formData + * @returns {string | null} + */ + getFormDataBoundary = (formData) => { + // eslint-disable-next-line no-return-assign + return formData.#boundary ??= `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}` + } - // eslint-disable-next-line no-return-assign - return formData.#boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}` + webidl.is.FormData = (arg) => { + return arg != null && typeof arg === 'object' && #state in arg + } } } -const { getFormDataState, setFormDataState, getFormDataBoundary } = FormData -Reflect.deleteProperty(FormData, 'getFormDataState') -Reflect.deleteProperty(FormData, 'setFormDataState') -Reflect.deleteProperty(FormData, 'getFormDataBoundary') - -iteratorMixin('FormData', FormData, getFormDataState, 'name', 'value') +iteratorMixin('FormData', FormData, getFormDataState, 'name', 'value', webidl.is.FormData) Object.defineProperties(FormData.prototype, { append: kEnumerableProperty, @@ -273,6 +269,4 @@ function makeEntry (name, value, filename) { return { name, value } } -webidl.is.FormData = webidl.util.MakeTypeAssertion(FormData) - module.exports = { FormData, makeEntry, setFormDataState, getFormDataBoundary } diff --git a/lib/web/fetch/headers.js b/lib/web/fetch/headers.js index 024d1989588..8f9fdfb327e 100644 --- a/lib/web/fetch/headers.js +++ b/lib/web/fetch/headers.js @@ -423,6 +423,8 @@ class HeadersList { } } +let getHeadersGuard, setHeadersGuard, getHeadersList, setHeadersList + // https://fetch.spec.whatwg.org/#headers-class class Headers { #guard @@ -458,7 +460,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-append append (name, value) { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) webidl.argumentLengthCheck(arguments, 2, 'Headers.append') @@ -471,7 +473,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-delete delete (name) { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) webidl.argumentLengthCheck(arguments, 1, 'Headers.delete') @@ -515,7 +517,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-get get (name) { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) webidl.argumentLengthCheck(arguments, 1, 'Headers.get') @@ -538,7 +540,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-has has (name) { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) webidl.argumentLengthCheck(arguments, 1, 'Headers.has') @@ -561,7 +563,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-set set (name, value) { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) webidl.argumentLengthCheck(arguments, 2, 'Headers.set') @@ -609,7 +611,7 @@ class Headers { // https://fetch.spec.whatwg.org/#dom-headers-getsetcookie getSetCookie () { - webidl.brandCheck(this, Headers) + webidl.brandCheck(this, webidl.is.Headers) // 1. If this’s header list does not contain `Set-Cookie`, then return « ». // 2. Return the values of all headers in this’s header list whose name is @@ -630,37 +632,38 @@ class Headers { return `Headers ${util.formatWithOptions(options, this.#headersList.entries)}` } - static getHeadersGuard (o) { - return o.#guard - } + static { + /** @param {Headers} headers */ + getHeadersGuard = (headers) => headers.#guard - static setHeadersGuard (o, guard) { - o.#guard = guard - } + /** + * @param {Headers} headers + * @param {string} guard + */ + setHeadersGuard = (headers, guard) => { + headers.#guard = guard + } - /** - * @param {Headers} o - */ - static getHeadersList (o) { - return o.#headersList - } + /** + * @param {Headers} headers + */ + getHeadersList = (headers) => headers.#headersList + + /** + * @param {Headers} target + * @param {HeadersList} list + */ + setHeadersList = (target, list) => { + target.#headersList = list + } - /** - * @param {Headers} target - * @param {HeadersList} list - */ - static setHeadersList (target, list) { - target.#headersList = list + webidl.is.Headers = (arg) => { + return arg != null && typeof arg === 'object' && #guard in arg + } } } -const { getHeadersGuard, setHeadersGuard, getHeadersList, setHeadersList } = Headers -Reflect.deleteProperty(Headers, 'getHeadersGuard') -Reflect.deleteProperty(Headers, 'setHeadersGuard') -Reflect.deleteProperty(Headers, 'getHeadersList') -Reflect.deleteProperty(Headers, 'setHeadersList') - -iteratorMixin('Headers', Headers, headersListSortAndCombine, 0, 1) +iteratorMixin('Headers', Headers, headersListSortAndCombine, 0, 1, webidl.is.Headers) Object.defineProperties(Headers.prototype, { append: kEnumerableProperty, diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js index 56945ec02ee..66f8150cb82 100644 --- a/lib/web/fetch/request.js +++ b/lib/web/fetch/request.js @@ -83,6 +83,7 @@ function buildAbort (acRef) { } let patchMethodWarning = false +let setRequestSignal, getRequestDispatcher, setRequestDispatcher, setRequestHeaders, getRequestState, setRequestState, removeRequestAbortListener // https://fetch.spec.whatwg.org/#request-class class Request { @@ -600,7 +601,7 @@ class Request { // Returns request’s HTTP method, which is "GET" by default. get method () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The method getter steps are to return this’s request’s method. return this.#state.method @@ -608,7 +609,7 @@ class Request { // Returns the URL of request as a string. get url () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The url getter steps are to return this’s request’s URL, serialized. return URLSerializer(this.#state.url) @@ -618,7 +619,7 @@ class Request { // Note that headers added in the network layer by the user agent will not // be accounted for in this object, e.g., the "Host" header. get headers () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The headers getter steps are to return this’s headers. return this.#headers @@ -627,7 +628,7 @@ class Request { // Returns the kind of resource requested by request, e.g., "document" // or "script". get destination () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The destination getter are to return this’s request’s destination. return this.#state.destination @@ -639,7 +640,7 @@ class Request { // during fetching to determine the value of the `Referer` header of the // request being made. get referrer () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // 1. If this’s request’s referrer is "no-referrer", then return the // empty string. @@ -661,7 +662,7 @@ class Request { // This is used during fetching to compute the value of the request’s // referrer. get referrerPolicy () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The referrerPolicy getter steps are to return this’s request’s referrer policy. return this.#state.referrerPolicy @@ -671,7 +672,7 @@ class Request { // whether the request will use CORS, or will be restricted to same-origin // URLs. get mode () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The mode getter steps are to return this’s request’s mode. return this.#state.mode @@ -681,7 +682,7 @@ class Request { // which is a string indicating whether credentials will be sent with the // request always, never, or only when sent to a same-origin URL. get credentials () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The credentials getter steps are to return this’s request’s credentials mode. return this.#state.credentials @@ -691,7 +692,7 @@ class Request { // which is a string indicating how the request will // interact with the browser’s cache when fetching. get cache () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The cache getter steps are to return this’s request’s cache mode. return this.#state.cache @@ -702,7 +703,7 @@ class Request { // request will be handled during fetching. A request // will follow redirects by default. get redirect () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The redirect getter steps are to return this’s request’s redirect mode. return this.#state.redirect @@ -712,7 +713,7 @@ class Request { // cryptographic hash of the resource being fetched. Its value // consists of multiple hashes separated by whitespace. [SRI] get integrity () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The integrity getter steps are to return this’s request’s integrity // metadata. @@ -722,7 +723,7 @@ class Request { // Returns a boolean indicating whether or not request can outlive the // global in which it was created. get keepalive () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The keepalive getter steps are to return this’s request’s keepalive. return this.#state.keepalive @@ -731,7 +732,7 @@ class Request { // Returns a boolean indicating whether or not request is for a reload // navigation. get isReloadNavigation () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The isReloadNavigation getter steps are to return true if this’s // request’s reload-navigation flag is set; otherwise false. @@ -741,7 +742,7 @@ class Request { // Returns a boolean indicating whether or not request is for a history // navigation (a.k.a. back-forward navigation). get isHistoryNavigation () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The isHistoryNavigation getter steps are to return true if this’s request’s // history-navigation flag is set; otherwise false. @@ -752,33 +753,33 @@ class Request { // object indicating whether or not request has been aborted, and its // abort event handler. get signal () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // The signal getter steps are to return this’s signal. return this.#signal } get body () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) return this.#state.body ? this.#state.body.stream : null } get bodyUsed () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) return !!this.#state.body && util.isDisturbed(this.#state.body.stream) } get duplex () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) return 'half' } // Returns a clone of request. clone () { - webidl.brandCheck(this, Request) + webidl.brandCheck(this, webidl.is.Request) // 1. If this is unusable, then throw a TypeError. if (bodyUnusable(this.#state)) { @@ -840,73 +841,69 @@ class Request { return `Request ${nodeUtil.formatWithOptions(options, properties)}` } - /** - * @param {Request} request - * @param {AbortSignal} newSignal - */ - static setRequestSignal (request, newSignal) { - request.#signal = newSignal - return request - } + static { + /** + * @param {Request} request + * @param {AbortSignal} newSignal + */ + setRequestSignal = (request, newSignal) => { + request.#signal = newSignal + } - /** - * @param {Request} request - */ - static getRequestDispatcher (request) { - return request.#dispatcher - } + /** + * @param {Request} request + */ + getRequestDispatcher = (request) => { + return request.#dispatcher + } - /** - * @param {Request} request - * @param {import('../../dispatcher/dispatcher')} newDispatcher - */ - static setRequestDispatcher (request, newDispatcher) { - request.#dispatcher = newDispatcher - } + /** + * @param {Request} request + * @param {import('../../dispatcher/dispatcher')} newDispatcher + */ + setRequestDispatcher = (request, newDispatcher) => { + request.#dispatcher = newDispatcher + } - /** - * @param {Request} request - * @param {Headers} newHeaders - */ - static setRequestHeaders (request, newHeaders) { - request.#headers = newHeaders - } + /** + * @param {Request} request + * @param {Headers} newHeaders + */ + setRequestHeaders = (request, newHeaders) => { + request.#headers = newHeaders + } - /** - * @param {Request} request - */ - static getRequestState (request) { - return request.#state - } + /** + * @param {Request} request + */ + getRequestState = (request) => { + return request.#state + } - /** - * @param {Request} request - * @param {any} newState - */ - static setRequestState (request, newState) { - request.#state = newState - } + /** + * @param {Request} request + * @param {any} newState + */ + setRequestState = (request, newState) => { + request.#state = newState + } - /** - * Removes the `abort` listener that makes this request's signal follow the - * signal passed to its constructor, if any. Idempotent. - * @param {Request} request - */ - static removeRequestAbortListener (request) { - request.#abortCleanup?.() + /** + * Removes the `abort` listener that makes this request's signal follow the + * signal passed to its constructor, if any. Idempotent. + * @param {Request} request + */ + removeRequestAbortListener = (request) => { + request.#abortCleanup?.() + } + + webidl.is.Request = (arg) => { + return arg != null && typeof arg === 'object' && #state in arg + } } } -const { setRequestSignal, getRequestDispatcher, setRequestDispatcher, setRequestHeaders, getRequestState, setRequestState, removeRequestAbortListener } = Request -Reflect.deleteProperty(Request, 'setRequestSignal') -Reflect.deleteProperty(Request, 'getRequestDispatcher') -Reflect.deleteProperty(Request, 'setRequestDispatcher') -Reflect.deleteProperty(Request, 'setRequestHeaders') -Reflect.deleteProperty(Request, 'getRequestState') -Reflect.deleteProperty(Request, 'setRequestState') -Reflect.deleteProperty(Request, 'removeRequestAbortListener') - -mixinBody(Request, getRequestState) +mixinBody(Request, getRequestState, webidl.is.Request) // https://fetch.spec.whatwg.org/#requests function makeRequest (init) { @@ -1021,8 +1018,6 @@ Object.defineProperties(Request.prototype, { } }) -webidl.is.Request = webidl.util.MakeTypeAssertion(Request) - /** * @param {*} V * @returns {import('../../../types/fetch').Request|string} diff --git a/lib/web/fetch/response.js b/lib/web/fetch/response.js index f555ea94b15..5e40c164a50 100644 --- a/lib/web/fetch/response.js +++ b/lib/web/fetch/response.js @@ -23,6 +23,7 @@ const assert = require('node:assert') const { isomorphicEncode, serializeJavascriptValueToJSONString } = require('../infra') const textEncoder = new TextEncoder('utf-8') +let getResponseHeaders, setResponseHeaders, getResponseState, setResponseState // https://fetch.spec.whatwg.org/#response-class class Response { @@ -145,7 +146,7 @@ class Response { // Returns response’s type, e.g., "cors". get type () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The type getter steps are to return this’s response’s type. return this.#state.type @@ -153,7 +154,7 @@ class Response { // Returns response’s URL, if it has one; otherwise the empty string. get url () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) const urlList = this.#state.urlList @@ -171,7 +172,7 @@ class Response { // Returns whether response was obtained through a redirect. get redirected () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The redirected getter steps are to return true if this’s response’s URL // list has more than one item; otherwise false. @@ -180,7 +181,7 @@ class Response { // Returns response’s status. get status () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The status getter steps are to return this’s response’s status. return this.#state.status @@ -188,7 +189,7 @@ class Response { // Returns whether response’s status is an ok status. get ok () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The ok getter steps are to return true if this’s response’s status is an // ok status; otherwise false. @@ -197,7 +198,7 @@ class Response { // Returns response’s status message. get statusText () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The statusText getter steps are to return this’s response’s status // message. @@ -206,27 +207,27 @@ class Response { // Returns response’s headers as Headers. get headers () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // The headers getter steps are to return this’s headers. return this.#headers } get body () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) return this.#state.body ? this.#state.body.stream : null } get bodyUsed () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) return !!this.#state.body && util.isDisturbed(this.#state.body.stream) } // Returns a clone of response. clone () { - webidl.brandCheck(this, Response) + webidl.brandCheck(this, webidl.is.Response) // 1. If this is unusable, then throw a TypeError. if (bodyUnusable(this.#state)) { @@ -272,44 +273,44 @@ class Response { return `Response ${nodeUtil.formatWithOptions(options, properties)}` } - /** - * @param {Response} response - */ - static getResponseHeaders (response) { - return response.#headers - } + static { + /** + * @param {Response} response + */ + getResponseHeaders = (response) => { + return response.#headers + } - /** - * @param {Response} response - * @param {Headers} newHeaders - */ - static setResponseHeaders (response, newHeaders) { - response.#headers = newHeaders - } + /** + * @param {Response} response + * @param {Headers} newHeaders + */ + setResponseHeaders = (response, newHeaders) => { + response.#headers = newHeaders + } - /** - * @param {Response} response - */ - static getResponseState (response) { - return response.#state - } + /** + * @param {Response} response + */ + getResponseState = (response) => { + return response.#state + } - /** - * @param {Response} response - * @param {any} newState - */ - static setResponseState (response, newState) { - response.#state = newState + /** + * @param {Response} response + * @param {any} newState + */ + setResponseState = (response, newState) => { + response.#state = newState + } + + webidl.is.Response = (arg) => { + return arg != null && typeof arg === 'object' && #state in arg + } } } -const { getResponseHeaders, setResponseHeaders, getResponseState, setResponseState } = Response -Reflect.deleteProperty(Response, 'getResponseHeaders') -Reflect.deleteProperty(Response, 'setResponseHeaders') -Reflect.deleteProperty(Response, 'getResponseState') -Reflect.deleteProperty(Response, 'setResponseState') - -mixinBody(Response, getResponseState) +mixinBody(Response, getResponseState, webidl.is.Response) Object.defineProperties(Response.prototype, { type: kEnumerableProperty, @@ -624,8 +625,6 @@ webidl.converters.ResponseInit = webidl.dictionaryConverter([ } ]) -webidl.is.Response = webidl.util.MakeTypeAssertion(Response) - module.exports = { isNetworkError, makeNetworkError, diff --git a/lib/web/fetch/util.js b/lib/web/fetch/util.js index 20cbb5c58f6..af6ecfc51b6 100644 --- a/lib/web/fetch/util.js +++ b/lib/web/fetch/util.js @@ -872,8 +872,9 @@ function createIterator (name, kInternalIterator, keyIndex = 0, valueIndex = 1) * @param {(target: any) => any} kInternalIterator * @param {string | number} [keyIndex] * @param {string | number} [valueIndex] + * @param {import('../../../types/webidl').WebidlIsFunction} brandCheck */ -function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueIndex = 1) { +function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueIndex = 1, brandCheck) { const makeIterator = createIterator(name, kInternalIterator, keyIndex, valueIndex) const properties = { @@ -882,7 +883,7 @@ function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueInde enumerable: true, configurable: true, value: function keys () { - webidl.brandCheck(this, object) + webidl.brandCheck(this, brandCheck) return makeIterator(this, 'key') } }, @@ -891,7 +892,7 @@ function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueInde enumerable: true, configurable: true, value: function values () { - webidl.brandCheck(this, object) + webidl.brandCheck(this, brandCheck) return makeIterator(this, 'value') } }, @@ -900,7 +901,7 @@ function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueInde enumerable: true, configurable: true, value: function entries () { - webidl.brandCheck(this, object) + webidl.brandCheck(this, brandCheck) return makeIterator(this, 'key+value') } }, @@ -909,7 +910,7 @@ function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueInde enumerable: true, configurable: true, value: function forEach (callbackfn, thisArg = globalThis) { - webidl.brandCheck(this, object) + webidl.brandCheck(this, brandCheck) webidl.argumentLengthCheck(arguments, 1, `${name}.forEach`) if (typeof callbackfn !== 'function') { throw new TypeError( diff --git a/lib/web/webidl/index.js b/lib/web/webidl/index.js index ce81c1e323a..6f4bd5036c0 100644 --- a/lib/web/webidl/index.js +++ b/lib/web/webidl/index.js @@ -73,26 +73,14 @@ webidl.errors.invalidArgument = function (context) { } // https://webidl.spec.whatwg.org/#implements -webidl.brandCheck = function (V, I) { - if (!FunctionPrototypeSymbolHasInstance(I, V)) { +webidl.brandCheck = function (V, is) { + if (!is(V)) { const err = new TypeError('Illegal invocation') err.code = 'ERR_INVALID_THIS' // node compat. throw err } } -webidl.brandCheckMultiple = function (List) { - const prototypes = List.map((c) => webidl.util.MakeTypeAssertion(c)) - - return (V) => { - if (prototypes.every(typeCheck => !typeCheck(V))) { - const err = new TypeError('Illegal invocation') - err.code = 'ERR_INVALID_THIS' // node compat. - throw err - } - } -} - webidl.argumentLengthCheck = function ({ length }, min, ctx) { if (length < min) { throw webidl.errors.exception({ diff --git a/lib/web/websocket/events.js b/lib/web/websocket/events.js index 7ac9566be46..b31c1d94293 100644 --- a/lib/web/websocket/events.js +++ b/lib/web/websocket/events.js @@ -4,6 +4,8 @@ const { webidl } = require('../webidl') const { kEnumerableProperty } = require('../../core/util') const { kConstruct } = require('../../core/symbols') +let createFastMessageEvent + /** * @see https://html.spec.whatwg.org/multipage/comms.html#messageevent */ @@ -30,31 +32,31 @@ class MessageEvent extends Event { } get data () { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) return this.#eventInit.data } get origin () { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) return this.#eventInit.origin } get lastEventId () { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) return this.#eventInit.lastEventId } get source () { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) return this.#eventInit.source } get ports () { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) if (!Object.isFrozen(this.#eventInit.ports)) { Object.freeze(this.#eventInit.ports) @@ -73,7 +75,7 @@ class MessageEvent extends Event { source = null, ports = [] ) { - webidl.brandCheck(this, MessageEvent) + webidl.brandCheck(this, webidl.is.MessageEvent) webidl.argumentLengthCheck(arguments, 1, 'MessageEvent.initMessageEvent') @@ -82,21 +84,24 @@ class MessageEvent extends Event { }) } - static createFastMessageEvent (type, init) { - const messageEvent = new MessageEvent(kConstruct, type, init) - messageEvent.#eventInit = init - messageEvent.#eventInit.data ??= null - messageEvent.#eventInit.origin ??= '' - messageEvent.#eventInit.lastEventId ??= '' - messageEvent.#eventInit.source ??= null - messageEvent.#eventInit.ports ??= [] - return messageEvent + static { + createFastMessageEvent = (type, init) => { + const messageEvent = new MessageEvent(kConstruct, type, init) + messageEvent.#eventInit = init + messageEvent.#eventInit.data ??= null + messageEvent.#eventInit.origin ??= '' + messageEvent.#eventInit.lastEventId ??= '' + messageEvent.#eventInit.source ??= null + messageEvent.#eventInit.ports ??= [] + return messageEvent + } + + webidl.is.MessageEvent = (arg) => { + return arg != null && typeof arg === 'object' && #eventInit in arg + } } } -const { createFastMessageEvent } = MessageEvent -delete MessageEvent.createFastMessageEvent - /** * @see https://websockets.spec.whatwg.org/#the-closeevent-interface */ @@ -117,22 +122,28 @@ class CloseEvent extends Event { } get wasClean () { - webidl.brandCheck(this, CloseEvent) + webidl.brandCheck(this, webidl.is.CloseEvent) return this.#eventInit.wasClean } get code () { - webidl.brandCheck(this, CloseEvent) + webidl.brandCheck(this, webidl.is.CloseEvent) return this.#eventInit.code } get reason () { - webidl.brandCheck(this, CloseEvent) + webidl.brandCheck(this, webidl.is.CloseEvent) return this.#eventInit.reason } + + static { + webidl.is.CloseEvent = (arg) => { + return arg != null && typeof arg === 'object' && #eventInit in arg + } + } } // https://html.spec.whatwg.org/multipage/webappapis.html#the-errorevent-interface @@ -153,34 +164,40 @@ class ErrorEvent extends Event { } get message () { - webidl.brandCheck(this, ErrorEvent) + webidl.brandCheck(this, webidl.is.ErrorEvent) return this.#eventInit.message } get filename () { - webidl.brandCheck(this, ErrorEvent) + webidl.brandCheck(this, webidl.is.ErrorEvent) return this.#eventInit.filename } get lineno () { - webidl.brandCheck(this, ErrorEvent) + webidl.brandCheck(this, webidl.is.ErrorEvent) return this.#eventInit.lineno } get colno () { - webidl.brandCheck(this, ErrorEvent) + webidl.brandCheck(this, webidl.is.ErrorEvent) return this.#eventInit.colno } get error () { - webidl.brandCheck(this, ErrorEvent) + webidl.brandCheck(this, webidl.is.ErrorEvent) return this.#eventInit.error } + + static { + webidl.is.ErrorEvent = (arg) => { + return arg != null && typeof arg === 'object' && #eventInit in arg + } + } } Object.defineProperties(MessageEvent.prototype, { diff --git a/lib/web/websocket/stream/websocketerror.js b/lib/web/websocket/stream/websocketerror.js index a34c5213a39..04937c271ed 100644 --- a/lib/web/websocket/stream/websocketerror.js +++ b/lib/web/websocket/stream/websocketerror.js @@ -26,6 +26,8 @@ function createInheritableDOMException () { }) } +let createUnvalidatedWebSocketError + class WebSocketError extends createInheritableDOMException() { #closeCode #reason @@ -77,17 +79,20 @@ class WebSocketError extends createInheritableDOMException() { * @param {number|null} code * @param {string} reason */ - static createUnvalidatedWebSocketError (message, code, reason) { - const error = new WebSocketError(message, kConstruct) - error.#closeCode = code - error.#reason = reason - return error + static { + createUnvalidatedWebSocketError = (message, code, reason) => { + const error = new WebSocketError(message, kConstruct) + error.#closeCode = code + error.#reason = reason + return error + } + + webidl.is.WebSocketError = (arg) => { + return arg != null && typeof arg === 'object' && #reason in arg + } } } -const { createUnvalidatedWebSocketError } = WebSocketError -delete WebSocketError.createUnvalidatedWebSocketError - Object.defineProperties(WebSocketError.prototype, { closeCode: kEnumerableProperty, reason: kEnumerableProperty, @@ -99,6 +104,4 @@ Object.defineProperties(WebSocketError.prototype, { } }) -webidl.is.WebSocketError = webidl.util.MakeTypeAssertion(WebSocketError) - module.exports = { WebSocketError, createUnvalidatedWebSocketError } diff --git a/lib/web/websocket/websocket.js b/lib/web/websocket/websocket.js index 45dbce1bea9..e83343bb4d8 100644 --- a/lib/web/websocket/websocket.js +++ b/lib/web/websocket/websocket.js @@ -28,6 +28,8 @@ const { channels } = require('../../core/diagnostics') const kRef = Symbol.for('nodejs.ref') const kUnref = Symbol.for('nodejs.unref') +let ping + function getSocketAddress (socket) { if (typeof socket?.address === 'function') { return socket.address() @@ -198,16 +200,14 @@ class WebSocket extends EventTarget { this.#binaryType = 'blob' } + // TODO: remove this [kRef] () { - webidl.brandCheck(this, WebSocket) - this.#refed = true this.#handler.socket?.ref?.() } + // TODO: remove this [kUnref] () { - webidl.brandCheck(this, WebSocket) - this.#refed = false this.#handler.socket?.unref?.() } @@ -218,7 +218,7 @@ class WebSocket extends EventTarget { * @param {string|undefined} reason */ close (code = undefined, reason = undefined) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) const prefix = 'WebSocket.close' @@ -245,7 +245,7 @@ class WebSocket extends EventTarget { * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data */ send (data) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) const prefix = 'WebSocket.send' webidl.argumentLengthCheck(arguments, 1, prefix) @@ -339,45 +339,45 @@ class WebSocket extends EventTarget { } get readyState () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) // The readyState getter steps are to return this's ready state. return this.#handler.readyState } get bufferedAmount () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#bufferedAmount } get url () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) // The url getter steps are to return this's url, serialized. return URLSerializer(this.#url) } get extensions () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#extensions } get protocol () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#protocol } get onopen () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#events.open } set onopen (fn) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) if (this.#events.open) { this.removeEventListener('open', this.#events.open) @@ -394,13 +394,13 @@ class WebSocket extends EventTarget { } get onerror () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#events.error } set onerror (fn) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) if (this.#events.error) { this.removeEventListener('error', this.#events.error) @@ -417,13 +417,13 @@ class WebSocket extends EventTarget { } get onclose () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#events.close } set onclose (fn) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) if (this.#events.close) { this.removeEventListener('close', this.#events.close) @@ -440,13 +440,13 @@ class WebSocket extends EventTarget { } get onmessage () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#events.message } set onmessage (fn) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) if (this.#events.message) { this.removeEventListener('message', this.#events.message) @@ -463,13 +463,13 @@ class WebSocket extends EventTarget { } get binaryType () { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) return this.#binaryType } set binaryType (type) { - webidl.brandCheck(this, WebSocket) + webidl.brandCheck(this, webidl.is.WebSocket) if (type !== 'blob' && type !== 'arraybuffer') { this.#binaryType = 'blob' @@ -654,33 +654,36 @@ class WebSocket extends EventTarget { } } - /** - * @param {WebSocket} ws - * @param {Buffer|undefined} buffer - */ - static ping (ws, buffer) { - if (Buffer.isBuffer(buffer)) { - if (buffer.length > 125) { - throw new TypeError('A PING frame cannot have a body larger than 125 bytes.') + static { + /** + * @param {WebSocket} ws + * @param {Buffer|undefined} buffer + */ + ping = (ws, buffer) => { + if (Buffer.isBuffer(buffer)) { + if (buffer.length > 125) { + throw new TypeError('A PING frame cannot have a body larger than 125 bytes.') + } + } else if (buffer !== undefined) { + throw new TypeError('Expected buffer payload') } - } else if (buffer !== undefined) { - throw new TypeError('Expected buffer payload') - } - // An endpoint MAY send a Ping frame any time after the connection is - // established and before the connection is closed. - const readyState = ws.#handler.readyState + // An endpoint MAY send a Ping frame any time after the connection is + // established and before the connection is closed. + const readyState = ws.#handler.readyState - if (isEstablished(readyState) && !isClosing(readyState) && !isClosed(readyState)) { - const frame = new WebsocketFrameSend(buffer) - ws.#handler.socket.write(frame.createFrame(opcodes.PING)) + if (isEstablished(readyState) && !isClosing(readyState) && !isClosed(readyState)) { + const frame = new WebsocketFrameSend(buffer) + ws.#handler.socket.write(frame.createFrame(opcodes.PING)) + } + } + + webidl.is.WebSocket = (arg) => { + return arg != null && typeof arg === 'object' && #handler in arg } } } -const { ping } = WebSocket -Reflect.deleteProperty(WebSocket, 'ping') - // https://websockets.spec.whatwg.org/#dom-websocket-connecting WebSocket.CONNECTING = WebSocket.prototype.CONNECTING = states.CONNECTING // https://websockets.spec.whatwg.org/#dom-websocket-open diff --git a/types/webidl.d.ts b/types/webidl.d.ts index b1873b9e52d..6bfe674c9ed 100644 --- a/types/webidl.d.ts +++ b/types/webidl.d.ts @@ -248,13 +248,22 @@ type WebidlIsFunction = (arg: any) => arg is T interface WebidlIs { Request: WebidlIsFunction Response: WebidlIsFunction + Headers: WebidlIsFunction + FormData: WebidlIsFunction + WebSocket: WebidlIsFunction + WebSocketError: WebidlIsFunction + Cache: WebidlIsFunction + CacheStorage: WebidlIsFunction + EventSource: WebidlIsFunction + MessageEvent: WebidlIsFunction + CloseEvent: WebidlIsFunction + ErrorEvent: WebidlIsFunction + ReadableStream: WebidlIsFunction Blob: WebidlIsFunction URLSearchParams: WebidlIsFunction File: WebidlIsFunction - FormData: WebidlIsFunction URL: WebidlIsFunction - WebSocketError: WebidlIsFunction AbortSignal: WebidlIsFunction MessagePort: WebidlIsFunction USVString: WebidlIsFunction @@ -272,12 +281,9 @@ export interface Webidl { attributes: WebIDLExtendedAttributes /** - * @description Performs a brand-check on {@param V} to ensure it is a - * {@param cls} object. + * @description Performs a brand-check on {@param V}. */ - brandCheck unknown>(V: unknown, cls: Interface): asserts V is Interface - - brandCheckMultiple unknown)[]> (list: Interfaces): (V: any) => asserts V is Interfaces[number] + brandCheck (V: unknown, assertion: WebidlIsFunction): asserts V is T /** * @see https://webidl.spec.whatwg.org/#es-sequence