@@ -1085,6 +1085,14 @@ static MaybeLocal<Value> ExecuteBootstrapper(
10851085}
10861086
10871087void LoadEnvironment (Environment* env) {
1088+ RunBootstrapping (env);
1089+ StartExecution (env);
1090+ }
1091+
1092+ void RunBootstrapping (Environment* env) {
1093+ CHECK (!env->has_run_bootstrapping_code ());
1094+ env->set_has_run_bootstrapping_code (true );
1095+
10881096 HandleScope handle_scope (env->isolate ());
10891097 Isolate* isolate = env->isolate ();
10901098 Local<Context> context = env->context ();
@@ -1146,11 +1154,29 @@ void LoadEnvironment(Environment* env) {
11461154 loader_exports.ToLocalChecked (),
11471155 Boolean::New (isolate, env->is_main_thread ())};
11481156
1149- if (ExecuteBootstrapper (
1157+ Local<Value> start_execution;
1158+ if (!ExecuteBootstrapper (
11501159 env, " internal/bootstrap/node" , &node_params, &node_args)
1151- .IsEmpty ( )) {
1160+ .ToLocal (&start_execution )) {
11521161 return ;
11531162 }
1163+
1164+ if (start_execution->IsFunction ())
1165+ env->set_start_execution_function (start_execution.As <Function>());
1166+ }
1167+
1168+ void StartExecution (Environment* env) {
1169+ HandleScope handle_scope (env->isolate ());
1170+ // We have to use Local<>::New because of the optimized way in which we access
1171+ // the object in the env->...() getters, which does not play well with
1172+ // resetting the handle while we're accessing the object through the Local<>.
1173+ Local<Function> start_execution =
1174+ Local<Function>::New (env->isolate (), env->start_execution_function ());
1175+ env->set_start_execution_function (Local<Function>());
1176+
1177+ if (start_execution.IsEmpty ()) return ;
1178+ USE (start_execution->Call (
1179+ env->context (), Undefined (env->isolate ()), 0 , nullptr ));
11541180}
11551181
11561182static void StartInspector (Environment* env, const char * path) {
0 commit comments