@@ -32,6 +32,7 @@ using v8::Isolate;
32
32
using v8::Local;
33
33
using v8::Locker;
34
34
using v8::Maybe;
35
+ using v8::NewStringType;
35
36
using v8::Null;
36
37
using v8::Number;
37
38
using v8::Object;
@@ -88,6 +89,15 @@ Worker::Worker(Environment* env,
88
89
Number::New (env->isolate (), static_cast <double >(thread_id_.id )))
89
90
.Check ();
90
91
92
+ object ()
93
+ ->Set (env->context (),
94
+ env->thread_name_string (),
95
+ String::NewFromUtf8 (env->isolate (),
96
+ name_.data (),
97
+ NewStringType::kNormal ,
98
+ name_.size ())
99
+ .ToLocalChecked ())
100
+ .Check ();
91
101
// Without this check, to use the permission model with
92
102
// workers (--allow-worker) one would need to pass --allow-inspector as well
93
103
if (env->permission ()->is_granted (
@@ -364,7 +374,8 @@ void Worker::Run() {
364
374
std::move (exec_argv_),
365
375
static_cast <EnvironmentFlags::Flags>(environment_flags_),
366
376
thread_id_,
367
- std::move (inspector_parent_handle_)));
377
+ std::move (inspector_parent_handle_),
378
+ name_));
368
379
if (is_stopped ()) return ;
369
380
CHECK_NOT_NULL (env_);
370
381
env_->set_env_vars (std::move (env_vars_));
@@ -1149,6 +1160,16 @@ void CreateWorkerPerContextProperties(Local<Object> target,
1149
1160
Number::New (isolate, static_cast <double >(env->thread_id ())))
1150
1161
.Check ();
1151
1162
1163
+ target
1164
+ ->Set (env->context (),
1165
+ env->thread_name_string (),
1166
+ String::NewFromUtf8 (isolate,
1167
+ env->thread_name ().data (),
1168
+ NewStringType::kNormal ,
1169
+ env->thread_name ().size ())
1170
+ .ToLocalChecked ())
1171
+ .Check ();
1172
+
1152
1173
target
1153
1174
->Set (env->context (),
1154
1175
FIXED_ONE_BYTE_STRING (isolate, " isMainThread" ),
0 commit comments