@@ -20,8 +20,11 @@ using v8::Function;
20
20
using v8::FunctionCallbackInfo;
21
21
using v8::HandleScope;
22
22
using v8::Isolate;
23
+ using v8::Just;
23
24
using v8::Local;
25
+ using v8::Maybe;
24
26
using v8::MaybeLocal;
27
+ using v8::Nothing;
25
28
using v8::Null;
26
29
using v8::Object;
27
30
using v8::ObjectTemplate;
@@ -523,58 +526,113 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
523
526
524
527
// This runs at runtime, regardless of whether the context
525
528
// is created from a snapshot.
526
- void InitializeContextRuntime (Local<Context> context) {
529
+ Maybe< bool > InitializeContextRuntime (Local<Context> context) {
527
530
Isolate* isolate = context->GetIsolate ();
528
531
HandleScope handle_scope (isolate);
529
532
530
533
// Delete `Intl.v8BreakIterator`
531
534
// 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
+ }
540
554
}
541
555
542
556
// Delete `Atomics.wake`
543
557
// 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
+ }
551
577
}
552
578
553
579
// Remove __proto__
554
580
// 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
+
565
608
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
+ }
567
614
} 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
+
570
621
PropertyDescriptor descriptor (thrower, thrower);
571
622
descriptor.set_enumerable (false );
572
623
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
+ }
574
629
} else if (per_process::cli_options->disable_proto != " " ) {
575
630
// Validated in ProcessGlobalArgs
576
- FatalError (" InitializeContextRuntime()" , " invalid --disable-proto mode" );
631
+ FatalError (" InitializeContextRuntime()" ,
632
+ " invalid --disable-proto mode" );
577
633
}
634
+
635
+ return Just (true );
578
636
}
579
637
580
638
bool InitializeContextForSnapshot (Local<Context> context) {
@@ -638,8 +696,7 @@ bool InitializeContext(Local<Context> context) {
638
696
return false ;
639
697
}
640
698
641
- InitializeContextRuntime (context);
642
- return true ;
699
+ return InitializeContextRuntime (context).IsJust ();
643
700
}
644
701
645
702
uv_loop_t * GetCurrentEventLoop (Isolate* isolate) {
0 commit comments