undici 6.14.0 → 6.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ Returns: `Client`
23
23
  * **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
24
24
  * **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
25
25
  * **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
26
- * **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
26
+ * **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `2e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 2 seconds.
27
27
  * **maxHeaderSize** `number | null` (optional) - Default: `--max-http-header-size` or `16384` - The maximum length of request headers in bytes. Defaults to Node.js' --max-http-header-size or 16KiB.
28
28
  * **maxResponseSize** `number | null` (optional) - Default: `-1` - The maximum length of response body in bytes. Set to `-1` to disable.
29
29
  * **pipelining** `number | null` (optional) - Default: `1` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections.
@@ -4,11 +4,11 @@ Stability: Experimental.
4
4
 
5
5
  Extends: `undici.Dispatcher`
6
6
 
7
- EnvHttpProxyAgent automatically reads the proxy configuration from the environment variables `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` and sets up the proxy agents accordingly. When `HTTP_PROXY` and `HTTPS_PROXY` are set, `HTTP_PROXY` is used for HTTP requests and `HTTPS_PROXY` is used for HTTPS requests. If only `HTTP_PROXY` is set, `HTTP_PROXY` is used for both HTTP and HTTPS requests. If only `HTTPS_PROXY` is set, it is only used for HTTPS requests.
7
+ EnvHttpProxyAgent automatically reads the proxy configuration from the environment variables `http_proxy`, `https_proxy`, and `no_proxy` and sets up the proxy agents accordingly. When `http_proxy` and `https_proxy` are set, `http_proxy` is used for HTTP requests and `https_proxy` is used for HTTPS requests. If only `http_proxy` is set, `http_proxy` is used for both HTTP and HTTPS requests. If only `https_proxy` is set, it is only used for HTTPS requests.
8
8
 
9
- `NO_PROXY` is a comma or space-separated list of hostnames that should not be proxied. The list may contain leading wildcard characters (`*`). If `NO_PROXY` is set, the EnvHttpProxyAgent will bypass the proxy for requests to hosts that match the list. If `NO_PROXY` is set to `"*"`, the EnvHttpProxyAgent will bypass the proxy for all requests.
9
+ `no_proxy` is a comma or space-separated list of hostnames that should not be proxied. The list may contain leading wildcard characters (`*`). If `no_proxy` is set, the EnvHttpProxyAgent will bypass the proxy for requests to hosts that match the list. If `no_proxy` is set to `"*"`, the EnvHttpProxyAgent will bypass the proxy for all requests.
10
10
 
11
- Lower case environment variables are also supported: `http_proxy`, `https_proxy`, and `no_proxy`. However, if both the lower case and upper case environment variables are set, the lower case environment variables will be ignored.
11
+ Uppercase environment variables are also supported: `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`. However, if both the lowercase and uppercase environment variables are set, the uppercase environment variables will be ignored.
12
12
 
13
13
  ## `new EnvHttpProxyAgent([options])`
14
14
 
package/index-fetch.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
4
+ const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent')
3
5
  const fetchImpl = require('./lib/web/fetch').fetch
4
6
 
5
7
  module.exports.fetch = function fetch (resource, init = undefined) {
@@ -15,7 +17,16 @@ module.exports.Headers = require('./lib/web/fetch/headers').Headers
15
17
  module.exports.Response = require('./lib/web/fetch/response').Response
16
18
  module.exports.Request = require('./lib/web/fetch/request').Request
17
19
 
20
+ const { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require('./lib/web/websocket/events')
18
21
  module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
19
- module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent
22
+ module.exports.CloseEvent = CloseEvent
23
+ module.exports.ErrorEvent = ErrorEvent
24
+ module.exports.MessageEvent = MessageEvent
25
+ module.exports.createFastMessageEvent = createFastMessageEvent
20
26
 
21
27
  module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource
28
+
29
+ // Expose the fetch implementation to be enabled in Node.js core via a flag
30
+ module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent
31
+ module.exports.getGlobalDispatcher = getGlobalDispatcher
32
+ module.exports.setGlobalDispatcher = setGlobalDispatcher
@@ -226,7 +226,7 @@ class Client extends DispatcherBase {
226
226
  this[kMaxHeadersSize] = maxHeaderSize || http.maxHeaderSize
227
227
  this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
228
228
  this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
229
- this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 1e3 : keepAliveTimeoutThreshold
229
+ this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 2e3 : keepAliveTimeoutThreshold
230
230
  this[kKeepAliveTimeoutValue] = this[kKeepAliveDefaultTimeout]
231
231
  this[kServerName] = null
232
232
  this[kLocalAddress] = localAddress != null ? localAddress : null
@@ -32,14 +32,14 @@ class EnvHttpProxyAgent extends DispatcherBase {
32
32
 
33
33
  this[kNoProxyAgent] = new Agent(agentOpts)
34
34
 
35
- const HTTP_PROXY = httpProxy ?? process.env.HTTP_PROXY ?? process.env.http_proxy
35
+ const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY
36
36
  if (HTTP_PROXY) {
37
37
  this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY })
38
38
  } else {
39
39
  this[kHttpProxyAgent] = this[kNoProxyAgent]
40
40
  }
41
41
 
42
- const HTTPS_PROXY = httpsProxy ?? process.env.HTTPS_PROXY ?? process.env.https_proxy
42
+ const HTTPS_PROXY = httpsProxy ?? process.env.https_proxy ?? process.env.HTTPS_PROXY
43
43
  if (HTTPS_PROXY) {
44
44
  this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTPS_PROXY })
45
45
  } else {
@@ -153,7 +153,7 @@ class EnvHttpProxyAgent extends DispatcherBase {
153
153
  }
154
154
 
155
155
  get #noProxyEnv () {
156
- return process.env.NO_PROXY ?? process.env.no_proxy ?? ''
156
+ return process.env.no_proxy ?? process.env.NO_PROXY ?? ''
157
157
  }
158
158
  }
159
159
 
@@ -7,9 +7,7 @@ const { isDisturbed, parseHeaders, parseRangeHeader } = require('../core/util')
7
7
 
8
8
  function calculateRetryAfterHeader (retryAfter) {
9
9
  const current = Date.now()
10
- const diff = new Date(retryAfter).getTime() - current
11
-
12
- return diff
10
+ return new Date(retryAfter).getTime() - current
13
11
  }
14
12
 
15
13
  class RetryHandler {
@@ -116,11 +114,7 @@ class RetryHandler {
116
114
  const { counter } = state
117
115
 
118
116
  // Any code that is not a Undici's originated and allowed to retry
119
- if (
120
- code &&
121
- code !== 'UND_ERR_REQ_RETRY' &&
122
- !errorCodes.includes(code)
123
- ) {
117
+ if (code && code !== 'UND_ERR_REQ_RETRY' && !errorCodes.includes(code)) {
124
118
  cb(err)
125
119
  return
126
120
  }
@@ -246,10 +240,7 @@ class RetryHandler {
246
240
  start != null && Number.isFinite(start),
247
241
  'content-range mismatch'
248
242
  )
249
- assert(
250
- end != null && Number.isFinite(end),
251
- 'invalid content-length'
252
- )
243
+ assert(end != null && Number.isFinite(end), 'invalid content-length')
253
244
 
254
245
  this.start = start
255
246
  this.end = end
@@ -270,6 +261,13 @@ class RetryHandler {
270
261
  this.resume = resume
271
262
  this.etag = headers.etag != null ? headers.etag : null
272
263
 
264
+ // Weak etags are not useful for comparison nor cache
265
+ // for instance not safe to assume if the response is byte-per-byte
266
+ // equal
267
+ if (this.etag != null && this.etag.startsWith('W/')) {
268
+ this.etag = null
269
+ }
270
+
273
271
  return this.handler.onHeaders(
274
272
  statusCode,
275
273
  rawHeaders,
@@ -308,7 +306,9 @@ class RetryHandler {
308
306
  // and server error response
309
307
  if (this.retryCount - this.retryCountCheckpoint > 0) {
310
308
  // We count the difference between the last checkpoint and the current retry count
311
- this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint)
309
+ this.retryCount =
310
+ this.retryCountCheckpoint +
311
+ (this.retryCount - this.retryCountCheckpoint)
312
312
  } else {
313
313
  this.retryCount += 1
314
314
  }
@@ -328,11 +328,18 @@ class RetryHandler {
328
328
  }
329
329
 
330
330
  if (this.start !== 0) {
331
+ const headers = { range: `bytes=${this.start}-${this.end ?? ''}` }
332
+
333
+ // Weak etag check - weak etags will make comparison algorithms never match
334
+ if (this.etag != null) {
335
+ headers['if-match'] = this.etag
336
+ }
337
+
331
338
  this.opts = {
332
339
  ...this.opts,
333
340
  headers: {
334
341
  ...this.opts.headers,
335
- range: `bytes=${this.start}-${this.end ?? ''}`
342
+ ...headers
336
343
  }
337
344
  }
338
345
  }
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const TICK_MS = 499
4
+
3
5
  let fastNow = Date.now()
4
6
  let fastNowTimeout
5
7
 
@@ -14,7 +16,7 @@ function onTimeout () {
14
16
  const timer = fastTimers[idx]
15
17
 
16
18
  if (timer.state === 0) {
17
- timer.state = fastNow + timer.delay
19
+ timer.state = fastNow + timer.delay - TICK_MS
18
20
  } else if (timer.state > 0 && fastNow >= timer.state) {
19
21
  timer.state = -1
20
22
  timer.callback(timer.opaque)
@@ -43,7 +45,7 @@ function refreshTimeout () {
43
45
  fastNowTimeout.refresh()
44
46
  } else {
45
47
  clearTimeout(fastNowTimeout)
46
- fastNowTimeout = setTimeout(onTimeout, 1e3)
48
+ fastNowTimeout = setTimeout(onTimeout, TICK_MS)
47
49
  if (fastNowTimeout.unref) {
48
50
  fastNowTimeout.unref()
49
51
  }
@@ -83,7 +85,7 @@ class Timeout {
83
85
 
84
86
  module.exports = {
85
87
  setTimeout (callback, delay, opaque) {
86
- return delay < 1e3
88
+ return delay <= 1e3
87
89
  ? setTimeout(callback, delay, opaque)
88
90
  : new Timeout(callback, delay, opaque)
89
91
  },
@@ -42,10 +42,12 @@ class Cache {
42
42
 
43
43
  async match (request, options = {}) {
44
44
  webidl.brandCheck(this, Cache)
45
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.match' })
46
45
 
47
- request = webidl.converters.RequestInfo(request)
48
- options = webidl.converters.CacheQueryOptions(options)
46
+ const prefix = 'Cache.match'
47
+ webidl.argumentLengthCheck(arguments, 1, prefix)
48
+
49
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
50
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
49
51
 
50
52
  const p = this.#internalMatchAll(request, options, 1)
51
53
 
@@ -59,17 +61,20 @@ class Cache {
59
61
  async matchAll (request = undefined, options = {}) {
60
62
  webidl.brandCheck(this, Cache)
61
63
 
62
- if (request !== undefined) request = webidl.converters.RequestInfo(request)
63
- options = webidl.converters.CacheQueryOptions(options)
64
+ const prefix = 'Cache.matchAll'
65
+ if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
66
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
64
67
 
65
68
  return this.#internalMatchAll(request, options)
66
69
  }
67
70
 
68
71
  async add (request) {
69
72
  webidl.brandCheck(this, Cache)
70
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.add' })
71
73
 
72
- request = webidl.converters.RequestInfo(request)
74
+ const prefix = 'Cache.add'
75
+ webidl.argumentLengthCheck(arguments, 1, prefix)
76
+
77
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
73
78
 
74
79
  // 1.
75
80
  const requests = [request]
@@ -83,7 +88,9 @@ class Cache {
83
88
 
84
89
  async addAll (requests) {
85
90
  webidl.brandCheck(this, Cache)
86
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })
91
+
92
+ const prefix = 'Cache.addAll'
93
+ webidl.argumentLengthCheck(arguments, 1, prefix)
87
94
 
88
95
  // 1.
89
96
  const responsePromises = []
@@ -95,7 +102,7 @@ class Cache {
95
102
  for (let request of requests) {
96
103
  if (request === undefined) {
97
104
  throw webidl.errors.conversionFailed({
98
- prefix: 'Cache.addAll',
105
+ prefix,
99
106
  argument: 'Argument 1',
100
107
  types: ['undefined is not allowed']
101
108
  })
@@ -113,7 +120,7 @@ class Cache {
113
120
  // 3.2
114
121
  if (!urlIsHttpHttpsScheme(r.url) || r.method !== 'GET') {
115
122
  throw webidl.errors.exception({
116
- header: 'Cache.addAll',
123
+ header: prefix,
117
124
  message: 'Expected http/s scheme when method is not GET.'
118
125
  })
119
126
  }
@@ -131,7 +138,7 @@ class Cache {
131
138
  // 5.2
132
139
  if (!urlIsHttpHttpsScheme(r.url)) {
133
140
  throw webidl.errors.exception({
134
- header: 'Cache.addAll',
141
+ header: prefix,
135
142
  message: 'Expected http/s scheme.'
136
143
  })
137
144
  }
@@ -251,10 +258,12 @@ class Cache {
251
258
 
252
259
  async put (request, response) {
253
260
  webidl.brandCheck(this, Cache)
254
- webidl.argumentLengthCheck(arguments, 2, { header: 'Cache.put' })
255
261
 
256
- request = webidl.converters.RequestInfo(request)
257
- response = webidl.converters.Response(response)
262
+ const prefix = 'Cache.put'
263
+ webidl.argumentLengthCheck(arguments, 2, prefix)
264
+
265
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
266
+ response = webidl.converters.Response(response, prefix, 'response')
258
267
 
259
268
  // 1.
260
269
  let innerRequest = null
@@ -269,7 +278,7 @@ class Cache {
269
278
  // 4.
270
279
  if (!urlIsHttpHttpsScheme(innerRequest.url) || innerRequest.method !== 'GET') {
271
280
  throw webidl.errors.exception({
272
- header: 'Cache.put',
281
+ header: prefix,
273
282
  message: 'Expected an http/s scheme when method is not GET'
274
283
  })
275
284
  }
@@ -280,7 +289,7 @@ class Cache {
280
289
  // 6.
281
290
  if (innerResponse.status === 206) {
282
291
  throw webidl.errors.exception({
283
- header: 'Cache.put',
292
+ header: prefix,
284
293
  message: 'Got 206 status'
285
294
  })
286
295
  }
@@ -295,7 +304,7 @@ class Cache {
295
304
  // 7.2.1
296
305
  if (fieldValue === '*') {
297
306
  throw webidl.errors.exception({
298
- header: 'Cache.put',
307
+ header: prefix,
299
308
  message: 'Got * vary field value'
300
309
  })
301
310
  }
@@ -305,7 +314,7 @@ class Cache {
305
314
  // 8.
306
315
  if (innerResponse.body && (isDisturbed(innerResponse.body.stream) || innerResponse.body.stream.locked)) {
307
316
  throw webidl.errors.exception({
308
- header: 'Cache.put',
317
+ header: prefix,
309
318
  message: 'Response body is locked or disturbed'
310
319
  })
311
320
  }
@@ -380,10 +389,12 @@ class Cache {
380
389
 
381
390
  async delete (request, options = {}) {
382
391
  webidl.brandCheck(this, Cache)
383
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.delete' })
384
392
 
385
- request = webidl.converters.RequestInfo(request)
386
- options = webidl.converters.CacheQueryOptions(options)
393
+ const prefix = 'Cache.delete'
394
+ webidl.argumentLengthCheck(arguments, 1, prefix)
395
+
396
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
397
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
387
398
 
388
399
  /**
389
400
  * @type {Request}
@@ -445,8 +456,10 @@ class Cache {
445
456
  async keys (request = undefined, options = {}) {
446
457
  webidl.brandCheck(this, Cache)
447
458
 
448
- if (request !== undefined) request = webidl.converters.RequestInfo(request)
449
- options = webidl.converters.CacheQueryOptions(options)
459
+ const prefix = 'Cache.keys'
460
+
461
+ if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
462
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
450
463
 
451
464
  // 1.
452
465
  let r = null
@@ -810,17 +823,17 @@ const cacheQueryOptionConverters = [
810
823
  {
811
824
  key: 'ignoreSearch',
812
825
  converter: webidl.converters.boolean,
813
- defaultValue: false
826
+ defaultValue: () => false
814
827
  },
815
828
  {
816
829
  key: 'ignoreMethod',
817
830
  converter: webidl.converters.boolean,
818
- defaultValue: false
831
+ defaultValue: () => false
819
832
  },
820
833
  {
821
834
  key: 'ignoreVary',
822
835
  converter: webidl.converters.boolean,
823
- defaultValue: false
836
+ defaultValue: () => false
824
837
  }
825
838
  ]
826
839
 
@@ -20,7 +20,7 @@ class CacheStorage {
20
20
 
21
21
  async match (request, options = {}) {
22
22
  webidl.brandCheck(this, CacheStorage)
23
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.match' })
23
+ webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match')
24
24
 
25
25
  request = webidl.converters.RequestInfo(request)
26
26
  options = webidl.converters.MultiCacheQueryOptions(options)
@@ -57,9 +57,11 @@ class CacheStorage {
57
57
  */
58
58
  async has (cacheName) {
59
59
  webidl.brandCheck(this, CacheStorage)
60
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.has' })
61
60
 
62
- cacheName = webidl.converters.DOMString(cacheName)
61
+ const prefix = 'CacheStorage.has'
62
+ webidl.argumentLengthCheck(arguments, 1, prefix)
63
+
64
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
63
65
 
64
66
  // 2.1.1
65
67
  // 2.2
@@ -73,9 +75,11 @@ class CacheStorage {
73
75
  */
74
76
  async open (cacheName) {
75
77
  webidl.brandCheck(this, CacheStorage)
76
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.open' })
77
78
 
78
- cacheName = webidl.converters.DOMString(cacheName)
79
+ const prefix = 'CacheStorage.open'
80
+ webidl.argumentLengthCheck(arguments, 1, prefix)
81
+
82
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
79
83
 
80
84
  // 2.1
81
85
  if (this.#caches.has(cacheName)) {
@@ -105,9 +109,11 @@ class CacheStorage {
105
109
  */
106
110
  async delete (cacheName) {
107
111
  webidl.brandCheck(this, CacheStorage)
108
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.delete' })
109
112
 
110
- cacheName = webidl.converters.DOMString(cacheName)
113
+ const prefix = 'CacheStorage.delete'
114
+ webidl.argumentLengthCheck(arguments, 1, prefix)
115
+
116
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
111
117
 
112
118
  return this.#caches.delete(cacheName)
113
119
  }
@@ -24,7 +24,7 @@ const { Headers } = require('../fetch/headers')
24
24
  * @returns {Record<string, string>}
25
25
  */
26
26
  function getCookies (headers) {
27
- webidl.argumentLengthCheck(arguments, 1, { header: 'getCookies' })
27
+ webidl.argumentLengthCheck(arguments, 1, 'getCookies')
28
28
 
29
29
  webidl.brandCheck(headers, Headers, { strict: false })
30
30
 
@@ -51,11 +51,12 @@ function getCookies (headers) {
51
51
  * @returns {void}
52
52
  */
53
53
  function deleteCookie (headers, name, attributes) {
54
- webidl.argumentLengthCheck(arguments, 2, { header: 'deleteCookie' })
55
-
56
54
  webidl.brandCheck(headers, Headers, { strict: false })
57
55
 
58
- name = webidl.converters.DOMString(name)
56
+ const prefix = 'deleteCookie'
57
+ webidl.argumentLengthCheck(arguments, 2, prefix)
58
+
59
+ name = webidl.converters.DOMString(name, prefix, 'name')
59
60
  attributes = webidl.converters.DeleteCookieAttributes(attributes)
60
61
 
61
62
  // Matches behavior of
@@ -73,7 +74,7 @@ function deleteCookie (headers, name, attributes) {
73
74
  * @returns {Cookie[]}
74
75
  */
75
76
  function getSetCookies (headers) {
76
- webidl.argumentLengthCheck(arguments, 1, { header: 'getSetCookies' })
77
+ webidl.argumentLengthCheck(arguments, 1, 'getSetCookies')
77
78
 
78
79
  webidl.brandCheck(headers, Headers, { strict: false })
79
80
 
@@ -93,7 +94,7 @@ function getSetCookies (headers) {
93
94
  * @returns {void}
94
95
  */
95
96
  function setCookie (headers, cookie) {
96
- webidl.argumentLengthCheck(arguments, 2, { header: 'setCookie' })
97
+ webidl.argumentLengthCheck(arguments, 2, 'setCookie')
97
98
 
98
99
  webidl.brandCheck(headers, Headers, { strict: false })
99
100
 
@@ -110,12 +111,12 @@ webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
110
111
  {
111
112
  converter: webidl.nullableConverter(webidl.converters.DOMString),
112
113
  key: 'path',
113
- defaultValue: null
114
+ defaultValue: () => null
114
115
  },
115
116
  {
116
117
  converter: webidl.nullableConverter(webidl.converters.DOMString),
117
118
  key: 'domain',
118
- defaultValue: null
119
+ defaultValue: () => null
119
120
  }
120
121
  ])
121
122
 
@@ -137,32 +138,32 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
137
138
  return new Date(value)
138
139
  }),
139
140
  key: 'expires',
140
- defaultValue: null
141
+ defaultValue: () => null
141
142
  },
142
143
  {
143
144
  converter: webidl.nullableConverter(webidl.converters['long long']),
144
145
  key: 'maxAge',
145
- defaultValue: null
146
+ defaultValue: () => null
146
147
  },
147
148
  {
148
149
  converter: webidl.nullableConverter(webidl.converters.DOMString),
149
150
  key: 'domain',
150
- defaultValue: null
151
+ defaultValue: () => null
151
152
  },
152
153
  {
153
154
  converter: webidl.nullableConverter(webidl.converters.DOMString),
154
155
  key: 'path',
155
- defaultValue: null
156
+ defaultValue: () => null
156
157
  },
157
158
  {
158
159
  converter: webidl.nullableConverter(webidl.converters.boolean),
159
160
  key: 'secure',
160
- defaultValue: null
161
+ defaultValue: () => null
161
162
  },
162
163
  {
163
164
  converter: webidl.nullableConverter(webidl.converters.boolean),
164
165
  key: 'httpOnly',
165
- defaultValue: null
166
+ defaultValue: () => null
166
167
  },
167
168
  {
168
169
  converter: webidl.converters.USVString,
@@ -172,7 +173,7 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
172
173
  {
173
174
  converter: webidl.sequenceConverter(webidl.converters.DOMString),
174
175
  key: 'unparsed',
175
- defaultValue: []
176
+ defaultValue: () => new Array(0)
176
177
  }
177
178
  ])
178
179
 
@@ -6,7 +6,7 @@ const { makeRequest } = require('../fetch/request')
6
6
  const { webidl } = require('../fetch/webidl')
7
7
  const { EventSourceStream } = require('./eventsource-stream')
8
8
  const { parseMIMEType } = require('../fetch/data-url')
9
- const { MessageEvent } = require('../websocket/events')
9
+ const { createFastMessageEvent } = require('../websocket/events')
10
10
  const { isNetworkError } = require('../fetch/response')
11
11
  const { delay } = require('./util')
12
12
  const { kEnumerableProperty } = require('../../core/util')
@@ -105,7 +105,8 @@ class EventSource extends EventTarget {
105
105
  // 1. Let ev be a new EventSource object.
106
106
  super()
107
107
 
108
- webidl.argumentLengthCheck(arguments, 1, { header: 'EventSource constructor' })
108
+ const prefix = 'EventSource constructor'
109
+ webidl.argumentLengthCheck(arguments, 1, prefix)
109
110
 
110
111
  if (!experimentalWarned) {
111
112
  experimentalWarned = true
@@ -114,8 +115,8 @@ class EventSource extends EventTarget {
114
115
  })
115
116
  }
116
117
 
117
- url = webidl.converters.USVString(url)
118
- eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict)
118
+ url = webidl.converters.USVString(url, prefix, 'url')
119
+ eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')
119
120
 
120
121
  this.#dispatcher = eventSourceInitDict.dispatcher
121
122
  this.#state = {
@@ -290,7 +291,7 @@ class EventSource extends EventTarget {
290
291
  const eventSourceStream = new EventSourceStream({
291
292
  eventSourceSettings: this.#state,
292
293
  push: (event) => {
293
- this.dispatchEvent(new MessageEvent(
294
+ this.dispatchEvent(createFastMessageEvent(
294
295
  event.type,
295
296
  event.options
296
297
  ))
@@ -463,7 +464,7 @@ webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
463
464
  {
464
465
  key: 'withCredentials',
465
466
  converter: webidl.converters.boolean,
466
- defaultValue: false
467
+ defaultValue: () => false
467
468
  },
468
469
  {
469
470
  key: 'dispatcher', // undici only
@@ -33,9 +33,10 @@ class CompatFinalizer {
33
33
  }
34
34
 
35
35
  module.exports = function () {
36
- // FIXME: remove workaround when the Node bug is fixed
36
+ // FIXME: remove workaround when the Node bug is backported to v18
37
37
  // https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
38
- if (process.env.NODE_V8_COVERAGE) {
38
+ if (process.env.NODE_V8_COVERAGE && process.version.startsWith('v18')) {
39
+ process._rawDebug('Using compatibility WeakRef and FinalizationRegistry')
39
40
  return {
40
41
  WeakRef: CompatWeakRef,
41
42
  FinalizationRegistry: CompatFinalizer