1
1
#include " node_worker.h"
2
+ #include " async_wrap-inl.h"
2
3
#include " base_object.h"
3
4
#include " debug_utils-inl.h"
4
5
#include " histogram-inl.h"
5
6
#include " memory_tracker-inl.h"
6
7
#include " node.h"
8
+ #include " node_buffer.h"
7
9
#include " node_errors.h"
8
10
#include " node_external_reference.h"
9
- #include " node_buffer.h"
10
11
#include " node_options-inl.h"
11
12
#include " node_perf.h"
12
13
#include " node_snapshot_builder.h"
13
14
#include " util-inl.h"
14
- #include " async_wrap-inl.h"
15
15
#include " v8-local-handle.h"
16
16
#include " v8-microtask-queue.h"
17
17
#include " v8-snapshot.h"
@@ -884,11 +884,8 @@ class SynchronousWorker final : public MemoryRetainer {
884
884
static bool HasInstance (Environment* env, v8::Local<v8::Value> value);
885
885
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate (
886
886
Environment* env);
887
- static void Initialize (
888
- Environment* env,
889
- v8::Local<v8::Object> target);
890
- static void RegisterExternalReferences (
891
- ExternalReferenceRegistry* registry);
887
+ static void Initialize (Environment* env, v8::Local<v8::Object> target);
888
+ static void RegisterExternalReferences (ExternalReferenceRegistry* registry);
892
889
893
890
SynchronousWorker (Environment* env, v8::Local<v8::Object> obj);
894
891
@@ -974,15 +971,13 @@ Local<FunctionTemplate> SynchronousWorker::GetConstructorTemplate(
974
971
return tmpl;
975
972
}
976
973
977
- void SynchronousWorker::Initialize (
978
- Environment* env,
979
- v8::Local<v8::Object> target) {
980
- SetConstructorFunction (
981
- env->context (),
982
- target,
983
- " SynchronousWorker" ,
984
- GetConstructorTemplate (env),
985
- SetConstructorFunctionFlag::NONE);
974
+ void SynchronousWorker::Initialize (Environment* env,
975
+ v8::Local<v8::Object> target) {
976
+ SetConstructorFunction (env->context (),
977
+ target,
978
+ " SynchronousWorker" ,
979
+ GetConstructorTemplate (env),
980
+ SetConstructorFunctionFlag::NONE);
986
981
987
982
NODE_DEFINE_CONSTANT (target, UV_RUN_DEFAULT);
988
983
NODE_DEFINE_CONSTANT (target, UV_RUN_ONCE);
@@ -1048,9 +1043,8 @@ void SynchronousWorker::New(const FunctionCallbackInfo<Value>& args) {
1048
1043
void SynchronousWorker::Start (const FunctionCallbackInfo<Value>& args) {
1049
1044
SynchronousWorker* self = Unwrap (args);
1050
1045
if (self == nullptr ) return ;
1051
- self->Start (
1052
- args[0 ]->BooleanValue (args.GetIsolate ()),
1053
- args[1 ]->BooleanValue (args.GetIsolate ()));
1046
+ self->Start (args[0 ]->BooleanValue (args.GetIsolate ()),
1047
+ args[1 ]->BooleanValue (args.GetIsolate ()));
1054
1048
}
1055
1049
1056
1050
void SynchronousWorker::Stop (const FunctionCallbackInfo<Value>& args) {
@@ -1118,7 +1112,7 @@ MaybeLocal<Value> SynchronousWorker::RunInCallbackScope(Local<Function> fn) {
1118
1112
}
1119
1113
SynchronousWorkerScope worker_scope (this );
1120
1114
v8::Isolate* isolate = isolate_;
1121
- CallbackScope callback_scope (isolate, wrap_.Get (isolate_), { 1 , 0 });
1115
+ CallbackScope callback_scope (isolate, wrap_.Get (isolate_), {1 , 0 });
1122
1116
MaybeLocal<Value> ret = fn->Call (context (), Null (isolate), 0 , nullptr );
1123
1117
if (signaled_stop_) {
1124
1118
isolate->CancelTerminateExecution ();
@@ -1145,10 +1139,10 @@ void SynchronousWorker::Start(bool own_loop, bool own_microtaskqueue) {
1145
1139
}
1146
1140
1147
1141
MicrotaskQueue* microtask_queue =
1148
- own_microtaskqueue ?
1149
- (microtask_queue_ = v8::MicrotaskQueue::New (
1150
- isolate_, v8::MicrotasksPolicy:: kExplicit )) .get () :
1151
- outer_context_.Get (isolate_)->GetMicrotaskQueue ();
1142
+ own_microtaskqueue ? (microtask_queue_ = v8::MicrotaskQueue::New (
1143
+ isolate_, v8::MicrotasksPolicy:: kExplicit ))
1144
+ .get ()
1145
+ : outer_context_.Get (isolate_)->GetMicrotaskQueue ();
1152
1146
uv_loop_t * loop = own_loop ? &loop_ : GetCurrentEventLoop (isolate_);
1153
1147
1154
1148
Local<Context> context = Context::New (
@@ -1174,20 +1168,18 @@ void SynchronousWorker::Start(bool own_loop, bool own_microtaskqueue) {
1174
1168
ThreadId thread_id = AllocateEnvironmentThreadId ();
1175
1169
auto inspector_parent_handle = GetInspectorParentHandle (
1176
1170
outer_env, thread_id, " file:///synchronous-worker.js" );
1177
- env_ = CreateEnvironment (
1178
- isolate_data_,
1179
- context,
1180
- {},
1181
- {},
1182
- static_cast <EnvironmentFlags::Flags>(
1183
- EnvironmentFlags::kTrackUnmanagedFds |
1184
- EnvironmentFlags::kNoRegisterESMLoader ),
1185
- thread_id,
1186
- std::move (inspector_parent_handle));
1171
+ env_ = CreateEnvironment (isolate_data_,
1172
+ context,
1173
+ {},
1174
+ {},
1175
+ static_cast <EnvironmentFlags::Flags>(
1176
+ EnvironmentFlags::kTrackUnmanagedFds |
1177
+ EnvironmentFlags::kNoRegisterESMLoader ),
1178
+ thread_id,
1179
+ std::move (inspector_parent_handle));
1187
1180
assert (env_ != nullptr );
1188
- SetProcessExitHandler (env_, [this ](Environment* env, int code) {
1189
- OnExit (code);
1190
- });
1181
+ SetProcessExitHandler (env_,
1182
+ [this ](Environment* env, int code) { OnExit (code); });
1191
1183
}
1192
1184
1193
1185
void SynchronousWorker::OnExit (int code) {
@@ -1198,10 +1190,11 @@ void SynchronousWorker::OnExit(int code) {
1198
1190
Isolate::SafeForTerminationScope termination_scope (isolate_);
1199
1191
Local<Value> onexit_v;
1200
1192
if (!self->Get (outer_context, String::NewFromUtf8Literal (isolate_, " onexit" ))
1201
- .ToLocal (&onexit_v) || !onexit_v->IsFunction ()) {
1193
+ .ToLocal (&onexit_v) ||
1194
+ !onexit_v->IsFunction ()) {
1202
1195
return ;
1203
1196
}
1204
- Local<Value> args[] = { Integer::New (isolate_, code) };
1197
+ Local<Value> args[] = {Integer::New (isolate_, code)};
1205
1198
USE (onexit_v.As <Function>()->Call (outer_context, self, 1 , args));
1206
1199
SignalStop ();
1207
1200
}
@@ -1266,10 +1259,7 @@ MaybeLocal<Value> SynchronousWorker::Load(Local<Function> callback) {
1266
1259
return worker_scope.EscapeMaybe (
1267
1260
LoadEnvironment (env_, [&](const StartExecutionCallbackInfo& info) {
1268
1261
Local<Value> argv[] = {
1269
- info.process_object ,
1270
- info.native_require ,
1271
- context ()->Global ()
1272
- };
1262
+ info.process_object , info.native_require , context ()->Global ()};
1273
1263
return callback->Call (context (), Null (isolate_), 3 , argv);
1274
1264
}));
1275
1265
}
0 commit comments