Skip to content

fix(ext/web): throw DataCloneError when posting non-serializable values#35604

Merged
bartlomieju merged 1 commit into
denoland:mainfrom
bartlomieju:fix/url-postmessage-dataclone
Jul 1, 2026
Merged

fix(ext/web): throw DataCloneError when posting non-serializable values#35604
bartlomieju merged 1 commit into
denoland:mainfrom
bartlomieju:fix/url-postmessage-dataclone

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Per the WHATWG/HTML spec, types like URL and URLSearchParams are not
[Serializable], so sending them through postMessage() must throw a
DataCloneError, which is what browsers and Node both do. #35423 already
made structuredClone() reject them, but postMessage() still silently
serialized them to an empty object, both through a web MessageChannel
(including the node:worker_threads MessageChannel) and through
Worker.postMessage().

The non-serializable marker that #35423 added on the prototypes was only
consulted inside structuredClone(). The postMessage paths gate on a
separate per-instance "uncloneable" check, so they never saw it. This folds
the prototype marker into that shared check so the MessagePort fast path,
serializeJsMessageData(), and structuredClone() all reject these types
consistently, and additionally guards the node Worker.postMessage() fast
path, which previously serialized directly with no check at all.

Fixes #35401

denoland#35423 marked URL/URLSearchParams non-serializable via markNotSerializable,
but that prototype marker was only consulted in structuredClone(). The
postMessage paths check isUncloneable(), which only knew about the per-instance
markAsUncloneable marker -- so posting a URL through a MessageChannel (incl.
node:worker_threads), or through Worker.postMessage, silently serialized to {}
instead of throwing, per denoland#35401.

Fold the kNotSerializable check into isUncloneable() so the web MessagePort
fast path, serializeJsMessageData(), and structuredClone() all reject
non-serializable platform types consistently, and drop the now-redundant inline
check in structuredClone(). Also guard the node Worker.postMessage fast path,
which serialized directly via core.serialize() with no check at all.
@bartlomieju bartlomieju changed the title fix(ext): throw DataCloneError when posting non-serializable values fix(ext/web): throw DataCloneError when posting non-serializable values Jul 1, 2026
@bartlomieju
bartlomieju merged commit 89ab853 into denoland:main Jul 1, 2026
269 of 271 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deno does not throw DataCloneError when using MessageChannel from node:worker_threads

1 participant