Skip to content

Commit 51aa926

Browse files
committed
worker: fix worker name with \0
1 parent 049664b commit 51aa926

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/api/environment.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,16 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
512512

513513
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
514514
Environment* env, ThreadId thread_id, const char* url, const char* name) {
515+
std::string name_str(name);
516+
return GetInspectorParentHandle(env, thread_id, url, name_str);
517+
}
518+
519+
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
520+
Environment* env,
521+
ThreadId thread_id,
522+
const char* url,
523+
const std::string& name) {
515524
CHECK_NOT_NULL(env);
516-
if (name == nullptr) name = "";
517525
CHECK_NE(thread_id.id, static_cast<uint64_t>(-1));
518526
if (!env->should_create_inspector()) {
519527
return nullptr;

src/node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
703703
const char* child_url,
704704
const char* name);
705705

706+
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
707+
Environment* parent_env,
708+
ThreadId child_thread_id,
709+
const char* child_url,
710+
const std::string& name);
711+
706712
struct StartExecutionCallbackInfo {
707713
v8::Local<v8::Object> process_object;
708714
v8::Local<v8::Function> native_require;

src/node_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Worker::Worker(Environment* env,
9393
if (env->permission()->is_granted(
9494
env, node::permission::PermissionScope::kInspector)) {
9595
inspector_parent_handle_ =
96-
GetInspectorParentHandle(env, thread_id_, url.c_str(), name.c_str());
96+
GetInspectorParentHandle(env, thread_id_, url.c_str(), name);
9797
}
9898

9999
argv_ = std::vector<std::string>{env->argv()[0]};

test/parallel/test-worker-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (!isMainThread) {
1717
const assert = require('assert');
1818

1919
if (isMainThread) {
20-
const name = 'Hello Thread';
20+
const name = 'Hello\0Thread';
2121
const expectedTitle = `[worker 1] ${name}`;
2222
const worker = new Worker(fixtures.path('worker-name.js'), {
2323
name,

0 commit comments

Comments
 (0)