Skip to content

Commit 637107f

Browse files
committed
worker: fix worker name with \0
1 parent 049664b commit 637107f

File tree

8 files changed

+33
-15
lines changed

8 files changed

+33
-15
lines changed

src/api/environment.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,19 @@ 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-
CHECK_NOT_NULL(env);
515+
if (url == nullptr) url = "";
516516
if (name == nullptr) name = "";
517+
std::string_view url_view(url);
518+
std::string_view name_view(name);
519+
return GetInspectorParentHandle(env, thread_id, url_view, name_view);
520+
}
521+
522+
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
523+
Environment* env,
524+
ThreadId thread_id,
525+
std::string_view url,
526+
std::string_view name) {
527+
CHECK_NOT_NULL(env);
517528
CHECK_NE(thread_id.id, static_cast<uint64_t>(-1));
518529
if (!env->should_create_inspector()) {
519530
return nullptr;

src/inspector/worker_inspector.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class WorkerFinishedRequest : public Request {
5757

5858
ParentInspectorHandle::ParentInspectorHandle(
5959
uint64_t id,
60-
const std::string& url,
60+
std::string_view url,
6161
std::shared_ptr<MainThreadHandle> parent_thread,
6262
bool wait_for_connect,
63-
const std::string& name,
63+
std::string_view name,
6464
std::shared_ptr<NetworkResourceManager> network_resource_manager)
6565
: id_(id),
6666
url_(url),
@@ -104,8 +104,8 @@ void WorkerManager::WorkerStarted(uint64_t session_id,
104104

105105
std::unique_ptr<ParentInspectorHandle> WorkerManager::NewParentHandle(
106106
uint64_t thread_id,
107-
const std::string& url,
108-
const std::string& name,
107+
std::string_view url,
108+
std::string_view name,
109109
std::shared_ptr<NetworkResourceManager> network_resource_manager) {
110110
bool wait = !delegates_waiting_on_start_.empty();
111111
return std::make_unique<ParentInspectorHandle>(

src/inspector/worker_inspector.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ class ParentInspectorHandle {
5757
public:
5858
ParentInspectorHandle(
5959
uint64_t id,
60-
const std::string& url,
60+
std::string_view url,
6161
std::shared_ptr<MainThreadHandle> parent_thread,
6262
bool wait_for_connect,
63-
const std::string& name,
63+
std::string_view name,
6464
std::shared_ptr<NetworkResourceManager> network_resource_manager);
6565
~ParentInspectorHandle();
6666
std::unique_ptr<ParentInspectorHandle> NewParentInspectorHandle(
67-
uint64_t thread_id, const std::string& url, const std::string& name) {
67+
uint64_t thread_id, std::string_view url, std::string_view name) {
6868
return std::make_unique<ParentInspectorHandle>(
6969
thread_id, url, parent_thread_, wait_, name, network_resource_manager_);
7070
}
@@ -97,8 +97,8 @@ class WorkerManager : public std::enable_shared_from_this<WorkerManager> {
9797

9898
std::unique_ptr<ParentInspectorHandle> NewParentHandle(
9999
uint64_t thread_id,
100-
const std::string& url,
101-
const std::string& name,
100+
std::string_view url,
101+
std::string_view name,
102102
std::shared_ptr<NetworkResourceManager> network_resource_manager);
103103
void WorkerStarted(uint64_t session_id, const WorkerInfo& info, bool waiting);
104104
void WorkerFinished(uint64_t session_id);

src/inspector_agent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ void Agent::SetParentHandle(
11541154
}
11551155

11561156
std::unique_ptr<ParentInspectorHandle> Agent::GetParentHandle(
1157-
uint64_t thread_id, const std::string& url, const std::string& name) {
1157+
uint64_t thread_id, std::string_view url, std::string_view name) {
11581158
THROW_IF_INSUFFICIENT_PERMISSIONS(parent_env_,
11591159
permission::PermissionScope::kInspector,
11601160
"GetParentHandle",

src/inspector_agent.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ class Agent {
9494
void DisableAsyncHook();
9595

9696
void SetParentHandle(std::unique_ptr<ParentInspectorHandle> parent_handle);
97-
std::unique_ptr<ParentInspectorHandle> GetParentHandle(
98-
uint64_t thread_id, const std::string& url, const std::string& name);
97+
std::unique_ptr<ParentInspectorHandle> GetParentHandle(uint64_t thread_id,
98+
std::string_view url,
99+
std::string_view name);
99100

100101
// Called to create inspector sessions that can be used from the same thread.
101102
// The inspector responds by using the delegate to send messages back.

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+
std::string_view child_url,
710+
std::string_view 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, 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)