undici
Advanced tools
Comparing version 6.14.1 to 6.15.0
'use strict' | ||
const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global') | ||
const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent') | ||
const fetchImpl = require('./lib/web/fetch').fetch | ||
@@ -18,5 +20,14 @@ | ||
const { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require('./lib/web/websocket/events') | ||
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket | ||
module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent | ||
module.exports.CloseEvent = CloseEvent | ||
module.exports.ErrorEvent = ErrorEvent | ||
module.exports.MessageEvent = MessageEvent | ||
module.exports.createFastMessageEvent = createFastMessageEvent | ||
module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource | ||
// Expose the fetch implementation to be enabled in Node.js core via a flag | ||
module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent | ||
module.exports.getGlobalDispatcher = getGlobalDispatcher | ||
module.exports.setGlobalDispatcher = setGlobalDispatcher |
@@ -10,5 +10,3 @@ 'use strict' | ||
const current = Date.now() | ||
const diff = new Date(retryAfter).getTime() - current | ||
return diff | ||
return new Date(retryAfter).getTime() - current | ||
} | ||
@@ -120,7 +118,3 @@ | ||
// Any code that is not a Undici's originated and allowed to retry | ||
if ( | ||
code && | ||
code !== 'UND_ERR_REQ_RETRY' && | ||
!errorCodes.includes(code) | ||
) { | ||
if (code && code !== 'UND_ERR_REQ_RETRY' && !errorCodes.includes(code)) { | ||
cb(err) | ||
@@ -251,6 +245,3 @@ return | ||
) | ||
assert( | ||
end != null && Number.isFinite(end), | ||
'invalid content-length' | ||
) | ||
assert(end != null && Number.isFinite(end), 'invalid content-length') | ||
@@ -276,2 +267,9 @@ this.start = start | ||
// Weak etags are not useful for comparison nor cache | ||
// for instance not safe to assume if the response is byte-per-byte | ||
// equal | ||
if (this.etag != null && this.etag.startsWith('W/')) { | ||
this.etag = null | ||
} | ||
return this.handler.onHeaders( | ||
@@ -315,3 +313,5 @@ statusCode, | ||
// We count the difference between the last checkpoint and the current retry count | ||
this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint) | ||
this.retryCount = | ||
this.retryCountCheckpoint + | ||
(this.retryCount - this.retryCountCheckpoint) | ||
} else { | ||
@@ -336,2 +336,9 @@ this.retryCount += 1 | ||
if (this.start !== 0) { | ||
const headers = { range: `bytes=${this.start}-${this.end ?? ''}` } | ||
// Weak etag check - weak etags will make comparison algorithms never match | ||
if (this.etag != null) { | ||
headers['if-match'] = this.etag | ||
} | ||
this.opts = { | ||
@@ -341,3 +348,3 @@ ...this.opts, | ||
...this.opts.headers, | ||
range: `bytes=${this.start}-${this.end ?? ''}` | ||
...headers | ||
} | ||
@@ -344,0 +351,0 @@ } |
@@ -45,7 +45,9 @@ 'use strict' | ||
webidl.brandCheck(this, Cache) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.match' }) | ||
request = webidl.converters.RequestInfo(request) | ||
options = webidl.converters.CacheQueryOptions(options) | ||
const prefix = 'Cache.match' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
options = webidl.converters.CacheQueryOptions(options, prefix, 'options') | ||
const p = this.#internalMatchAll(request, options, 1) | ||
@@ -63,4 +65,5 @@ | ||
if (request !== undefined) request = webidl.converters.RequestInfo(request) | ||
options = webidl.converters.CacheQueryOptions(options) | ||
const prefix = 'Cache.matchAll' | ||
if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
options = webidl.converters.CacheQueryOptions(options, prefix, 'options') | ||
@@ -72,6 +75,8 @@ return this.#internalMatchAll(request, options) | ||
webidl.brandCheck(this, Cache) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.add' }) | ||
request = webidl.converters.RequestInfo(request) | ||
const prefix = 'Cache.add' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
// 1. | ||
@@ -89,4 +94,6 @@ const requests = [request] | ||
webidl.brandCheck(this, Cache) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' }) | ||
const prefix = 'Cache.addAll' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
// 1. | ||
@@ -102,3 +109,3 @@ const responsePromises = [] | ||
throw webidl.errors.conversionFailed({ | ||
prefix: 'Cache.addAll', | ||
prefix, | ||
argument: 'Argument 1', | ||
@@ -121,3 +128,3 @@ types: ['undefined is not allowed'] | ||
throw webidl.errors.exception({ | ||
header: 'Cache.addAll', | ||
header: prefix, | ||
message: 'Expected http/s scheme when method is not GET.' | ||
@@ -140,3 +147,3 @@ }) | ||
throw webidl.errors.exception({ | ||
header: 'Cache.addAll', | ||
header: prefix, | ||
message: 'Expected http/s scheme.' | ||
@@ -261,7 +268,9 @@ }) | ||
webidl.brandCheck(this, Cache) | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'Cache.put' }) | ||
request = webidl.converters.RequestInfo(request) | ||
response = webidl.converters.Response(response) | ||
const prefix = 'Cache.put' | ||
webidl.argumentLengthCheck(arguments, 2, prefix) | ||
request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
response = webidl.converters.Response(response, prefix, 'response') | ||
// 1. | ||
@@ -280,3 +289,3 @@ let innerRequest = null | ||
throw webidl.errors.exception({ | ||
header: 'Cache.put', | ||
header: prefix, | ||
message: 'Expected an http/s scheme when method is not GET' | ||
@@ -292,3 +301,3 @@ }) | ||
throw webidl.errors.exception({ | ||
header: 'Cache.put', | ||
header: prefix, | ||
message: 'Got 206 status' | ||
@@ -308,3 +317,3 @@ }) | ||
throw webidl.errors.exception({ | ||
header: 'Cache.put', | ||
header: prefix, | ||
message: 'Got * vary field value' | ||
@@ -319,3 +328,3 @@ }) | ||
throw webidl.errors.exception({ | ||
header: 'Cache.put', | ||
header: prefix, | ||
message: 'Response body is locked or disturbed' | ||
@@ -395,7 +404,9 @@ }) | ||
webidl.brandCheck(this, Cache) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.delete' }) | ||
request = webidl.converters.RequestInfo(request) | ||
options = webidl.converters.CacheQueryOptions(options) | ||
const prefix = 'Cache.delete' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
options = webidl.converters.CacheQueryOptions(options, prefix, 'options') | ||
/** | ||
@@ -461,5 +472,7 @@ * @type {Request} | ||
if (request !== undefined) request = webidl.converters.RequestInfo(request) | ||
options = webidl.converters.CacheQueryOptions(options) | ||
const prefix = 'Cache.keys' | ||
if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request') | ||
options = webidl.converters.CacheQueryOptions(options, prefix, 'options') | ||
// 1. | ||
@@ -827,3 +840,3 @@ let r = null | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -833,3 +846,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -839,3 +852,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
} | ||
@@ -842,0 +855,0 @@ ] |
@@ -23,3 +23,3 @@ 'use strict' | ||
webidl.brandCheck(this, CacheStorage) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.match' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match') | ||
@@ -61,6 +61,8 @@ request = webidl.converters.RequestInfo(request) | ||
webidl.brandCheck(this, CacheStorage) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.has' }) | ||
cacheName = webidl.converters.DOMString(cacheName) | ||
const prefix = 'CacheStorage.has' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName') | ||
// 2.1.1 | ||
@@ -78,6 +80,8 @@ // 2.2 | ||
webidl.brandCheck(this, CacheStorage) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.open' }) | ||
cacheName = webidl.converters.DOMString(cacheName) | ||
const prefix = 'CacheStorage.open' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName') | ||
// 2.1 | ||
@@ -111,6 +115,8 @@ if (this.#caches.has(cacheName)) { | ||
webidl.brandCheck(this, CacheStorage) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.delete' }) | ||
cacheName = webidl.converters.DOMString(cacheName) | ||
const prefix = 'CacheStorage.delete' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName') | ||
return this.#caches.delete(cacheName) | ||
@@ -117,0 +123,0 @@ } |
@@ -27,3 +27,3 @@ 'use strict' | ||
function getCookies (headers) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'getCookies' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'getCookies') | ||
@@ -55,7 +55,8 @@ webidl.brandCheck(headers, Headers, { strict: false }) | ||
function deleteCookie (headers, name, attributes) { | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'deleteCookie' }) | ||
webidl.brandCheck(headers, Headers, { strict: false }) | ||
name = webidl.converters.DOMString(name) | ||
const prefix = 'deleteCookie' | ||
webidl.argumentLengthCheck(arguments, 2, prefix) | ||
name = webidl.converters.DOMString(name, prefix, 'name') | ||
attributes = webidl.converters.DeleteCookieAttributes(attributes) | ||
@@ -78,3 +79,3 @@ | ||
function getSetCookies (headers) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'getSetCookies' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'getSetCookies') | ||
@@ -99,3 +100,3 @@ webidl.brandCheck(headers, Headers, { strict: false }) | ||
function setCookie (headers, cookie) { | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'setCookie' }) | ||
webidl.argumentLengthCheck(arguments, 2, 'setCookie') | ||
@@ -117,3 +118,3 @@ webidl.brandCheck(headers, Headers, { strict: false }) | ||
key: 'path', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -123,3 +124,3 @@ { | ||
key: 'domain', | ||
defaultValue: null | ||
defaultValue: () => null | ||
} | ||
@@ -146,3 +147,3 @@ ]) | ||
key: 'expires', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -152,3 +153,3 @@ { | ||
key: 'maxAge', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -158,3 +159,3 @@ { | ||
key: 'domain', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -164,3 +165,3 @@ { | ||
key: 'path', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -170,3 +171,3 @@ { | ||
key: 'secure', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -176,3 +177,3 @@ { | ||
key: 'httpOnly', | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -187,3 +188,3 @@ { | ||
key: 'unparsed', | ||
defaultValue: [] | ||
defaultValue: () => new Array(0) | ||
} | ||
@@ -190,0 +191,0 @@ ]) |
@@ -9,3 +9,3 @@ 'use strict' | ||
const { parseMIMEType } = require('../fetch/data-url') | ||
const { MessageEvent } = require('../websocket/events') | ||
const { createFastMessageEvent } = require('../websocket/events') | ||
const { isNetworkError } = require('../fetch/response') | ||
@@ -109,3 +109,4 @@ const { delay } = require('./util') | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'EventSource constructor' }) | ||
const prefix = 'EventSource constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
@@ -119,4 +120,4 @@ if (!experimentalWarned) { | ||
url = webidl.converters.USVString(url) | ||
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict) | ||
url = webidl.converters.USVString(url, prefix, 'url') | ||
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict') | ||
@@ -296,3 +297,3 @@ this.#dispatcher = eventSourceInitDict.dispatcher | ||
push: (event) => { | ||
this.dispatchEvent(new MessageEvent( | ||
this.dispatchEvent(createFastMessageEvent( | ||
event.type, | ||
@@ -470,3 +471,3 @@ event.options | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -473,0 +474,0 @@ { |
@@ -36,5 +36,6 @@ 'use strict' | ||
module.exports = function () { | ||
// FIXME: remove workaround when the Node bug is fixed | ||
// FIXME: remove workaround when the Node bug is backported to v18 | ||
// https://github.com/nodejs/node/issues/49344#issuecomment-1741776308 | ||
if (process.env.NODE_V8_COVERAGE) { | ||
if (process.env.NODE_V8_COVERAGE && process.version.startsWith('v18')) { | ||
process._rawDebug('Using compatibility WeakRef and FinalizationRegistry') | ||
return { | ||
@@ -41,0 +42,0 @@ WeakRef: CompatWeakRef, |
@@ -31,3 +31,4 @@ 'use strict' | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'FormData.append' }) | ||
const prefix = 'FormData.append' | ||
webidl.argumentLengthCheck(arguments, 2, prefix) | ||
@@ -42,8 +43,8 @@ if (arguments.length === 3 && !isBlobLike(value)) { | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
value = isBlobLike(value) | ||
? webidl.converters.Blob(value, { strict: false }) | ||
: webidl.converters.USVString(value) | ||
? webidl.converters.Blob(value, prefix, 'value', { strict: false }) | ||
: webidl.converters.USVString(value, prefix, 'value') | ||
filename = arguments.length === 3 | ||
? webidl.converters.USVString(filename) | ||
? webidl.converters.USVString(filename, prefix, 'filename') | ||
: undefined | ||
@@ -62,5 +63,6 @@ | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FormData.delete' }) | ||
const prefix = 'FormData.delete' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
@@ -75,5 +77,6 @@ // The delete(name) method steps are to remove all entries whose name | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FormData.get' }) | ||
const prefix = 'FormData.get' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
@@ -95,5 +98,6 @@ // 1. If there is no entry whose name is name in this’s entry list, | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FormData.getAll' }) | ||
const prefix = 'FormData.getAll' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
@@ -112,5 +116,6 @@ // 1. If there is no entry whose name is name in this’s entry list, | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FormData.has' }) | ||
const prefix = 'FormData.has' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
@@ -125,3 +130,4 @@ // The has(name) method steps are to return true if there is an entry | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'FormData.set' }) | ||
const prefix = 'FormData.set' | ||
webidl.argumentLengthCheck(arguments, 2, prefix) | ||
@@ -139,8 +145,8 @@ if (arguments.length === 3 && !isBlobLike(value)) { | ||
name = webidl.converters.USVString(name) | ||
name = webidl.converters.USVString(name, prefix, 'name') | ||
value = isBlobLike(value) | ||
? webidl.converters.Blob(value, { strict: false }) | ||
: webidl.converters.USVString(value) | ||
? webidl.converters.Blob(value, prefix, 'name', { strict: false }) | ||
: webidl.converters.USVString(value, prefix, 'name') | ||
filename = arguments.length === 3 | ||
? webidl.converters.USVString(filename) | ||
? webidl.converters.USVString(filename, prefix, 'name') | ||
: undefined | ||
@@ -147,0 +153,0 @@ |
@@ -262,2 +262,20 @@ // https://github.com/Ethan-Arrowood/undici-fetch | ||
get entriesList () { | ||
const headers = [] | ||
if (this[kHeadersMap].size !== 0) { | ||
for (const { 0: lowerName, 1: { name, value } } of this[kHeadersMap]) { | ||
if (lowerName === 'set-cookie') { | ||
for (const cookie of this.cookies) { | ||
headers.push([name, cookie]) | ||
} | ||
} else { | ||
headers.push([name, value]) | ||
} | ||
} | ||
} | ||
return headers | ||
} | ||
// https://fetch.spec.whatwg.org/#convert-header-names-to-a-sorted-lowercase-set | ||
@@ -352,3 +370,3 @@ toSortedArray () { | ||
if (init !== undefined) { | ||
init = webidl.converters.HeadersInit(init) | ||
init = webidl.converters.HeadersInit(init, 'Headers contructor', 'init') | ||
fill(this, init) | ||
@@ -362,6 +380,7 @@ } | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'Headers.append' }) | ||
webidl.argumentLengthCheck(arguments, 2, 'Headers.append') | ||
name = webidl.converters.ByteString(name) | ||
value = webidl.converters.ByteString(value) | ||
const prefix = 'Headers.append' | ||
name = webidl.converters.ByteString(name, prefix, 'name') | ||
value = webidl.converters.ByteString(value, prefix, 'value') | ||
@@ -375,5 +394,6 @@ return appendHeader(this, name, value) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Headers.delete' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'Headers.delete') | ||
name = webidl.converters.ByteString(name) | ||
const prefix = 'Headers.delete' | ||
name = webidl.converters.ByteString(name, prefix, 'name') | ||
@@ -421,5 +441,6 @@ // 1. If name is not a header name, then throw a TypeError. | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Headers.get' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'Headers.get') | ||
name = webidl.converters.ByteString(name) | ||
const prefix = 'Headers.get' | ||
name = webidl.converters.ByteString(name, prefix, 'name') | ||
@@ -429,3 +450,3 @@ // 1. If name is not a header name, then throw a TypeError. | ||
throw webidl.errors.invalidArgument({ | ||
prefix: 'Headers.get', | ||
prefix, | ||
value: name, | ||
@@ -445,5 +466,6 @@ type: 'header name' | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Headers.has' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'Headers.has') | ||
name = webidl.converters.ByteString(name) | ||
const prefix = 'Headers.has' | ||
name = webidl.converters.ByteString(name, prefix, 'name') | ||
@@ -453,3 +475,3 @@ // 1. If name is not a header name, then throw a TypeError. | ||
throw webidl.errors.invalidArgument({ | ||
prefix: 'Headers.has', | ||
prefix, | ||
value: name, | ||
@@ -469,6 +491,7 @@ type: 'header name' | ||
webidl.argumentLengthCheck(arguments, 2, { header: 'Headers.set' }) | ||
webidl.argumentLengthCheck(arguments, 2, 'Headers.set') | ||
name = webidl.converters.ByteString(name) | ||
value = webidl.converters.ByteString(value) | ||
const prefix = 'Headers.set' | ||
name = webidl.converters.ByteString(name, prefix, 'name') | ||
value = webidl.converters.ByteString(value, prefix, 'value') | ||
@@ -482,3 +505,3 @@ // 1. Normalize value. | ||
throw webidl.errors.invalidArgument({ | ||
prefix: 'Headers.set', | ||
prefix, | ||
value: name, | ||
@@ -489,3 +512,3 @@ type: 'header name' | ||
throw webidl.errors.invalidArgument({ | ||
prefix: 'Headers.set', | ||
prefix, | ||
value, | ||
@@ -612,11 +635,17 @@ type: 'header value' | ||
webidl.converters.HeadersInit = function (V) { | ||
webidl.converters.HeadersInit = function (V, prefix, argument) { | ||
if (webidl.util.Type(V) === 'Object') { | ||
const iterator = Reflect.get(V, Symbol.iterator) | ||
// A work-around to ensure we send the properly-cased Headers when V is a Headers object. | ||
// Read https://github.com/nodejs/undici/pull/3159#issuecomment-2075537226 before touching, please. | ||
if (!util.types.isProxy(V) && kHeadersList in V && iterator === Headers.prototype.entries) { // Headers object | ||
return V[kHeadersList].entriesList | ||
} | ||
if (typeof iterator === 'function') { | ||
return webidl.converters['sequence<sequence<ByteString>>'](V, iterator.bind(V)) | ||
return webidl.converters['sequence<sequence<ByteString>>'](V, prefix, argument, iterator.bind(V)) | ||
} | ||
return webidl.converters['record<ByteString, ByteString>'](V) | ||
return webidl.converters['record<ByteString, ByteString>'](V, prefix, argument) | ||
} | ||
@@ -623,0 +652,0 @@ |
@@ -41,2 +41,42 @@ /* globals AbortController */ | ||
const dependentControllerMap = new WeakMap() | ||
function buildAbort (acRef) { | ||
return abort | ||
function abort () { | ||
const ac = acRef.deref() | ||
if (ac !== undefined) { | ||
// Currently, there is a problem with FinalizationRegistry. | ||
// https://github.com/nodejs/node/issues/49344 | ||
// https://github.com/nodejs/node/issues/47748 | ||
// In the case of abort, the first step is to unregister from it. | ||
// If the controller can refer to it, it is still registered. | ||
// It will be removed in the future. | ||
requestFinalizer.unregister(abort) | ||
// Unsubscribe a listener. | ||
// FinalizationRegistry will no longer be called, so this must be done. | ||
this.removeEventListener('abort', abort) | ||
ac.abort(this.reason) | ||
const controllerList = dependentControllerMap.get(ac.signal) | ||
if (controllerList !== undefined) { | ||
if (controllerList.size !== 0) { | ||
for (const ref of controllerList) { | ||
const ctrl = ref.deref() | ||
if (ctrl !== undefined) { | ||
ctrl.abort(this.reason) | ||
} | ||
} | ||
controllerList.clear() | ||
} | ||
dependentControllerMap.delete(ac.signal) | ||
} | ||
} | ||
} | ||
} | ||
let patchMethodWarning = false | ||
@@ -52,6 +92,7 @@ | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Request constructor' }) | ||
const prefix = 'Request constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
input = webidl.converters.RequestInfo(input) | ||
init = webidl.converters.RequestInit(init) | ||
input = webidl.converters.RequestInfo(input, prefix, 'input') | ||
init = webidl.converters.RequestInit(init, prefix, 'init') | ||
@@ -382,21 +423,4 @@ // 1. Let request be null. | ||
const acRef = new WeakRef(ac) | ||
const abort = function () { | ||
const ac = acRef.deref() | ||
if (ac !== undefined) { | ||
// Currently, there is a problem with FinalizationRegistry. | ||
// https://github.com/nodejs/node/issues/49344 | ||
// https://github.com/nodejs/node/issues/47748 | ||
// In the case of abort, the first step is to unregister from it. | ||
// If the controller can refer to it, it is still registered. | ||
// It will be removed in the future. | ||
requestFinalizer.unregister(abort) | ||
const abort = buildAbort(acRef) | ||
// Unsubscribe a listener. | ||
// FinalizationRegistry will no longer be called, so this must be done. | ||
this.removeEventListener('abort', abort) | ||
ac.abort(this.reason) | ||
} | ||
} | ||
// Third-party AbortControllers may not work with these. | ||
@@ -408,5 +432,5 @@ // See, https://github.com/nodejs/undici/pull/1910#issuecomment-1464495619. | ||
if (typeof getMaxListeners === 'function' && getMaxListeners(signal) === defaultMaxListeners) { | ||
setMaxListeners(100, signal) | ||
setMaxListeners(1500, signal) | ||
} else if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) { | ||
setMaxListeners(100, signal) | ||
setMaxListeners(1500, signal) | ||
} | ||
@@ -460,4 +484,5 @@ } catch {} | ||
if (headers instanceof HeadersList) { | ||
for (const [key, val] of headers) { | ||
headersList.append(key, val) | ||
for (const { 0: key, 1: val } of headers) { | ||
// Note: The header names are already in lowercase. | ||
headersList.append(key, val, true) | ||
} | ||
@@ -755,7 +780,12 @@ // Note: Copy the `set-cookie` meta-data. | ||
} else { | ||
let list = dependentControllerMap.get(this.signal) | ||
if (list === undefined) { | ||
list = new Set() | ||
dependentControllerMap.set(this.signal, list) | ||
} | ||
const acRef = new WeakRef(ac) | ||
list.add(acRef) | ||
util.addAbortListener( | ||
this.signal, | ||
() => { | ||
ac.abort(this.signal.reason) | ||
} | ||
ac.signal, | ||
buildAbort(acRef) | ||
) | ||
@@ -912,12 +942,12 @@ } | ||
// https://fetch.spec.whatwg.org/#requestinfo | ||
webidl.converters.RequestInfo = function (V) { | ||
webidl.converters.RequestInfo = function (V, prefix, argument) { | ||
if (typeof V === 'string') { | ||
return webidl.converters.USVString(V) | ||
return webidl.converters.USVString(V, prefix, argument) | ||
} | ||
if (V instanceof Request) { | ||
return webidl.converters.Request(V) | ||
return webidl.converters.Request(V, prefix, argument) | ||
} | ||
return webidl.converters.USVString(V) | ||
return webidl.converters.USVString(V, prefix, argument) | ||
} | ||
@@ -992,2 +1022,4 @@ | ||
signal, | ||
'RequestInit', | ||
'signal', | ||
{ strict: false } | ||
@@ -994,0 +1026,0 @@ ) |
@@ -46,3 +46,3 @@ 'use strict' | ||
static json (data, init = {}) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Response.json' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'Response.json') | ||
@@ -74,3 +74,3 @@ if (init !== null) { | ||
static redirect (url, status = 302) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'Response.redirect' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'Response.redirect') | ||
@@ -531,30 +531,30 @@ url = webidl.converters.USVString(url) | ||
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit | ||
webidl.converters.XMLHttpRequestBodyInit = function (V) { | ||
webidl.converters.XMLHttpRequestBodyInit = function (V, prefix, name) { | ||
if (typeof V === 'string') { | ||
return webidl.converters.USVString(V) | ||
return webidl.converters.USVString(V, prefix, name) | ||
} | ||
if (isBlobLike(V)) { | ||
return webidl.converters.Blob(V, { strict: false }) | ||
return webidl.converters.Blob(V, prefix, name, { strict: false }) | ||
} | ||
if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) { | ||
return webidl.converters.BufferSource(V) | ||
return webidl.converters.BufferSource(V, prefix, name) | ||
} | ||
if (util.isFormDataLike(V)) { | ||
return webidl.converters.FormData(V, { strict: false }) | ||
return webidl.converters.FormData(V, prefix, name, { strict: false }) | ||
} | ||
if (V instanceof URLSearchParams) { | ||
return webidl.converters.URLSearchParams(V) | ||
return webidl.converters.URLSearchParams(V, prefix, name) | ||
} | ||
return webidl.converters.DOMString(V) | ||
return webidl.converters.DOMString(V, prefix, name) | ||
} | ||
// https://fetch.spec.whatwg.org/#bodyinit | ||
webidl.converters.BodyInit = function (V) { | ||
webidl.converters.BodyInit = function (V, prefix, argument) { | ||
if (V instanceof ReadableStream) { | ||
return webidl.converters.ReadableStream(V) | ||
return webidl.converters.ReadableStream(V, prefix, argument) | ||
} | ||
@@ -568,3 +568,3 @@ | ||
return webidl.converters.XMLHttpRequestBodyInit(V) | ||
return webidl.converters.XMLHttpRequestBodyInit(V, prefix, argument) | ||
} | ||
@@ -576,3 +576,3 @@ | ||
converter: webidl.converters['unsigned short'], | ||
defaultValue: 200 | ||
defaultValue: () => 200 | ||
}, | ||
@@ -582,3 +582,3 @@ { | ||
converter: webidl.converters.ByteString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
}, | ||
@@ -585,0 +585,0 @@ { |
@@ -1019,3 +1019,3 @@ 'use strict' | ||
webidl.brandCheck(this, object) | ||
webidl.argumentLengthCheck(arguments, 1, { header: `${name}.forEach` }) | ||
webidl.argumentLengthCheck(arguments, 1, `${name}.forEach`) | ||
if (typeof callbackfn !== 'function') { | ||
@@ -1022,0 +1022,0 @@ throw new TypeError( |
@@ -36,10 +36,14 @@ 'use strict' | ||
// https://webidl.spec.whatwg.org/#implements | ||
webidl.brandCheck = function (V, I, opts = undefined) { | ||
webidl.brandCheck = function (V, I, opts) { | ||
if (opts?.strict !== false) { | ||
if (!(V instanceof I)) { | ||
throw new TypeError('Illegal invocation') | ||
const err = new TypeError('Illegal invocation') | ||
err.code = 'ERR_INVALID_THIS' // node compat. | ||
throw err | ||
} | ||
} else { | ||
if (V?.[Symbol.toStringTag] !== I.prototype[Symbol.toStringTag]) { | ||
throw new TypeError('Illegal invocation') | ||
const err = new TypeError('Illegal invocation') | ||
err.code = 'ERR_INVALID_THIS' // node compat. | ||
throw err | ||
} | ||
@@ -54,3 +58,3 @@ } | ||
`but${length ? ' only' : ''} ${length} found.`, | ||
...ctx | ||
header: ctx | ||
}) | ||
@@ -88,3 +92,3 @@ } | ||
// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint | ||
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts = {}) { | ||
webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) { | ||
let upperBound | ||
@@ -133,3 +137,3 @@ let lowerBound | ||
// with the [EnforceRange] extended attribute, then: | ||
if (opts.enforceRange === true) { | ||
if (opts?.enforceRange === true) { | ||
// 1. If x is NaN, +∞, or −∞, then throw a TypeError. | ||
@@ -166,3 +170,3 @@ if ( | ||
// attribute, then: | ||
if (!Number.isNaN(x) && opts.clamp === true) { | ||
if (!Number.isNaN(x) && opts?.clamp === true) { | ||
// 1. Set x to min(max(x, lowerBound), upperBound). | ||
@@ -241,8 +245,8 @@ x = Math.min(Math.max(x, lowerBound), upperBound) | ||
webidl.sequenceConverter = function (converter) { | ||
return (V, Iterable) => { | ||
return (V, prefix, argument, Iterable) => { | ||
// 1. If Type(V) is not Object, throw a TypeError. | ||
if (webidl.util.Type(V) !== 'Object') { | ||
throw webidl.errors.exception({ | ||
header: 'Sequence', | ||
message: `Value of type ${webidl.util.Type(V)} is not an Object.` | ||
header: prefix, | ||
message: `${argument} (${webidl.util.Stringify(V)}) is not iterable.` | ||
}) | ||
@@ -262,4 +266,4 @@ } | ||
throw webidl.errors.exception({ | ||
header: 'Sequence', | ||
message: 'Object is not an iterator.' | ||
header: prefix, | ||
message: `${argument} is not iterable.` | ||
}) | ||
@@ -276,3 +280,3 @@ } | ||
seq.push(converter(value)) | ||
seq.push(converter(value, prefix, argument)) | ||
} | ||
@@ -286,8 +290,8 @@ | ||
webidl.recordConverter = function (keyConverter, valueConverter) { | ||
return (O) => { | ||
return (O, prefix, argument) => { | ||
// 1. If Type(O) is not Object, throw a TypeError. | ||
if (webidl.util.Type(O) !== 'Object') { | ||
throw webidl.errors.exception({ | ||
header: 'Record', | ||
message: `Value of type ${webidl.util.Type(O)} is not an Object.` | ||
header: prefix, | ||
message: `${argument} ("${webidl.util.Type(O)}") is not an Object.` | ||
}) | ||
@@ -305,7 +309,7 @@ } | ||
// 1. Let typedKey be key converted to an IDL value of type K. | ||
const typedKey = keyConverter(key) | ||
const typedKey = keyConverter(key, prefix, argument) | ||
// 2. Let value be ? Get(O, key). | ||
// 3. Let typedValue be value converted to an IDL value of type V. | ||
const typedValue = valueConverter(O[key]) | ||
const typedValue = valueConverter(O[key], prefix, argument) | ||
@@ -331,7 +335,7 @@ // 4. Set result[typedKey] to typedValue. | ||
// 1. Let typedKey be key converted to an IDL value of type K. | ||
const typedKey = keyConverter(key) | ||
const typedKey = keyConverter(key, prefix, argument) | ||
// 2. Let value be ? Get(O, key). | ||
// 3. Let typedValue be value converted to an IDL value of type V. | ||
const typedValue = valueConverter(O[key]) | ||
const typedValue = valueConverter(O[key], prefix, argument) | ||
@@ -349,7 +353,7 @@ // 4. Set result[typedKey] to typedValue. | ||
webidl.interfaceConverter = function (i) { | ||
return (V, opts = {}) => { | ||
if (opts.strict !== false && !(V instanceof i)) { | ||
return (V, prefix, argument, opts) => { | ||
if (opts?.strict !== false && !(V instanceof i)) { | ||
throw webidl.errors.exception({ | ||
header: i.name, | ||
message: `Expected ${webidl.util.Stringify(V)} to be an instance of ${i.name}.` | ||
header: prefix, | ||
message: `Expected ${argument} ("${webidl.util.Stringify(V)}") to be an instance of ${i.name}.` | ||
}) | ||
@@ -363,3 +367,3 @@ } | ||
webidl.dictionaryConverter = function (converters) { | ||
return (dictionary) => { | ||
return (dictionary, prefix, argument) => { | ||
const type = webidl.util.Type(dictionary) | ||
@@ -372,3 +376,3 @@ const dict = {} | ||
throw webidl.errors.exception({ | ||
header: 'Dictionary', | ||
header: prefix, | ||
message: `Expected ${dictionary} to be one of: Null, Undefined, Object.` | ||
@@ -384,3 +388,3 @@ }) | ||
throw webidl.errors.exception({ | ||
header: 'Dictionary', | ||
header: prefix, | ||
message: `Missing required key "${key}".` | ||
@@ -397,3 +401,3 @@ }) | ||
if (hasDefault && value !== null) { | ||
value = value ?? defaultValue | ||
value ??= defaultValue() | ||
} | ||
@@ -405,3 +409,3 @@ | ||
if (required || hasDefault || value !== undefined) { | ||
value = converter(value) | ||
value = converter(value, prefix, `${argument}.${key}`) | ||
@@ -413,3 +417,3 @@ if ( | ||
throw webidl.errors.exception({ | ||
header: 'Dictionary', | ||
header: prefix, | ||
message: `${value} is not an accepted type. Expected one of ${options.allowedValues.join(', ')}.` | ||
@@ -428,3 +432,3 @@ }) | ||
webidl.nullableConverter = function (converter) { | ||
return (V) => { | ||
return (V, prefix, argument) => { | ||
if (V === null) { | ||
@@ -434,3 +438,3 @@ return V | ||
return converter(V) | ||
return converter(V, prefix, argument) | ||
} | ||
@@ -440,3 +444,3 @@ } | ||
// https://webidl.spec.whatwg.org/#es-DOMString | ||
webidl.converters.DOMString = function (V, opts = {}) { | ||
webidl.converters.DOMString = function (V, prefix, argument, opts) { | ||
// 1. If V is null and the conversion is to an IDL type | ||
@@ -446,3 +450,3 @@ // associated with the [LegacyNullToEmptyString] | ||
// that represents the empty string. | ||
if (V === null && opts.legacyNullToEmptyString) { | ||
if (V === null && opts?.legacyNullToEmptyString) { | ||
return '' | ||
@@ -453,3 +457,6 @@ } | ||
if (typeof V === 'symbol') { | ||
throw new TypeError('Could not convert argument of type symbol to string.') | ||
throw webidl.errors.exception({ | ||
header: prefix, | ||
message: `${argument} is a symbol, which cannot be converted to a DOMString.` | ||
}) | ||
} | ||
@@ -464,6 +471,6 @@ | ||
// https://webidl.spec.whatwg.org/#es-ByteString | ||
webidl.converters.ByteString = function (V) { | ||
webidl.converters.ByteString = function (V, prefix, argument) { | ||
// 1. Let x be ? ToString(V). | ||
// Note: DOMString converter perform ? ToString(V) | ||
const x = webidl.converters.DOMString(V) | ||
const x = webidl.converters.DOMString(V, prefix, argument) | ||
@@ -488,2 +495,3 @@ // 2. If the value of any element of x is greater than | ||
// https://webidl.spec.whatwg.org/#es-USVString | ||
// TODO: rewrite this so we can control the errors thrown | ||
webidl.converters.USVString = toUSVString | ||
@@ -507,5 +515,5 @@ | ||
// https://webidl.spec.whatwg.org/#es-long-long | ||
webidl.converters['long long'] = function (V) { | ||
webidl.converters['long long'] = function (V, prefix, argument) { | ||
// 1. Let x be ? ConvertToInt(V, 64, "signed"). | ||
const x = webidl.util.ConvertToInt(V, 64, 'signed') | ||
const x = webidl.util.ConvertToInt(V, 64, 'signed', undefined, prefix, argument) | ||
@@ -518,5 +526,5 @@ // 2. Return the IDL long long value that represents | ||
// https://webidl.spec.whatwg.org/#es-unsigned-long-long | ||
webidl.converters['unsigned long long'] = function (V) { | ||
webidl.converters['unsigned long long'] = function (V, prefix, argument) { | ||
// 1. Let x be ? ConvertToInt(V, 64, "unsigned"). | ||
const x = webidl.util.ConvertToInt(V, 64, 'unsigned') | ||
const x = webidl.util.ConvertToInt(V, 64, 'unsigned', undefined, prefix, argument) | ||
@@ -529,5 +537,5 @@ // 2. Return the IDL unsigned long long value that | ||
// https://webidl.spec.whatwg.org/#es-unsigned-long | ||
webidl.converters['unsigned long'] = function (V) { | ||
webidl.converters['unsigned long'] = function (V, prefix, argument) { | ||
// 1. Let x be ? ConvertToInt(V, 32, "unsigned"). | ||
const x = webidl.util.ConvertToInt(V, 32, 'unsigned') | ||
const x = webidl.util.ConvertToInt(V, 32, 'unsigned', undefined, prefix, argument) | ||
@@ -540,5 +548,5 @@ // 2. Return the IDL unsigned long value that | ||
// https://webidl.spec.whatwg.org/#es-unsigned-short | ||
webidl.converters['unsigned short'] = function (V, opts) { | ||
webidl.converters['unsigned short'] = function (V, prefix, argument, opts) { | ||
// 1. Let x be ? ConvertToInt(V, 16, "unsigned"). | ||
const x = webidl.util.ConvertToInt(V, 16, 'unsigned', opts) | ||
const x = webidl.util.ConvertToInt(V, 16, 'unsigned', opts, prefix, argument) | ||
@@ -551,3 +559,3 @@ // 2. Return the IDL unsigned short value that represents | ||
// https://webidl.spec.whatwg.org/#idl-ArrayBuffer | ||
webidl.converters.ArrayBuffer = function (V, opts = {}) { | ||
webidl.converters.ArrayBuffer = function (V, prefix, argument, opts) { | ||
// 1. If Type(V) is not Object, or V does not have an | ||
@@ -563,4 +571,4 @@ // [[ArrayBufferData]] internal slot, then throw a | ||
throw webidl.errors.conversionFailed({ | ||
prefix: webidl.util.Stringify(V), | ||
argument: webidl.util.Stringify(V), | ||
prefix, | ||
argument: `${argument} ("${webidl.util.Stringify(V)}")`, | ||
types: ['ArrayBuffer'] | ||
@@ -574,3 +582,3 @@ }) | ||
// TypeError. | ||
if (opts.allowShared === false && types.isSharedArrayBuffer(V)) { | ||
if (opts?.allowShared === false && types.isSharedArrayBuffer(V)) { | ||
throw webidl.errors.exception({ | ||
@@ -598,3 +606,3 @@ header: 'ArrayBuffer', | ||
webidl.converters.TypedArray = function (V, T, opts = {}) { | ||
webidl.converters.TypedArray = function (V, T, prefix, name, opts) { | ||
// 1. Let T be the IDL type V is being converted to. | ||
@@ -611,4 +619,4 @@ | ||
throw webidl.errors.conversionFailed({ | ||
prefix: `${T.name}`, | ||
argument: webidl.util.Stringify(V), | ||
prefix, | ||
argument: `${name} ("${webidl.util.Stringify(V)}")`, | ||
types: [T.name] | ||
@@ -622,3 +630,3 @@ }) | ||
// true, then throw a TypeError. | ||
if (opts.allowShared === false && types.isSharedArrayBuffer(V.buffer)) { | ||
if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) { | ||
throw webidl.errors.exception({ | ||
@@ -646,3 +654,3 @@ header: 'ArrayBuffer', | ||
webidl.converters.DataView = function (V, opts = {}) { | ||
webidl.converters.DataView = function (V, prefix, name, opts) { | ||
// 1. If Type(V) is not Object, or V does not have a | ||
@@ -652,4 +660,4 @@ // [[DataView]] internal slot, then throw a TypeError. | ||
throw webidl.errors.exception({ | ||
header: 'DataView', | ||
message: 'Object is not a DataView.' | ||
header: prefix, | ||
message: `${name} is not a DataView.` | ||
}) | ||
@@ -662,3 +670,3 @@ } | ||
// then throw a TypeError. | ||
if (opts.allowShared === false && types.isSharedArrayBuffer(V.buffer)) { | ||
if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) { | ||
throw webidl.errors.exception({ | ||
@@ -687,16 +695,20 @@ header: 'ArrayBuffer', | ||
// https://webidl.spec.whatwg.org/#BufferSource | ||
webidl.converters.BufferSource = function (V, opts = {}) { | ||
webidl.converters.BufferSource = function (V, prefix, name, opts) { | ||
if (types.isAnyArrayBuffer(V)) { | ||
return webidl.converters.ArrayBuffer(V, { ...opts, allowShared: false }) | ||
return webidl.converters.ArrayBuffer(V, prefix, name, { ...opts, allowShared: false }) | ||
} | ||
if (types.isTypedArray(V)) { | ||
return webidl.converters.TypedArray(V, V.constructor, { ...opts, allowShared: false }) | ||
return webidl.converters.TypedArray(V, V.constructor, prefix, name, { ...opts, allowShared: false }) | ||
} | ||
if (types.isDataView(V)) { | ||
return webidl.converters.DataView(V, opts, { ...opts, allowShared: false }) | ||
return webidl.converters.DataView(V, prefix, name, { ...opts, allowShared: false }) | ||
} | ||
throw new TypeError(`Could not convert ${webidl.util.Stringify(V)} to a BufferSource.`) | ||
throw webidl.errors.conversionFailed({ | ||
prefix, | ||
argument: `${name} ("${webidl.util.Stringify(V)}")`, | ||
types: ['BufferSource'] | ||
}) | ||
} | ||
@@ -703,0 +715,0 @@ |
@@ -42,3 +42,3 @@ 'use strict' | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsArrayBuffer' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsArrayBuffer') | ||
@@ -59,3 +59,3 @@ blob = webidl.converters.Blob(blob, { strict: false }) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsBinaryString' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsBinaryString') | ||
@@ -77,3 +77,3 @@ blob = webidl.converters.Blob(blob, { strict: false }) | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsText' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsText') | ||
@@ -83,3 +83,3 @@ blob = webidl.converters.Blob(blob, { strict: false }) | ||
if (encoding !== undefined) { | ||
encoding = webidl.converters.DOMString(encoding) | ||
encoding = webidl.converters.DOMString(encoding, 'FileReader.readAsText', 'encoding') | ||
} | ||
@@ -99,3 +99,3 @@ | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'FileReader.readAsDataURL' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsDataURL') | ||
@@ -102,0 +102,0 @@ blob = webidl.converters.Blob(blob, { strict: false }) |
@@ -12,3 +12,3 @@ 'use strict' | ||
constructor (type, eventInitDict = {}) { | ||
type = webidl.converters.DOMString(type) | ||
type = webidl.converters.DOMString(type, 'ProgressEvent constructor', 'type') | ||
eventInitDict = webidl.converters.ProgressEventInit(eventInitDict ?? {}) | ||
@@ -48,3 +48,3 @@ | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -54,3 +54,3 @@ { | ||
converter: webidl.converters['unsigned long long'], | ||
defaultValue: 0 | ||
defaultValue: () => 0 | ||
}, | ||
@@ -60,3 +60,3 @@ { | ||
converter: webidl.converters['unsigned long long'], | ||
defaultValue: 0 | ||
defaultValue: () => 0 | ||
}, | ||
@@ -66,3 +66,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -72,3 +72,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -78,3 +78,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
} | ||
@@ -81,0 +81,0 @@ ]) |
@@ -270,3 +270,3 @@ 'use strict' | ||
// TODO: process.nextTick | ||
fireEvent('close', ws, CloseEvent, { | ||
fireEvent('close', ws, (type, init) => new CloseEvent(type, init), { | ||
wasClean, code, reason | ||
@@ -273,0 +273,0 @@ }) |
@@ -5,2 +5,3 @@ 'use strict' | ||
const { kEnumerableProperty } = require('../../core/util') | ||
const { kConstruct } = require('../../core/symbols') | ||
const { MessagePort } = require('node:worker_threads') | ||
@@ -15,7 +16,13 @@ | ||
constructor (type, eventInitDict = {}) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'MessageEvent constructor' }) | ||
if (type === kConstruct) { | ||
super(arguments[1], arguments[2]) | ||
return | ||
} | ||
type = webidl.converters.DOMString(type) | ||
eventInitDict = webidl.converters.MessageEventInit(eventInitDict) | ||
const prefix = 'MessageEvent constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
type = webidl.converters.DOMString(type, prefix, 'type') | ||
eventInitDict = webidl.converters.MessageEventInit(eventInitDict, prefix, 'eventInitDict') | ||
super(type, eventInitDict) | ||
@@ -72,3 +79,3 @@ | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'MessageEvent.initMessageEvent' }) | ||
webidl.argumentLengthCheck(arguments, 1, 'MessageEvent.initMessageEvent') | ||
@@ -79,4 +86,18 @@ return new MessageEvent(type, { | ||
} | ||
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 | ||
} | ||
} | ||
const { createFastMessageEvent } = MessageEvent | ||
delete MessageEvent.createFastMessageEvent | ||
/** | ||
@@ -89,5 +110,6 @@ * @see https://websockets.spec.whatwg.org/#the-closeevent-interface | ||
constructor (type, eventInitDict = {}) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'CloseEvent constructor' }) | ||
const prefix = 'CloseEvent constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
type = webidl.converters.DOMString(type) | ||
type = webidl.converters.DOMString(type, prefix, 'type') | ||
eventInitDict = webidl.converters.CloseEventInit(eventInitDict) | ||
@@ -124,7 +146,8 @@ | ||
constructor (type, eventInitDict) { | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'ErrorEvent constructor' }) | ||
const prefix = 'ErrorEvent constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
super(type, eventInitDict) | ||
type = webidl.converters.DOMString(type) | ||
type = webidl.converters.DOMString(type, prefix, 'type') | ||
eventInitDict = webidl.converters.ErrorEventInit(eventInitDict ?? {}) | ||
@@ -211,3 +234,3 @@ | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -217,3 +240,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -223,3 +246,3 @@ { | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
} | ||
@@ -233,3 +256,3 @@ ] | ||
converter: webidl.converters.any, | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -239,3 +262,3 @@ { | ||
converter: webidl.converters.USVString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
}, | ||
@@ -245,3 +268,3 @@ { | ||
converter: webidl.converters.DOMString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
}, | ||
@@ -253,3 +276,3 @@ { | ||
converter: webidl.nullableConverter(webidl.converters.MessagePort), | ||
defaultValue: null | ||
defaultValue: () => null | ||
}, | ||
@@ -259,5 +282,3 @@ { | ||
converter: webidl.converters['sequence<MessagePort>'], | ||
get defaultValue () { | ||
return [] | ||
} | ||
defaultValue: () => new Array(0) | ||
} | ||
@@ -271,3 +292,3 @@ ]) | ||
converter: webidl.converters.boolean, | ||
defaultValue: false | ||
defaultValue: () => false | ||
}, | ||
@@ -277,3 +298,3 @@ { | ||
converter: webidl.converters['unsigned short'], | ||
defaultValue: 0 | ||
defaultValue: () => 0 | ||
}, | ||
@@ -283,3 +304,3 @@ { | ||
converter: webidl.converters.USVString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
} | ||
@@ -293,3 +314,3 @@ ]) | ||
converter: webidl.converters.DOMString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
}, | ||
@@ -299,3 +320,3 @@ { | ||
converter: webidl.converters.USVString, | ||
defaultValue: '' | ||
defaultValue: () => '' | ||
}, | ||
@@ -305,3 +326,3 @@ { | ||
converter: webidl.converters['unsigned long'], | ||
defaultValue: 0 | ||
defaultValue: () => 0 | ||
}, | ||
@@ -311,3 +332,3 @@ { | ||
converter: webidl.converters['unsigned long'], | ||
defaultValue: 0 | ||
defaultValue: () => 0 | ||
}, | ||
@@ -323,3 +344,4 @@ { | ||
CloseEvent, | ||
ErrorEvent | ||
ErrorEvent, | ||
createFastMessageEvent | ||
} |
@@ -5,3 +5,3 @@ 'use strict' | ||
const { states, opcodes } = require('./constants') | ||
const { MessageEvent, ErrorEvent } = require('./events') | ||
const { ErrorEvent, createFastMessageEvent } = require('./events') | ||
const { isUtf8 } = require('node:buffer') | ||
@@ -55,5 +55,6 @@ | ||
* @param {EventTarget} target | ||
* @param {(...args: ConstructorParameters<typeof Event>) => Event} eventFactory | ||
* @param {EventInit | undefined} eventInitDict | ||
*/ | ||
function fireEvent (e, target, eventConstructor = Event, eventInitDict = {}) { | ||
function fireEvent (e, target, eventFactory = (type, init) => new Event(type, init), eventInitDict = {}) { | ||
// 1. If eventConstructor is not given, then let eventConstructor be Event. | ||
@@ -64,3 +65,3 @@ | ||
// 3. Initialize event’s type attribute to e. | ||
const event = new eventConstructor(e, eventInitDict) // eslint-disable-line new-cap | ||
const event = eventFactory(e, eventInitDict) | ||
@@ -116,3 +117,3 @@ // 4. Initialize any other IDL attributes of event as described in the | ||
// object’s url's origin, and the data attribute initialized to dataForEvent. | ||
fireEvent('message', ws, MessageEvent, { | ||
fireEvent('message', ws, createFastMessageEvent, { | ||
origin: ws[kWebSocketURL].origin, | ||
@@ -202,3 +203,3 @@ data: dataForEvent | ||
// TODO: process.nextTick | ||
fireEvent('error', ws, ErrorEvent, { | ||
fireEvent('error', ws, (type, init) => new ErrorEvent(type, init), { | ||
error: new Error(reason) | ||
@@ -205,0 +206,0 @@ }) |
@@ -54,3 +54,4 @@ 'use strict' | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'WebSocket constructor' }) | ||
const prefix = 'WebSocket constructor' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
@@ -64,5 +65,5 @@ if (!experimentalWarned) { | ||
const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols) | ||
const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols, prefix, 'options') | ||
url = webidl.converters.USVString(url) | ||
url = webidl.converters.USVString(url, prefix, 'url') | ||
protocols = options.protocols | ||
@@ -164,8 +165,10 @@ | ||
const prefix = 'WebSocket.close' | ||
if (code !== undefined) { | ||
code = webidl.converters['unsigned short'](code, { clamp: true }) | ||
code = webidl.converters['unsigned short'](code, prefix, 'code', { clamp: true }) | ||
} | ||
if (reason !== undefined) { | ||
reason = webidl.converters.USVString(reason) | ||
reason = webidl.converters.USVString(reason, prefix, 'reason') | ||
} | ||
@@ -270,5 +273,6 @@ | ||
webidl.argumentLengthCheck(arguments, 1, { header: 'WebSocket.send' }) | ||
const prefix = 'WebSocket.send' | ||
webidl.argumentLengthCheck(arguments, 1, prefix) | ||
data = webidl.converters.WebSocketSendData(data) | ||
data = webidl.converters.WebSocketSendData(data, prefix, 'data') | ||
@@ -602,3 +606,3 @@ // 1. If this's ready state is CONNECTING, then throw an | ||
webidl.converters['DOMString or sequence<DOMString>'] = function (V) { | ||
webidl.converters['DOMString or sequence<DOMString>'] = function (V, prefix, argument) { | ||
if (webidl.util.Type(V) === 'Object' && Symbol.iterator in V) { | ||
@@ -608,3 +612,3 @@ return webidl.converters['sequence<DOMString>'](V) | ||
return webidl.converters.DOMString(V) | ||
return webidl.converters.DOMString(V, prefix, argument) | ||
} | ||
@@ -617,5 +621,3 @@ | ||
converter: webidl.converters['DOMString or sequence<DOMString>'], | ||
get defaultValue () { | ||
return [] | ||
} | ||
defaultValue: () => new Array(0) | ||
}, | ||
@@ -625,5 +627,3 @@ { | ||
converter: (V) => V, | ||
get defaultValue () { | ||
return getGlobalDispatcher() | ||
} | ||
defaultValue: () => getGlobalDispatcher() | ||
}, | ||
@@ -630,0 +630,0 @@ { |
{ | ||
"name": "undici", | ||
"version": "6.14.1", | ||
"version": "6.15.0", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -103,2 +103,3 @@ "homepage": "https://undici.nodejs.org", | ||
"devDependencies": { | ||
"@fastify/busboy": "2.1.1", | ||
"@matteo.collina/tspl": "^0.1.1", | ||
@@ -122,3 +123,2 @@ "@sinonjs/fake-timers": "^11.1.0", | ||
"proxy": "^2.1.1", | ||
"sinon": "^17.0.1", | ||
"snazzy": "^9.0.0", | ||
@@ -125,0 +125,0 @@ "standard": "^17.0.0", |
@@ -58,3 +58,5 @@ // These types are not exported, and are only used internally | ||
signedness: 'signed' | 'unsigned', | ||
opts?: ConvertToIntOpts | ||
opts?: ConvertToIntOpts, | ||
prefix: string, | ||
argument: string | ||
): number | ||
@@ -77,3 +79,3 @@ | ||
*/ | ||
DOMString (V: unknown, opts?: { | ||
DOMString (V: unknown, prefix: string, argument: string, opts?: { | ||
legacyNullToEmptyString: boolean | ||
@@ -85,3 +87,3 @@ }): string | ||
*/ | ||
ByteString (V: unknown): string | ||
ByteString (V: unknown, prefix: string, argument: string): string | ||
@@ -210,3 +212,3 @@ /** | ||
key: string, | ||
defaultValue?: unknown, | ||
defaultValue?: () => unknown, | ||
required?: boolean, | ||
@@ -225,6 +227,3 @@ converter: (...args: unknown[]) => unknown, | ||
argumentLengthCheck (args: { length: number }, min: number, context: { | ||
header: string | ||
message?: string | ||
}): void | ||
argumentLengthCheck (args: { length: number }, min: number, context: string): void | ||
} |
Sorry, the diff of this file is too big to display
1112970
23389