Skip to content

Commit 503c034

Browse files
nodejs-github-botmarco-ippolito
authored andcommittedMay 2, 2024
deps: update undici to 6.6.2
PR-URL: #51667 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 256bcba commit 503c034

File tree

10 files changed

+1265
-536
lines changed

10 files changed

+1265
-536
lines changed
 

‎deps/undici/src/index-fetch.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ module.exports.FormData = require('./lib/fetch/formdata').FormData
1414
module.exports.Headers = require('./lib/fetch/headers').Headers
1515
module.exports.Response = require('./lib/fetch/response').Response
1616
module.exports.Request = require('./lib/fetch/request').Request
17+
1718
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket
19+
20+
module.exports.EventSource = require('./lib/eventsource/eventsource').EventSource

‎deps/undici/src/lib/fetch/formdata.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
const { isBlobLike, toUSVString, makeIterator } = require('./util')
44
const { kState } = require('./symbols')
5+
const { kEnumerableProperty } = require('../core/util')
56
const { File: UndiciFile, FileLike, isFileLike } = require('./file')
67
const { webidl } = require('./webidl')
7-
const { Blob, File: NativeFile } = require('node:buffer')
8+
const { File: NativeFile } = require('node:buffer')
89

910
/** @type {globalThis['File']} */
1011
const File = NativeFile ?? UndiciFile
@@ -158,29 +159,32 @@ class FormData {
158159
webidl.brandCheck(this, FormData)
159160

160161
return makeIterator(
161-
() => this[kState].map(pair => [pair.name, pair.value]),
162+
() => this[kState],
162163
'FormData',
163-
'key+value'
164+
'key+value',
165+
'name', 'value'
164166
)
165167
}
166168

167169
keys () {
168170
webidl.brandCheck(this, FormData)
169171

170172
return makeIterator(
171-
() => this[kState].map(pair => [pair.name, pair.value]),
173+
() => this[kState],
172174
'FormData',
173-
'key'
175+
'key',
176+
'name', 'value'
174177
)
175178
}
176179

177180
values () {
178181
webidl.brandCheck(this, FormData)
179182

180183
return makeIterator(
181-
() => this[kState].map(pair => [pair.name, pair.value]),
184+
() => this[kState],
182185
'FormData',
183-
'value'
186+
'value',
187+
'name', 'value'
184188
)
185189
}
186190

@@ -200,14 +204,25 @@ class FormData {
200204
}
201205

202206
for (const [key, value] of this) {
203-
callbackFn.apply(thisArg, [value, key, this])
207+
callbackFn.call(thisArg, value, key, this)
204208
}
205209
}
206210
}
207211

208212
FormData.prototype[Symbol.iterator] = FormData.prototype.entries
209213

