Skip to content

NodeWorker.sendMessageToWorker fails with multi-byte code points in JSON #50516

Closed
@connor4312

Description

@connor4312

Version

21.1.0

Platform

Darwin mbp.peet.io 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64 x86_64

Subsystem

inspector

What steps will reproduce the bug?

From a user's point of view...

  1. Debug a script like this in VS Code
const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
  new Worker(__filename);
} else {
  debugger;
}
  1. Ensure the worker_thread session is select and run console.log('本機磁碟')
  2. Nothing happens (an error behind the scenes)

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

It should log 本機磁碟

What do you see instead?

An error

Additional information

Behind the scenes, this calls

{
  "id": 1027,
  "method": "NodeWorker.sendMessageToWorker",
  "params": {
    "message": "{\"id\":1014,\"method\":\"Debugger.evaluateOnCallFrame\",\"params\":{\"expression\":\"console.log('本機磁碟')\\n//# sourceURL=eval-1e14c9c5.repl\\n\",\"includeCommandLineAPI\":true,\"objectGroup\":\"console\",\"generatePreview\":true,\"callFrameId\":\"-7882104772351236078.1.0\"}}",
    "sessionId": "1"
  }
}

This is created by simply JSON.stringify'ing the relevant CDP call.

However, this results in

{
  "method": "NodeWorker.receivedMessageFromWorker",
  "params": {
    "sessionId": "1",
    "message": "{\"error\":{\"code\":-32700,\"message\":\"Message must be a valid JSON\"}}"
  }
}

Which seems to come from here

reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
. I would expect any JSON created by JSON.stringify would be able to be parsed by the NodeWorker domain.

This causes more 'real' issues when users have paths with multi-byte codepoints, as reported in microsoft/vscode-js-debug#1798 and microsoft/vscode-js-debug#2043

Metadata

Metadata

Assignees

No one assigned

    Labels

    inspectorIssues and PRs related to the V8 inspector protocolworkerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions