@@ -1079,6 +1079,14 @@ static MaybeLocal<Value> ExecuteBootstrapper(
10791079}
10801080
10811081void LoadEnvironment (Environment* env) {
1082+ RunBootstrapping (env);
1083+ StartExecution (env);
1084+ }
1085+
1086+ void RunBootstrapping (Environment* env) {
1087+ CHECK (!env->has_run_bootstrapping_code ());
1088+ env->set_has_run_bootstrapping_code (true );
1089+
10821090 HandleScope handle_scope (env->isolate ());
10831091 Isolate* isolate = env->isolate ();
10841092 Local<Context> context = env->context ();
@@ -1140,11 +1148,29 @@ void LoadEnvironment(Environment* env) {
11401148 loader_exports.ToLocalChecked (),
11411149 Boolean::New (isolate, env->is_main_thread ())};
11421150
1143- if (ExecuteBootstrapper (
1151+ Local<Value> start_execution;
1152+ if (!ExecuteBootstrapper (
11441153 env, " internal/bootstrap/node" , &node_params, &node_args)
1145- .IsEmpty ( )) {
1154+ .ToLocal (&start_execution )) {
11461155 return ;
11471156 }
1157+
1158+ if (start_execution->IsFunction ())
1159+ env->set_start_execution_function (start_execution.As <Function>());
1160+ }
1161+
1162+ void StartExecution (Environment* env) {
1163+ HandleScope handle_scope (env->isolate ());
1164+ // We have to use Local<>::New because of the optimized way in which we access
1165+ // the object in the env->...() getters, which does not play well with
1166+ // resetting the handle while we're accessing the object through the Local<>.
1167+ Local<Function> start_execution =
1168+ Local<Function>::New (env->isolate (), env->start_execution_function ());
1169+ env->set_start_execution_function (Local<Function>());
1170+
1171+ if (start_execution.IsEmpty ()) return ;
1172+ USE (start_execution->Call (
1173+ env->context (), Undefined (env->isolate ()), 0 , nullptr ));
11481174}
11491175
11501176static void StartInspector (Environment* env, const char * path) {
0 commit comments