lib,src: preserve domexception in v8 serialize/deserialize#61856
lib,src: preserve domexception in v8 serialize/deserialize#61856efekrskl wants to merge 3 commits intonodejs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61856 +/- ##
=======================================
Coverage 89.72% 89.72%
=======================================
Files 675 675
Lines 204806 204849 +43
Branches 39355 39363 +8
=======================================
+ Hits 183761 183807 +46
- Misses 13330 13331 +1
+ Partials 7715 7711 -4
🚀 New features to boost your workflow:
|
addaleax
left a comment
There was a problem hiding this comment.
No particularly strong feelings, but I'll point out that the ability to (de)serialize custom objects is part of why Serializer and Deserializer are exposed as abstract classes
| */ | ||
| _writeHostObject(abView) { | ||
| // Route DOMException through the same hooks used by structuredClone | ||
| if (abView instanceof DOMException) { |
There was a problem hiding this comment.
DOMException is a per-context concept in Node.js, so I don't think instanceof is a reliable brand check (as usual in JS)
There was a problem hiding this comment.
Would it make sense to check the symbols instead?
Something like:
const cloneSymbol = abView?.[messaging_clone_symbol];
if (typeof cloneSymbol === 'function') {
// ...call
}There was a problem hiding this comment.
Yeah, something like that would probably be a better brand check.
I'm not sure how well messaging_clone_symbol works, it's going to cover other cases than just DOMException – and that's not necessarily a bad thing, but potentially quite a bit more effort to implement properly – especially when structuredClone is already dealing with it just fine
Thanks for the input! I mostly just opened this to see what folks think and if this would make sense to support by default. If custom serializers make more sense, that's fine. I'm not strongly attached to it |
Closes #53225
Not sure whether
v8.serialize()/deserialize()should preserve DOMException, but I took a shot since structuredClone() already does. This should treat DOMExceptions as a host object and use a escape hatch for serializing them on our end.