node_patches/node12.11.1_modified/src/node_main_instance.cc
// TODO(joyeecheung): align this with the CreateEnvironment exposed in node.h
// and the environment creation routine in workers somehow.
align this with the CreateEnvironment exposed in node.h
and the environment creation routine in workers somehow.
align this with the CreateEnvironment exposed in node . h and the environment creation routine in workers somehow .
std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
    int* exit_code) {
  *exit_code = 0;  
  HandleScope handle_scope(isolate_);
  if (isolate_data_->options()->track_heap_objects) {
    isolate_->GetHeapProfiler()->StartTrackingHeapObjects(true);
  }
  Local<Context> context;
  if (deserialize_mode_) {
    context =
        Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked();
    InitializeContextRuntime(context);
    SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
  } else {
    context = NewContext(isolate_);
  }
  CHECK(!context.IsEmpty());
  Context::Scope context_scope(context);
  std::unique_ptr<Environment> env = std::make_unique<Environment>(
      isolate_data_.get(),
      context,
      args_,
      exec_args_,
      static_cast<Environment::Flags>(Environment::kIsMainThread |
                                      Environment::kOwnsProcessState |
                                      Environment::kOwnsInspector));
  env->InitializeLibuv(per_process::v8_is_profiling);
  env->InitializeDiagnostics();
#if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM
  *exit_code = env->InitializeInspector(nullptr);
#endif
  if (*exit_code != 0) {
    return env;
  }
  if (env->RunBootstrapping().IsEmpty()) {
    *exit_code = 1;
  }
  return env;
}
std :: unique_ptr < Environment > NodeMainInstance :: CreateMainEnvironment ( int * exit_code ) { * exit_code = 0 ; HandleScope handle_scope ( isolate_ ) ; if ( isolate_data_ -> options ( ) -> track_heap_objects ) { isolate_ -> GetHeapProfiler ( ) -> StartTrackingHeapObjects ( true ) ; } Local < Context > context ; if ( deserialize_mode_ ) { context = Context :: FromSnapshot ( isolate_ , kNodeContextIndex ) . ToLocalChecked ( ) ; InitializeContextRuntime ( context ) ; SetIsolateUpForNode ( isolate_ , IsolateSettingCategories :: kErrorHandlers ) ; } else { context = NewContext ( isolate_ ) ; } CHECK ( ! context . IsEmpty ( ) ) ; Context :: Scope context_scope ( context ) ; std :: unique_ptr < Environment > env = std :: make_unique < Environment > ( isolate_data_ . get ( ) , context , args_ , exec_args_ , static_cast < Environment :: Flags > ( Environment :: kIsMainThread | Environment :: kOwnsProcessState | Environment :: kOwnsInspector ) ) ; env -> InitializeLibuv ( per_process :: v8_is_profiling ) ; env -> InitializeDiagnostics ( ) ; #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM * exit_code = env -> InitializeInspector ( nullptr ) ; #endif if ( * exit_code != 0 ) { return env ; } if ( env -> RunBootstrapping ( ) . IsEmpty ( ) ) { * exit_code = 1 ; } return env ; }
TODO(joyeecheung): align this with the CreateEnvironment exposed in node.h
and the environment creation routine in workers somehow.
TODO ( joyeecheung ) : align this with the CreateEnvironment exposed in node . h and the environment creation routine in workers somehow .
// Reset the exit code to 0 // TODO(addaleax): This should load a real per-Isolate option, currently // this is still effectively per-process. // TODO(joyeecheung): when we snapshot the bootstrapped context, // the inspector and diagnostics setup should after after deserialization.