worker: fix worker name with \0 · nodejs/node@c38b7cf

8 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -532,8 +532,19 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(

532532
533533

NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(

534534

Environment* env, ThreadId thread_id, const char* url, const char* name) {

535-

CHECK_NOT_NULL(env);

535+

if (url == nullptr) url = "";

536536

if (name == nullptr) name = "";

537+

std::string_view url_view(url);

538+

std::string_view name_view(name);

539+

return GetInspectorParentHandle(env, thread_id, url_view, name_view);

540+

}

541+
542+

NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(

543+

Environment* env,

544+

ThreadId thread_id,

545+

std::string_view url,

546+

std::string_view name) {

547+

CHECK_NOT_NULL(env);

537548

CHECK_NE(thread_id.id, static_cast<uint64_t>(-1));

538549

if (!env->should_create_inspector()) {

539550

return nullptr;

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>(

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

Original file line numberDiff line numberDiff line change

@@ -1155,7 +1155,7 @@ void Agent::SetParentHandle(

11551155

}

11561156
11571157

std::unique_ptr<ParentInspectorHandle> Agent::GetParentHandle(

1158-

uint64_t thread_id, const std::string& url, const std::string& name) {

1158+

uint64_t thread_id, std::string_view url, std::string_view name) {

11591159

THROW_IF_INSUFFICIENT_PERMISSIONS(parent_env_,

11601160

permission::PermissionScope::kInspector,

11611161

"GetParentHandle",

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.

Original file line numberDiff line numberDiff line change

@@ -758,6 +758,12 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(

758758

const char* child_url,

759759

const char* name);

760760
761+

NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(

762+

Environment* parent_env,

763+

ThreadId child_thread_id,

764+

std::string_view child_url,

765+

std::string_view name);

766+
761767

struct StartExecutionCallbackInfo {

762768

v8::Local<v8::Object> process_object;

763769

v8::Local<v8::Function> native_require;

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]};

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,