Repository navigation
stucturedClone defective for DataCloneError #49181
Description
Activity
I can take it
Hello!
I've looked at @inctnce to check if he was taking care of this issue, but apparently he is not, so I have been trying to solve this by myself.
I haven't solved it yet, but I've discovered things that can be useful to find a solution...
Before any explanations, I would like to say that I am new here and I don't know much about V8 and node internals yet, but I did my best to understand what was possible until now.
So, here we go:
To say the truth, this problem does not happen with DataCloneError only, but with any type of error that is also a "DomException" (based on my tests). With that said, we can also see that a DomException object is a little different from a standard Error object. I think it's due this object being "different" that makes the function to not work as excepted.
Where the problem probably is
When using the structuredClone function directly on browser (like Chrome, that uses V8) we get a different result from Node, and that is because Node has implemented its own custom function (can be found in
src/node_messaging.cc).The node structuredClone function uses a custom serializer to serialize an object (can be found on line 295 of
src/node_messaging.ccfile). The custom serializer includes a function called IsHostObject that apparently indicates if the structuredClone first argument is a BaseObject or a JSTransferable, and apparently our DomException is neither of them, returning nothing.So, searching for the method WriteJSReceiver on
deps/v8/objects/value-serializer.cc, we can see that when the function IsHostObject does not have a result, we fall on a case (and I am not sure if I am correctly here) where an empty result is also returned and apparently that is why we ends with an empty object on JS.But look, just changing the IsHostObject function to return true for our Dom Exception does not solve the problem. I think that would be necessary to change the function WriteHostObject too, but my knowledge was limited here.
Final considerations
Like I said, I am new here on NodeJS community, and I have little knowledge of how V8 and Node uses C++ code to allow we to run JS. So, if I said something that does not make sense, I would be grateful to be warned about :)
- addedweb-standardsIssues and PRs related to web-platform APIs and standards compliance.Issues and PRs related to web-platform APIs and standards compliance.
on Jun 4, 2024 - added a commit that references this issue
on Jun 11, 2025 - added a commit that references this issue
on Jun 16, 2025 - added 3 commits that reference this issue
on Jul 21, 2025
Version
v19.9.0
Platform
Linux WORKSTATION 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Run the following snippet:
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Since
structuredCloneis supposed to support errors, the result should not be an empty object. It should be either a copy of the original error, or a copy of the origininal error but withnamechanged toError.What do you see instead?
The cloned
DataCloneErrorcloned as an empty object.Additional information
This error limits sending back useful error information through
MessagePortsThis is the result of running the same snippet in other runtimes.
Deno
Microsoft Edge
Mozilla Firefox