@@ -20,8 +20,11 @@ using v8::Function;
2020using v8::FunctionCallbackInfo;
2121using v8::HandleScope;
2222using v8::Isolate;
23+ using v8::Just;
2324using v8::Local;
25+ using v8::Maybe;
2426using v8::MaybeLocal;
27+ using v8::Nothing;
2528using v8::Null;
2629using v8::Object;
2730using v8::ObjectTemplate;
@@ -523,58 +526,113 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
523526
524527// This runs at runtime, regardless of whether the context
525528// is created from a snapshot.
526- void InitializeContextRuntime (Local<Context> context) {
529+ Maybe< bool > InitializeContextRuntime (Local<Context> context) {
527530 Isolate* isolate = context->GetIsolate ();
528531 HandleScope handle_scope (isolate);
529532
530533 // Delete `Intl.v8BreakIterator`
531534 // https://github.com/nodejs/node/issues/14909
532- Local<String> intl_string = FIXED_ONE_BYTE_STRING (isolate, " Intl" );
533- Local<String> break_iter_string =
534- FIXED_ONE_BYTE_STRING (isolate, " v8BreakIterator" );
535- Local<Value> intl_v;
536- if (context->Global ()->Get (context, intl_string).ToLocal (&intl_v) &&
537- intl_v->IsObject ()) {
538- Local<Object> intl = intl_v.As <Object>();
539- intl->Delete (context, break_iter_string).Check ();
535+ {
536+ Local<String> intl_string =
537+ FIXED_ONE_BYTE_STRING (isolate, " Intl" );
538+ Local<String> break_iter_string =
539+ FIXED_ONE_BYTE_STRING (isolate, " v8BreakIterator" );
540+
541+ Local<Value> intl_v;
542+ if (!context->Global ()
543+ ->Get (context, intl_string)
544+ .ToLocal (&intl_v)) {
545+ return Nothing<bool >();
546+ }
547+
548+ if (intl_v->IsObject () &&
549+ intl_v.As <Object>()
550+ ->Delete (context, break_iter_string)
551+ .IsNothing ()) {
552+ return Nothing<bool >();
553+ }
540554 }
541555
542556 // Delete `Atomics.wake`
543557 // https://github.com/nodejs/node/issues/21219
544- Local<String> atomics_string = FIXED_ONE_BYTE_STRING (isolate, " Atomics" );
545- Local<String> wake_string = FIXED_ONE_BYTE_STRING (isolate, " wake" );
546- Local<Value> atomics_v;
547- if (context->Global ()->Get (context, atomics_string).ToLocal (&atomics_v) &&
548- atomics_v->IsObject ()) {
549- Local<Object> atomics = atomics_v.As <Object>();
550- atomics->Delete (context, wake_string).Check ();
558+ {
559+ Local<String> atomics_string =
560+ FIXED_ONE_BYTE_STRING (isolate, " Atomics" );
561+ Local<String> wake_string =
562+ FIXED_ONE_BYTE_STRING (isolate, " wake" );
563+
564+ Local<Value> atomics_v;
565+ if (!context->Global ()
566+ ->Get (context, atomics_string)
567+ .ToLocal (&atomics_v)) {
568+ return Nothing<bool >();
569+ }
570+
571+ if (atomics_v->IsObject () &&
572+ atomics_v.As <Object>()
573+ ->Delete (context, wake_string)
574+ .IsNothing ()) {
575+ return Nothing<bool >();
576+ }
551577 }
552578
553579 // Remove __proto__
554580 // https://github.com/nodejs/node/issues/31951
555- Local<String> object_string = FIXED_ONE_BYTE_STRING (isolate, " Object" );
556- Local<String> prototype_string = FIXED_ONE_BYTE_STRING (isolate, " prototype" );
557- Local<Object> prototype = context->Global ()
558- ->Get (context, object_string)
559- .ToLocalChecked ()
560- .As <Object>()
561- ->Get (context, prototype_string)
562- .ToLocalChecked ()
563- .As <Object>();
564- Local<String> proto_string = FIXED_ONE_BYTE_STRING (isolate, " __proto__" );
581+ Local<Object> prototype;
582+ {
583+ Local<String> object_string =
584+ FIXED_ONE_BYTE_STRING (isolate, " Object" );
585+ Local<String> prototype_string =
586+ FIXED_ONE_BYTE_STRING (isolate, " prototype" );
587+
588+ Local<Value> object_v;
589+ if (!context->Global ()
590+ ->Get (context, object_string)
591+ .ToLocal (&object_v)) {
592+ return Nothing<bool >();
593+ }
594+
595+ Local<Value> prototype_v;
596+ if (!object_v.As <Object>()
597+ ->Get (context, prototype_string)
598+ .ToLocal (&prototype_v)) {
599+ return Nothing<bool >();
600+ }
601+
602+ prototype = prototype_v.As <Object>();
603+ }
604+
605+ Local<String> proto_string =
606+ FIXED_ONE_BYTE_STRING (isolate, " __proto__" );
607+
565608 if (per_process::cli_options->disable_proto == " delete" ) {
566- prototype->Delete (context, proto_string).ToChecked ();
609+ if (prototype
610+ ->Delete (context, proto_string)
611+ .IsNothing ()) {
612+ return Nothing<bool >();
613+ }
567614 } else if (per_process::cli_options->disable_proto == " throw" ) {
568- Local<Value> thrower =
569- Function::New (context, ProtoThrower).ToLocalChecked ();
615+ Local<Value> thrower;
616+ if (!Function::New (context, ProtoThrower)
617+ .ToLocal (&thrower)) {
618+ return Nothing<bool >();
619+ }
620+
570621 PropertyDescriptor descriptor (thrower, thrower);
571622 descriptor.set_enumerable (false );
572623 descriptor.set_configurable (true );
573- prototype->DefineProperty (context, proto_string, descriptor).ToChecked ();
624+ if (prototype
625+ ->DefineProperty (context, proto_string, descriptor)
626+ .IsNothing ()) {
627+ return Nothing<bool >();
628+ }
574629 } else if (per_process::cli_options->disable_proto != " " ) {
575630 // Validated in ProcessGlobalArgs
576- FatalError (" InitializeContextRuntime()" , " invalid --disable-proto mode" );
631+ FatalError (" InitializeContextRuntime()" ,
632+ " invalid --disable-proto mode" );
577633 }
634+
635+ return Just (true );
578636}
579637
580638bool InitializeContextForSnapshot (Local<Context> context) {
@@ -638,8 +696,7 @@ bool InitializeContext(Local<Context> context) {
638696 return false ;
639697 }
640698
641- InitializeContextRuntime (context);
642- return true ;
699+ return InitializeContextRuntime (context).IsJust ();
643700}
644701
645702uv_loop_t * GetCurrentEventLoop (Isolate* isolate) {
0 commit comments