fix(ext/web): allow transferring non-serializable types in structuredClone - #33491
Merged
Merged
Conversation
…Clone The kNotSerializable check added in #33465 was too broad -- it threw DataCloneError even when the value was being transferred, not cloned. Skip the check when the value is in the transfer list.
bartlomieju
enabled auto-merge (squash)
April 25, 2026 18:15
bartlomieju
disabled auto-merge
April 25, 2026 18:15
bartlomieju
enabled auto-merge (squash)
April 25, 2026 18:15
The "A subclass instance will be received as its closest transferable superclass" test now passes for both window and worker contexts.
This reverts commit 2940f74.
fibibot
approved these changes
Apr 25, 2026
fibibot
left a comment
Contributor
There was a problem hiding this comment.
LGTM. This is the right fix for the regression I flagged on #33482 — the unconditional kNotSerializable check at ext/web/13_message_port.js:561 was firing for structuredClone(stream, { transfer: [stream] }) even though the stream was being transferred, not cloned. Adding && !ArrayPrototypeIncludes(options.transfer, value) skips the check exactly when the user asked for transfer.
Verified:
ArrayPrototypeIncludesis already imported on line 18, so no new primordial needed.- The check runs after
webidl.converters.StructuredSerializeOptions(options, ...), sooptions.transferis guaranteed to be an array (defaults to[]), and a non-transferable object that gets passed in will still fail downstream at V8's serializer withDataCloneError— same observable behavior, just a different throw site. - The two
html.jsonexpectations dropped ("A subclass instance will be received as its closest transferable superclass"at lines 994 + 1023) confirm this WPT subcase now passes. - Cloning without transfer still throws, since
value[kNotSerializable]still gates the path when the transfer list doesn't containvalue.
This was referenced Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a regression from #33465 where
structuredClone(value, { transfer: [value] })threwDataCloneErrorforReadableStream,WritableStream, andTransformStream. ThekNotSerializablecheck was firing even when the value was being transferred, not cloned.The fix skips the check when the value is present in the transfer list.
Test plan
./x test-compat test-webstream-structured-clone-no-leftovers-- now passes./x test-spec structured_clone_non_serializable-- still passes (cloning without transfer still throws)