Skip to content

Commit c5a93a3

Browse files
theanarkhrichardlau
authored andcommitted
worker: fix worker name with \0
PR-URL: #59214 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent b3c507c commit c5a93a3

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
@@ -523,8 +523,19 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
523523

524524
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
525525
Environment* env, ThreadId thread_id, const char* url, const char* name) {
526-
CHECK_NOT_NULL(env);
526+
if (url == nullptr) url = "";
527527
if (name == nullptr) name = "";
528+
std::string_view url_view(url);
529+
std::string_view name_view(name);
530+
return GetInspectorParentHandle(env, thread_id, url_view, name_view);
531+
}
532+
533+
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
534+
Environment* env,
535+
ThreadId thread_id,
536+
std::string_view url,
537+
std::string_view name) {
538+
CHECK_NOT_NULL(env);
528539
CHECK_NE(thread_id.id, static_cast<uint64_t>(-1));
529540
if (!env->should_create_inspector()) {
530541
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
@@ -744,6 +744,12 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
744744
const char* child_url,
745745
const char* name);
746746

747+
NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
748+
Environment* parent_env,
749+
ThreadId child_thread_id,
750+
std::string_view child_url,
751+
std::string_view name);
752+
747753
struct StartExecutionCallbackInfo {
748754
v8::Local<v8::Object> process_object;
749755
v8::Local<v8::Function> native_require;

src/node_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Worker::Worker(Environment* env,
104104
if (env->permission()->is_granted(
105105
env, node::permission::PermissionScope::kInspector)) {
106106
inspector_parent_handle_ =
107-
GetInspectorParentHandle(env, thread_id_, url.c_str(), name.c_str());
107+
GetInspectorParentHandle(env, thread_id_, url, name);
108108
}
109109

110110
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)