@@ -306,28 +306,27 @@ std::string GetExecPath(const std::vector<std::string>& argv) {
306
306
}
307
307
308
308
Environment::Environment (IsolateData* isolate_data,
309
- Local<Context> context ,
309
+ Isolate* isolate ,
310
310
const std::vector<std::string>& args,
311
311
const std::vector<std::string>& exec_args,
312
312
EnvironmentFlags::Flags flags,
313
313
ThreadId thread_id)
314
- : isolate_(context-> GetIsolate () ),
314
+ : isolate_(isolate ),
315
315
isolate_data_(isolate_data),
316
- immediate_info_(context-> GetIsolate () ),
317
- tick_info_(context-> GetIsolate () ),
316
+ immediate_info_(isolate ),
317
+ tick_info_(isolate ),
318
318
timer_base_(uv_now(isolate_data->event_loop ())),
319
319
exec_argv_(exec_args),
320
320
argv_(args),
321
321
exec_path_(GetExecPath(args)),
322
322
should_abort_on_uncaught_toggle_(isolate_, 1 ),
323
323
stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields ),
324
324
flags_(flags),
325
- thread_id_(thread_id.id == static_cast <uint64_t >(-1 ) ?
326
- AllocateEnvironmentThreadId().id : thread_id.id),
327
- context_(context-> GetIsolate (), context ) {
325
+ thread_id_(thread_id.id == static_cast <uint64_t >(-1 )
326
+ ? AllocateEnvironmentThreadId().id
327
+ : thread_id.id ) {
328
328
// We'll be creating new objects so make sure we've entered the context.
329
- HandleScope handle_scope (isolate ());
330
- Context::Scope context_scope (context);
329
+ HandleScope handle_scope (isolate);
331
330
332
331
// Set some flags if only kDefaultFlags was passed. This can make API version
333
332
// transitions easier for embedders.
@@ -338,6 +337,8 @@ Environment::Environment(IsolateData* isolate_data,
338
337
}
339
338
340
339
set_env_vars (per_process::system_environment);
340
+ // TODO(joyeecheung): pass Isolate* and env_vars to it instead of the entire
341
+ // env
341
342
enabled_debug_list_.Parse (this );
342
343
343
344
// We create new copies of the per-Environment option sets, so that it is
@@ -348,13 +349,15 @@ Environment::Environment(IsolateData* isolate_data,
348
349
inspector_host_port_.reset (
349
350
new ExclusiveAccess<HostPort>(options_->debug_options ().host_port ));
350
351
352
+ if (flags & EnvironmentFlags::kOwnsProcessState ) {
353
+ set_abort_on_uncaught_exception (false );
354
+ }
355
+
351
356
#if HAVE_INSPECTOR
352
357
// We can only create the inspector agent after having cloned the options.
353
358
inspector_agent_ = std::make_unique<inspector::Agent>(this );
354
359
#endif
355
360
356
- AssignToContext (context, ContextInfo (" " ));
357
-
358
361
static uv_once_t init_once = UV_ONCE_INIT;
359
362
uv_once (&init_once, InitThreadLocalOnce);
360
363
uv_key_set (&thread_local_env, this );
@@ -367,8 +370,7 @@ Environment::Environment(IsolateData* isolate_data,
367
370
368
371
destroy_async_id_list_.reserve (512 );
369
372
370
- performance_state_ =
371
- std::make_unique<performance::PerformanceState>(isolate ());
373
+ performance_state_ = std::make_unique<performance::PerformanceState>(isolate);
372
374
performance_state_->Mark (
373
375
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
374
376
performance_state_->Mark (performance::NODE_PERFORMANCE_MILESTONE_NODE_START,
@@ -400,6 +402,29 @@ Environment::Environment(IsolateData* isolate_data,
400
402
async_hooks_.no_force_checks ();
401
403
}
402
404
405
+ // This adjusts the return value of base_object_count() so that tests that
406
+ // check the count do not have to account for internally created BaseObjects.
407
+ initial_base_object_count_ = base_object_count ();
408
+ }
409
+
410
+ Environment::Environment (IsolateData* isolate_data,
411
+ Local<Context> context,
412
+ const std::vector<std::string>& args,
413
+ const std::vector<std::string>& exec_args,
414
+ EnvironmentFlags::Flags flags,
415
+ ThreadId thread_id)
416
+ : Environment(isolate_data,
417
+ context->GetIsolate (),
418
+ args,
419
+ exec_args,
420
+ flags,
421
+ thread_id) {
422
+ InitializeMainContext (context);
423
+ }
424
+
425
+ void Environment::InitializeMainContext (Local<Context> context) {
426
+ context_.Reset (context->GetIsolate (), context);
427
+ AssignToContext (context, ContextInfo (" " ));
403
428
// TODO(joyeecheung): deserialize when the snapshot covers the environment
404
429
// properties.
405
430
CreateProperties ();
0 commit comments