diff --git a/lib/internal/webstreams/transformstream.js b/lib/internal/webstreams/transformstream.js index bb1d1aa8396..2943ce3fe09 100644 --- a/lib/internal/webstreams/transformstream.js +++ b/lib/internal/webstreams/transformstream.js @@ -592,11 +592,11 @@ function transformStreamDefaultControllerError(controller, error) { // Mirrors the reference implementation's // `promiseCall(transformAlgorithm, ...).then(undefined, rejectionSteps)`: -// the returned promise settles one microtask after the (coerced) result -// does, and a rejection errors the transform stream before propagating. -// The raw transform callback plus the shared resolved promise for -// non-thenable results replace the previous async wrapper's two implicit -// promises per chunk. +// a rejection errors the transform stream before propagating. A +// non-thenable result cannot reject, so it maps to the shared resolved +// promise without the rejection step; the write then completes one +// microtask earlier than in the reference implementation, with the +// relative order of all stream events unchanged. function transformStreamDefaultControllerPerformTransform(controller, chunk) { const controllerState = controller[kState]; const transformAlgorithm = controllerState.transformAlgorithm; @@ -612,10 +612,9 @@ function transformStreamDefaultControllerPerformTransform(controller, chunk) { } if (result === null || (typeof result !== 'object' && typeof result !== 'function')) { - result = kResolvedPromise; - } else { - result = PromiseResolve(result); + return kResolvedPromise; } + result = PromiseResolve(result); controllerState.performTransformRejected ??= (error) => { transformStreamError(controller[kState].stream, error); throw error;