210214
Object.defineProperties(FormData.prototype, {
215+
append: kEnumerableProperty,
216+
delete: kEnumerableProperty,
217+
get: kEnumerableProperty,
218+
getAll: kEnumerableProperty,
219+
has: kEnumerableProperty,
220+
set: kEnumerableProperty,
221+
entries: kEnumerableProperty,
222+
keys: kEnumerableProperty,
223+
values: kEnumerableProperty,
224+
forEach: kEnumerableProperty,
225+
[Symbol.iterator]: { enumerable: false },
211226
[Symbol.toStringTag]: {
212227
value: 'FormData',
213228
configurable: true
@@ -225,7 +240,7 @@ function makeEntry (name, value, filename) {
225240
// 1. Set name to the result of converting name into a scalar value string.
226241
// "To convert a string into a scalar value string, replace any surrogates
227242
// with U+FFFD."
228-
// see: https://nodejs.org/dist/latest-v18.x/docs/api/buffer.html#buftostringencoding-start-end
243+
// see: https://nodejs.org/dist/latest-v20.x/docs/api/buffer.html#buftostringencoding-start-end
229244
name = Buffer.from(name).toString('utf8')
230245

231246
// 2. If value is a string, then set value to the result of converting

‎deps/undici/src/lib/fetch/headers.js

+10-25
Original file line numberDiff line numberDiff line change
@@ -492,48 +492,33 @@ class Headers {
492492
keys () {
493493
webidl.brandCheck(this, Headers)
494494

495-
if (this[kGuard] === 'immutable') {
496-
const value = this[kHeadersSortedMap]
497-
return makeIterator(() => value, 'Headers',
498-
'key')
499-
}
500-
501495
return makeIterator(
502-
() => [...this[kHeadersSortedMap].values()],
496+
() => this[kHeadersSortedMap],
503497
'Headers',
504-
'key'
498+
'key',
499+
0, 1
505500
)
506501
}
507502

508503
values () {
509504
webidl.brandCheck(this, Headers)
510505

511-
if (this[kGuard] === 'immutable') {
512-
const value = this[kHeadersSortedMap]
513-
return makeIterator(() => value, 'Headers',
514-
'value')
515-
}
516-
517506
return makeIterator(
518-
() => [...this[kHeadersSortedMap].values()],
507+
() => this[kHeadersSortedMap],
519508
'Headers',
520-
'value'
509+
'value',
510+
0, 1
521511
)
522512
}
523513

524514
entries () {
525515
webidl.brandCheck(this, Headers)
526516

527-
if (this[kGuard] === 'immutable') {
528-
const value = this[kHeadersSortedMap]
529-
return makeIterator(() => value, 'Headers',
530-
'key+value')
531-
}
532-
533517
return makeIterator(
534-
() => [...this[kHeadersSortedMap].values()],
518+
() => this[kHeadersSortedMap],
535519
'Headers',
536-
'key+value'
520+
'key+value',
521+
0, 1
537522
)
538523
}
539524

@@ -553,7 +538,7 @@ class Headers {
553538
}
554539

555540
for (const [key, value] of this) {
556-
callbackFn.apply(thisArg, [value, key, this])
541+
callbackFn.call(thisArg, value, key, this)
557542
}
558543
}
559544

‎deps/undici/src/lib/fetch/index.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1099,11 +1099,12 @@ function fetchFinale (fetchParams, response) {
10991099

11001100
const byteStream = new ReadableStream({
11011101
readableStream: transformStream.readable,
1102-
async start (controller) {
1103-
const reader = this.readableStream.getReader()
1104-
1105-
while (true) {
1106-
const { done, value } = await reader.read()
1102+
async start () {
1103+
this._bodyReader = this.readableStream.getReader()
1104+
},
1105+
async pull (controller) {
1106+
while (controller.desiredSize >= 0) {
1107+
const { done, value } = await this._bodyReader.read()
11071108

11081109
if (done) {
11091110
queueMicrotask(() => readableStreamClose(controller))
@@ -1113,6 +1114,7 @@ function fetchFinale (fetchParams, response) {
11131114
controller.enqueue(value)
11141115
}
11151116
},
1117+
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 }),
11161118
type: 'bytes'
11171119
})
11181120

@@ -1904,8 +1906,8 @@ async function httpNetworkFetch (
19041906

19051907
// 11. Let pullAlgorithm be an action that resumes the ongoing fetch
19061908
// if it is suspended.
1907-
const pullAlgorithm = () => {
1908-
fetchParams.controller.resume()
1909+
const pullAlgorithm = async () => {
1910+
await fetchParams.controller.resume()
19091911
}
19101912

19111913
// 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s
@@ -1927,6 +1929,7 @@ async function httpNetworkFetch (
19271929
// cancelAlgorithm set to cancelAlgorithm.
19281930
const stream = new ReadableStream(
19291931
{
1932+
highWaterMark: 16384,
19301933
async start (controller) {
19311934
fetchParams.controller.controller = controller
19321935
},
@@ -1936,7 +1939,8 @@ async function httpNetworkFetch (
19361939
async cancel (reason) {
19371940
await cancelAlgorithm(reason)
19381941
},
1939-
type: 'bytes'
1942+
type: 'bytes',
1943+
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 })
19401944
}
19411945
)
19421946

@@ -2029,7 +2033,7 @@ async function httpNetworkFetch (
20292033

20302034
// 9. If stream doesn’t need more data ask the user agent to suspend
20312035
// the ongoing fetch.
2032-
if (!fetchParams.controller.controller.desiredSize) {
2036+
if (fetchParams.controller.controller.desiredSize <= 0) {
20332037
return
20342038
}
20352039
}

‎deps/undici/src/lib/fetch/util.js

+62-60
Original file line numberDiff line numberDiff line change
@@ -808,19 +808,23 @@ const esIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbo
808808

809809
/**
810810
* @see https://webidl.spec.whatwg.org/#dfn-iterator-prototype-object
811-
* @param {() => unknown[]} iterator
811+
* @param {() => unknown} iterator
812812
* @param {string} name name of the instance
813813
* @param {'key'|'value'|'key+value'} kind
814+
* @param {string | number} [keyIndex]
815+
* @param {string | number} [valueIndex]
814816
*/
815-
function makeIterator (iterator, name, kind) {
817+
function makeIterator (iterator, name, kind, keyIndex = 0, valueIndex = 1) {
816818
const object = {
817819
index: 0,
818820
kind,
819821
target: iterator
820822
}
823+
// The [[Prototype]] internal slot of an iterator prototype object must be %IteratorPrototype%.
824+
const iteratorObject = Object.create(esIteratorPrototype)
821825

822-
const i = {
823-
next () {
826+
Object.defineProperty(iteratorObject, 'next', {
827+
value: function next () {
824828
// 1. Let interface be the interface for which the iterator prototype object exists.
825829

826830
// 2. Let thisValue be the this value.
@@ -832,7 +836,7 @@ function makeIterator (iterator, name, kind) {
832836

833837
// 5. If object is not a default iterator object for interface,
834838
// then throw a TypeError.
835-
if (Object.getPrototypeOf(this) !== i) {
839+
if (Object.getPrototypeOf(this) !== iteratorObject) {
836840
throw new TypeError(
837841
`'next' called on an object that does not implement interface ${name} Iterator.`
838842
)
@@ -852,68 +856,66 @@ function makeIterator (iterator, name, kind) {
852856
if (index >= len) {
853857
return { value: undefined, done: true }
854858
}
855-
856859
// 11. Let pair be the entry in values at index index.
857-
const pair = values[index]
858-
860+
const { [keyIndex]: key, [valueIndex]: value } = values[index]
859861
// 12. Set object’s index to index + 1.
860862
object.index = index + 1
861-
862863
// 13. Return the iterator result for pair and kind.
863-
return iteratorResult(pair, kind)
864+
// https://webidl.spec.whatwg.org/#iterator-result
865+
// 1. Let result be a value determined by the value of kind:
866+
let result
867+
switch (kind) {
868+
case 'key':
869+
// 1. Let idlKey be pair’s key.
870+
// 2. Let key be the result of converting idlKey to an
871+
// ECMAScript value.
872+
// 3. result is key.
873+
result = key
874+
break
875+
case 'value':
876+
// 1. Let idlValue be pair’s value.
877+
// 2. Let value be the result of converting idlValue to
878+
// an ECMAScript value.
879+
// 3. result is value.
880+
result = value
881+
break
882+
case 'key+value':
883+
// 1. Let idlKey be pair’s key.
884+
// 2. Let idlValue be pair’s value.
885+
// 3. Let key be the result of converting idlKey to an
886+
// ECMAScript value.
887+
// 4. Let value be the result of converting idlValue to
888+
// an ECMAScript value.
889+
// 5. Let array be ! ArrayCreate(2).
890+
// 6. Call ! CreateDataProperty(array, "0", key).
891+
// 7. Call ! CreateDataProperty(array, "1", value).
892+
// 8. result is array.
893+
result = [key, value]
894+
break
895+
}
896+
// 2. Return CreateIterResultObject(result, false).
897+
return {
898+
value: result,
899+
done: false
900+
}
864901
},
865-
// The class string of an iterator prototype object for a given interface is the
866-
// result of concatenating the identifier of the interface and the string " Iterator".
867-
[Symbol.toStringTag]: `${name} Iterator`
868-
}
869-
870-
// The [[Prototype]] internal slot of an iterator prototype object must be %IteratorPrototype%.
871-
Object.setPrototypeOf(i, esIteratorPrototype)
872-
// esIteratorPrototype needs to be the prototype of i
873-
// which is the prototype of an empty object. Yes, it's confusing.
874-
return Object.setPrototypeOf({}, i)
875-
}
902+
writable: true,
903+
enumerable: true,
904+
configurable: true
905+
})
876906

877-
// https://webidl.spec.whatwg.org/#iterator-result
878-
function iteratorResult (pair, kind) {
879-
let result
880-
881-
// 1. Let result be a value determined by the value of kind:
882-
switch (kind) {
883-
case 'key': {
884-
// 1. Let idlKey be pair’s key.
885-
// 2. Let key be the result of converting idlKey to an
886-
// ECMAScript value.
887-
// 3. result is key.
888-
result = pair[0]
889-
break
890-
}
891-
case 'value': {
892-
// 1. Let idlValue be pair’s value.
893-
// 2. Let value be the result of converting idlValue to
894-
// an ECMAScript value.
895-
// 3. result is value.
896-
result = pair[1]
897-
break
898-
}
899-
case 'key+value': {
900-
// 1. Let idlKey be pair’s key.
901-
// 2. Let idlValue be pair’s value.
902-
// 3. Let key be the result of converting idlKey to an
903-
// ECMAScript value.
904-
// 4. Let value be the result of converting idlValue to
905-
// an ECMAScript value.
906-
// 5. Let array be ! ArrayCreate(2).
907-
// 6. Call ! CreateDataProperty(array, "0", key).
908-
// 7. Call ! CreateDataProperty(array, "1", value).
909-
// 8. result is array.
910-
result = pair
911-
break
912-
}
913-
}
907+
// The class string of an iterator prototype object for a given interface is the
908+
// result of concatenating the identifier of the interface and the string " Iterator".
909+
Object.defineProperty(iteratorObject, Symbol.toStringTag, {
910+
value: `${name} Iterator`,
911+
writable: false,
912+
enumerable: false,
913+
configurable: true
914+
})
914915

915-
// 2. Return CreateIterResultObject(result, false).
916-
return { value: result, done: false }
916+
// esIteratorPrototype needs to be the prototype of iteratorObject
917+
// which is the prototype of an empty object. Yes, it's confusing.
918+
return Object.create(iteratorObject)
917919
}
918920

919921
/**

‎deps/undici/src/lib/fetch/webidl.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ webidl.errors.invalidArgument = function (context) {
3434

3535
// https://webidl.spec.whatwg.org/#implements
3636
webidl.brandCheck = function (V, I, opts = undefined) {
37-
if (opts?.strict !== false && !(V instanceof I)) {
38-
throw new TypeError('Illegal invocation')
37+
if (opts?.strict !== false) {
38+
if (!(V instanceof I)) {
39+
throw new TypeError('Illegal invocation')
40+
}
3941
} else {
40-
return V?.[Symbol.toStringTag] === I.prototype[Symbol.toStringTag]
42+
if (V?.[Symbol.toStringTag] !== I.prototype[Symbol.toStringTag]) {
43+
throw new TypeError('Illegal invocation')
44+
}
4145
}
4246
}
4347

‎deps/undici/src/package-lock.json

+489-344
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps/undici/src/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undici",
3-
"version": "6.6.0",
3+
"version": "6.6.2",
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"homepage": "https://undici.nodejs.org",
66
"bugs": {
@@ -104,7 +104,7 @@
104104
"@sinonjs/fake-timers": "^11.1.0",
105105
"@types/node": "^18.0.3",
106106
"abort-controller": "^3.0.0",
107-
"borp": "^0.5.0",
107+
"borp": "^0.9.1",
108108
"chai": "^4.3.4",
109109
"chai-as-promised": "^7.1.1",
110110
"chai-iterator": "^3.0.2",
@@ -121,7 +121,7 @@
121121
"jest": "^29.0.2",
122122
"jsdom": "^24.0.0",
123123
"jsfuzz": "^1.0.15",
124-
"mitata": "^0.1.6",
124+
"mitata": "^0.1.8",
125125
"mocha": "^10.0.0",
126126
"p-timeout": "^3.2.0",
127127
"pre-commit": "^1.2.2",

‎deps/undici/undici.js

+653-82
Large diffs are not rendered by default.

‎src/undici_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-undici.sh
33
#ifndef SRC_UNDICI_VERSION_H_
44
#define SRC_UNDICI_VERSION_H_
5-
#define UNDICI_VERSION "6.6.0"
5+
#define UNDICI_VERSION "6.6.2"
66
#endif // SRC_UNDICI_VERSION_H_

0 commit comments

Comments
 (0)
Please sign in to comment.