@@ -330,28 +330,27 @@ std::string GetExecPath(const std::vector<std::string>& argv) {
330330}
331331
332332Environment::Environment (IsolateData* isolate_data,
333- Local<Context> context ,
333+ Isolate* isolate ,
334334 const std::vector<std::string>& args,
335335 const std::vector<std::string>& exec_args,
336336 EnvironmentFlags::Flags flags,
337337 ThreadId thread_id)
338- : isolate_(context-> GetIsolate () ),
338+ : isolate_(isolate ),
339339 isolate_data_(isolate_data),
340- immediate_info_(context-> GetIsolate () ),
341- tick_info_(context-> GetIsolate () ),
340+ immediate_info_(isolate ),
341+ tick_info_(isolate ),
342342 timer_base_(uv_now(isolate_data->event_loop ())),
343343 exec_argv_(exec_args),
344344 argv_(args),
345345 exec_path_(GetExecPath(args)),
346346 should_abort_on_uncaught_toggle_(isolate_, 1 ),
347347 stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields ),
348348 flags_(flags),
349- thread_id_(thread_id.id == static_cast <uint64_t >(-1 ) ?
350- AllocateEnvironmentThreadId().id : thread_id.id),
351- context_(context-> GetIsolate (), context ) {
349+ thread_id_(thread_id.id == static_cast <uint64_t >(-1 )
350+ ? AllocateEnvironmentThreadId().id
351+ : thread_id.id ) {
352352 // We'll be creating new objects so make sure we've entered the context.
353- HandleScope handle_scope (isolate ());
354- Context::Scope context_scope (context);
353+ HandleScope handle_scope (isolate);
355354
356355 // Set some flags if only kDefaultFlags was passed. This can make API version
357356 // transitions easier for embedders.
@@ -362,6 +361,8 @@ Environment::Environment(IsolateData* isolate_data,
362361 }
363362
364363 set_env_vars (per_process::system_environment);
364+ // TODO(joyeecheung): pass Isolate* and env_vars to it instead of the entire
365+ // env
365366 enabled_debug_list_.Parse (this );
366367
367368 // We create new copies of the per-Environment option sets, so that it is
@@ -377,8 +378,6 @@ Environment::Environment(IsolateData* isolate_data,
377378 inspector_agent_ = std::make_unique<inspector::Agent>(this );
378379#endif
379380
380- AssignToContext (context, ContextInfo (" " ));
381-
382381 static uv_once_t init_once = UV_ONCE_INIT;
383382 uv_once (&init_once, InitThreadLocalOnce);
384383 uv_key_set (&thread_local_env, this );
@@ -398,8 +397,7 @@ Environment::Environment(IsolateData* isolate_data,
398397 },
399398 this );
400399
401- performance_state_ =
402- std::make_unique<performance::PerformanceState>(isolate ());
400+ performance_state_ = std::make_unique<performance::PerformanceState>(isolate);
403401 performance_state_->Mark (
404402 performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
405403 performance_state_->Mark (performance::NODE_PERFORMANCE_MILESTONE_NODE_START,
@@ -431,6 +429,29 @@ Environment::Environment(IsolateData* isolate_data,
431429 async_hooks_.no_force_checks ();
432430 }
433431
432+ // This adjusts the return value of base_object_count() so that tests that
433+ // check the count do not have to account for internally created BaseObjects.
434+ initial_base_object_count_ = base_object_count ();
435+ }
436+
437+ Environment::Environment (IsolateData* isolate_data,
438+ Local<Context> context,
439+ const std::vector<std::string>& args,
440+ const std::vector<std::string>& exec_args,
441+ EnvironmentFlags::Flags flags,
442+ ThreadId thread_id)
443+ : Environment(isolate_data,
444+ context->GetIsolate (),
445+ args,
446+ exec_args,
447+ flags,
448+ thread_id) {
449+ InitializeMainContext (context);
450+ }
451+
452+ void Environment::InitializeMainContext (Local<Context> context) {
453+ context_.Reset (context->GetIsolate (), context);
454+ AssignToContext (context, ContextInfo (" " ));
434455 // TODO(joyeecheung): deserialize when the snapshot covers the environment
435456 // properties.
436457 CreateProperties ();
0 commit comments