diff --git a/src/node_realm.cc b/src/node_realm.cc index d2459d4eeb33..ae57010f93fa 100644 --- a/src/node_realm.cc +++ b/src/node_realm.cc @@ -19,6 +19,7 @@ using v8::MaybeLocal; using v8::Object; using v8::SnapshotCreator; using v8::String; +using v8::TryCatch; using v8::Value; Realm::Realm(Environment* env, v8::Local context, Kind kind) @@ -64,11 +65,22 @@ void Realm::CreateProperties() { Local ctx = context(); // Store primordials setup by the per-context script in the environment. - Local per_context_bindings = - GetPerContextExports(ctx, env_->isolate_data()).ToLocalChecked(); - Local primordials = - per_context_bindings->Get(ctx, env_->primordials_string()) - .ToLocalChecked(); + TryCatch try_catch(isolate_); + Local per_context_bindings; + Local primordials; + if (!GetPerContextExports(ctx, env_->isolate_data()) + .ToLocal(&per_context_bindings) || + !per_context_bindings->Get(ctx, env_->primordials_string()) + .ToLocal(&primordials)) { + // In general, this should only throw exceptions during local development + // when there's a temporary bug in the scripts. Print the exception here to + // facilitate debugging. + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { + PrintCaughtException(isolate_, ctx, try_catch); + } + env_->Exit(ExitCode::kBootstrapFailure); + return; + } CHECK(primordials->IsObject()); set_primordials(primordials.As());