From ba864ad40c29a20a464f75f942160a3213edfbd1 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:19:36 +0100 Subject: [PATCH] build: update distribution (#3154) --- dist/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 161382bc1c..a9377f3730 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31563,8 +31563,9 @@ const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.versi let registry if (hasFinalizationRegistry) { - registry = new FinalizationRegistry((stream) => { - if (!stream.locked && !isDisturbed(stream) && !isErrored(stream)) { + registry = new FinalizationRegistry((weakRef) => { + const stream = weakRef.deref() + if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) { stream.cancel('Response object has been garbage collected').catch(noop) } }) @@ -32055,7 +32056,12 @@ function fromInnerResponse (innerResponse, guard) { setHeadersGuard(response[kHeaders], guard) if (hasFinalizationRegistry && innerResponse.body?.stream) { - registry.register(response, innerResponse.body.stream) + // If the target (response) is reclaimed, the cleanup callback may be called at some point with + // the held value provided for it (innerResponse.body.stream). The held value can be any value: + // a primitive or an object, even undefined. If the held value is an object, the registry keeps + // a strong reference to it (so it can pass it to the cleanup callback later). Reworded from + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry + registry.register(response, new WeakRef(innerResponse.body.stream)) } return response