@@ -15930,9 +15930,23 @@ const kWeight = Symbol('kWeight')
15930
15930
const kMaxWeightPerServer = Symbol('kMaxWeightPerServer')
15931
15931
const kErrorPenalty = Symbol('kErrorPenalty')
15932
15932
15933
+ /**
15934
+ * Calculate the greatest common divisor of two numbers by
15935
+ * using the Euclidean algorithm.
15936
+ *
15937
+ * @param {number} a
15938
+ * @param {number} b
15939
+ * @returns {number}
15940
+ */
15933
15941
function getGreatestCommonDivisor (a, b) {
15934
- if (b === 0) return a
15935
- return getGreatestCommonDivisor(b, a % b)
15942
+ if (a === 0) return b
15943
+
15944
+ while (b !== 0) {
15945
+ const t = b
15946
+ b = a % b
15947
+ a = t
15948
+ }
15949
+ return a
15936
15950
}
15937
15951
15938
15952
function defaultFactory (origin, opts) {
@@ -16010,7 +16024,12 @@ class BalancedPool extends PoolBase {
16010
16024
}
16011
16025
16012
16026
_updateBalancedPoolStats () {
16013
- this[kGreatestCommonDivisor] = this[kClients].map(p => p[kWeight]).reduce(getGreatestCommonDivisor, 0)
16027
+ let result = 0
16028
+ for (let i = 0; i < this[kClients].length; i++) {
16029
+ result = getGreatestCommonDivisor(this[kClients][i][kWeight], result)
16030
+ }
16031
+
16032
+ this[kGreatestCommonDivisor] = result
16014
16033
}
16015
16034
16016
16035
removeUpstream (upstream) {
@@ -25197,12 +25216,25 @@ const { kState } = __nccwpck_require__(749)
25197
25216
const { webidl } = __nccwpck_require__(4890)
25198
25217
const { Blob } = __nccwpck_require__(2254)
25199
25218
const assert = __nccwpck_require__(8061)
25200
- const { isErrored } = __nccwpck_require__(3983 )
25219
+ const { isErrored, isDisturbed } = __nccwpck_require__(4492 )
25201
25220
const { isArrayBuffer } = __nccwpck_require__(3746)
25202
25221
const { serializeAMimeType } = __nccwpck_require__(7704)
25203
25222
const { multipartFormDataParser } = __nccwpck_require__(7991)
25204
25223
25205
25224
const textEncoder = new TextEncoder()
25225
+ function noop () {}
25226
+
25227
+ const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
25228
+ let streamRegistry
25229
+
25230
+ if (hasFinalizationRegistry) {
25231
+ streamRegistry = new FinalizationRegistry((weakRef) => {
25232
+ const stream = weakRef.deref()
25233
+ if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
25234
+ stream.cancel('Response object has been garbage collected').catch(noop)
25235
+ }
25236
+ })
25237
+ }
25206
25238
25207
25239
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
25208
25240
function extractBody (object, keepalive = false) {
@@ -25445,14 +25477,18 @@ function safelyExtractBody (object, keepalive = false) {
25445
25477
return extractBody(object, keepalive)
25446
25478
}
25447
25479
25448
- function cloneBody (body) {
25480
+ function cloneBody (instance, body) {
25449
25481
// To clone a body body, run these steps:
25450
25482
25451
25483
// https://fetch.spec.whatwg.org/#concept-body-clone
25452
25484
25453
25485
// 1. Let « out1, out2 » be the result of teeing body’s stream.
25454
25486
const [out1, out2] = body.stream.tee()
25455
25487
25488
+ if (hasFinalizationRegistry) {
25489
+ streamRegistry.register(instance, new WeakRef(out1))
25490
+ }
25491
+
25456
25492
// 2. Set body’s stream to out1.
25457
25493
body.stream = out1
25458
25494
@@ -25595,7 +25631,7 @@ async function consumeBody (object, convertBytesToJSValue, instance) {
25595
25631
25596
25632
// 1. If object is unusable, then return a promise rejected
25597
25633
// with a TypeError.
25598
- if (bodyUnusable(object[kState].body )) {
25634
+ if (bodyUnusable(object)) {
25599
25635
throw new TypeError('Body is unusable: Body has already been read')
25600
25636
}
25601
25637
@@ -25635,7 +25671,9 @@ async function consumeBody (object, convertBytesToJSValue, instance) {
25635
25671
}
25636
25672
25637
25673
// https://fetch.spec.whatwg.org/#body-unusable
25638
- function bodyUnusable (body) {
25674
+ function bodyUnusable (object) {
25675
+ const body = object[kState].body
25676
+
25639
25677
// An object including the Body interface mixin is
25640
25678
// said to be unusable if its body is non-null and
25641
25679
// its body’s stream is disturbed or locked.
@@ -25677,7 +25715,10 @@ module.exports = {
25677
25715
extractBody,
25678
25716
safelyExtractBody,
25679
25717
cloneBody,
25680
- mixinBody
25718
+ mixinBody,
25719
+ streamRegistry,
25720
+ hasFinalizationRegistry,
25721
+ bodyUnusable
25681
25722
}
25682
25723
25683
25724
@@ -30487,7 +30528,7 @@ module.exports = {
30487
30528
30488
30529
30489
30530
30490
- const { extractBody, mixinBody, cloneBody } = __nccwpck_require__(6682)
30531
+ const { extractBody, mixinBody, cloneBody, bodyUnusable } = __nccwpck_require__(6682)
30491
30532
const { Headers, fill: fillHeaders, HeadersList, setHeadersGuard, getHeadersGuard, setHeadersList, getHeadersList } = __nccwpck_require__(2991)
30492
30533
const { FinalizationRegistry } = __nccwpck_require__(1922)()
30493
30534
const util = __nccwpck_require__(3983)
@@ -31042,7 +31083,7 @@ class Request {
31042
31083
// 40. If initBody is null and inputBody is non-null, then:
31043
31084
if (initBody == null && inputBody != null) {
31044
31085
// 1. If input is unusable, then throw a TypeError.
31045
- if (util.isDisturbed(inputBody.stream) || inputBody.stream.locked ) {
31086
+ if (bodyUnusable(input) ) {
31046
31087
throw new TypeError(
31047
31088
'Cannot construct a Request with a Request object that has already been used.'
31048
31089
)
@@ -31244,7 +31285,7 @@ class Request {
31244
31285
webidl.brandCheck(this, Request)
31245
31286
31246
31287
// 1. If this is unusable, then throw a TypeError.
31247
- if (this.bodyUsed || this.body?.locked ) {
31288
+ if (bodyUnusable( this) ) {
31248
31289
throw new TypeError('unusable')
31249
31290
}
31250
31291
@@ -31362,7 +31403,7 @@ function cloneRequest (request) {
31362
31403
// 2. If request’s body is non-null, set newRequest’s body to the
31363
31404
// result of cloning request’s body.
31364
31405
if (request.body != null) {
31365
- newRequest.body = cloneBody(request.body)
31406
+ newRequest.body = cloneBody(newRequest, request.body)
31366
31407
}
31367
31408
31368
31409
// 3. Return newRequest.
@@ -31530,7 +31571,7 @@ module.exports = { Request, makeRequest, fromInnerRequest, cloneRequest }
31530
31571
31531
31572
31532
31573
const { Headers, HeadersList, fill, getHeadersGuard, setHeadersGuard, setHeadersList } = __nccwpck_require__(2991)
31533
- const { extractBody, cloneBody, mixinBody } = __nccwpck_require__(6682)
31574
+ const { extractBody, cloneBody, mixinBody, hasFinalizationRegistry, streamRegistry, bodyUnusable } = __nccwpck_require__(6682)
31534
31575
const util = __nccwpck_require__(3983)
31535
31576
const nodeUtil = __nccwpck_require__(7261)
31536
31577
const { kEnumerableProperty } = util
@@ -31555,24 +31596,9 @@ const { URLSerializer } = __nccwpck_require__(7704)
31555
31596
const { kConstruct } = __nccwpck_require__(2785)
31556
31597
const assert = __nccwpck_require__(8061)
31557
31598
const { types } = __nccwpck_require__(7261)
31558
- const { isDisturbed, isErrored } = __nccwpck_require__(4492)
31559
31599
31560
31600
const textEncoder = new TextEncoder('utf-8')
31561
31601
31562
- const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
31563
- let registry
31564
-
31565
- if (hasFinalizationRegistry) {
31566
- registry = new FinalizationRegistry((weakRef) => {
31567
- const stream = weakRef.deref()
31568
- if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
31569
- stream.cancel('Response object has been garbage collected').catch(noop)
31570
- }
31571
- })
31572
- }
31573
-
31574
- function noop () {}
31575
-
31576
31602
// https://fetch.spec.whatwg.org/#response-class
31577
31603
class Response {
31578
31604
// Creates network error Response.
@@ -31773,7 +31799,7 @@ class Response {
31773
31799
webidl.brandCheck(this, Response)
31774
31800
31775
31801
// 1. If this is unusable, then throw a TypeError.
31776
- if (this.bodyUsed || this.body?.locked ) {
31802
+ if (bodyUnusable( this) ) {
31777
31803
throw webidl.errors.exception({
31778
31804
header: 'Response.clone',
31779
31805
message: 'Body has already been consumed.'
@@ -31856,7 +31882,7 @@ function cloneResponse (response) {
31856
31882
// 3. If response’s body is non-null, then set newResponse’s body to the
31857
31883
// result of cloning response’s body.
31858
31884
if (response.body != null) {
31859
- newResponse.body = cloneBody(response.body)
31885
+ newResponse.body = cloneBody(newResponse, response.body)
31860
31886
}
31861
31887
31862
31888
// 4. Return newResponse.
@@ -32061,7 +32087,7 @@ function fromInnerResponse (innerResponse, guard) {
32061
32087
// a primitive or an object, even undefined. If the held value is an object, the registry keeps
32062
32088
// a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
32063
32089
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
32064
- registry .register(response, new WeakRef(innerResponse.body.stream))
32090
+ streamRegistry .register(response, new WeakRef(innerResponse.body.stream))
32065
32091
}
32066
32092
32067
32093
return response
0 commit comments