Skip to content

fix(ext/node): fix IPC message prototype for child_process JSON#32731

Merged
fraidev merged 2 commits intodenoland:mainfrom
fraidev:fix/child-process-ipc-message-prototype
Mar 16, 2026
Merged

fix(ext/node): fix IPC message prototype for child_process JSON#32731
fraidev merged 2 commits intodenoland:mainfrom
fraidev:fix/child-process-ipc-message-prototype

Conversation

@fraidev
Copy link
Copy Markdown
Contributor

@fraidev fraidev commented Mar 14, 2026

Deno's serde_v8 layer deserializes JSON objects with null prototype (Object.create(null)), but Node.js IPC messages should have Object.prototype (as if from JSON.parse). This caused assert.deepStrictEqual to fail when comparing IPC messages.

For the JSON serialization mode, re-parse the message through JSON.parse(JSON.stringify(msg)) to restore normal prototypes.

…lization

Deno's serde_v8 layer deserializes JSON objects with null prototype
(Object.create(null)), but Node.js IPC messages should have
Object.prototype (as if from JSON.parse). This caused
assert.deepStrictEqual to fail when comparing IPC messages.

For the JSON serialization mode, re-parse the message through
JSON.parse(JSON.stringify(msg)) to restore normal prototypes.
@fraidev fraidev changed the title fix(ext/node): fix IPC message prototype for child_process JSON seria… fix(ext/node): fix IPC message prototype for child_process JSON Mar 14, 2026
// serde_v8 deserializes objects with null prototype, but Node.js IPC
// messages should have Object.prototype (as if from JSON.parse).
if (serialization === "json" && msg !== null && typeof msg === "object") {
msg = JSON.parse(JSON.stringify(msg));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gonna be horrible for performance. Can you think of some other solution?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is bad. I created a restorePrototype function to do it via walk the tree.

@fraidev fraidev requested a review from bartlomieju March 16, 2026 14:38
@fraidev fraidev merged commit 262cb59 into denoland:main Mar 16, 2026
220 of 222 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.

2 participants