worker: add name for worker · nodejs/node@eecd327

@@ -33,6 +33,7 @@ using v8::Local;

3333

using v8::Locker;

3434

using v8::Maybe;

3535

using v8::Name;

36+

using v8::NewStringType;

3637

using v8::Null;

3738

using v8::Number;

3839

using v8::Object;

@@ -89,6 +90,15 @@ Worker::Worker(Environment* env,

8990

Number::New(env->isolate(), static_cast<double>(thread_id_.id)))

9091

.Check();

919293+

object()

94+

->Set(env->context(),

95+

env->thread_name_string(),

96+

String::NewFromUtf8(env->isolate(),

97+

name_.data(),

98+

NewStringType::kNormal,

99+

name_.size())

100+

.ToLocalChecked())

101+

.Check();

92102

// Without this check, to use the permission model with

93103

// workers (--allow-worker) one would need to pass --allow-inspector as well

94104

if (env->permission()->is_granted(

@@ -365,7 +375,8 @@ void Worker::Run() {

365375

std::move(exec_argv_),

366376

static_cast<EnvironmentFlags::Flags>(environment_flags_),

367377

thread_id_,

368-

std::move(inspector_parent_handle_)));

378+

std::move(inspector_parent_handle_),

379+

name_));

369380

if (is_stopped()) return;

370381

CHECK_NOT_NULL(env_);

371382

env_->set_env_vars(std::move(env_vars_));

@@ -1239,6 +1250,16 @@ void CreateWorkerPerContextProperties(Local<Object> target,

12391250

Number::New(isolate, static_cast<double>(env->thread_id())))

12401251

.Check();

124112521253+

target

1254+

->Set(env->context(),

1255+

env->thread_name_string(),

1256+

String::NewFromUtf8(isolate,

1257+

env->thread_name().data(),

1258+

NewStringType::kNormal,

1259+

env->thread_name().size())

1260+

.ToLocalChecked())

1261+

.Check();

1262+12421263

target

12431264

->Set(env->context(),

12441265

FIXED_ONE_BYTE_STRING(isolate, "isMainThread"),