@@ -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;
@@ -501,7 +504,7 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
501
504
502
505
Local<Object> exports = Object::New (isolate);
503
506
if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
504
- ! InitializePrimordials (context))
507
+ InitializePrimordials (context). IsNothing ( ))
505
508
return MaybeLocal<Object>();
506
509
return handle_scope.Escape (exports);
507
510
}
@@ -514,7 +517,7 @@ Local<Context> NewContext(Isolate* isolate,
514
517
auto context = Context::New (isolate, nullptr , object_template);
515
518
if (context.IsEmpty ()) return context;
516
519
517
- if (! InitializeContext (context)) {
520
+ if (InitializeContext (context). IsNothing ( )) {
518
521
return Local<Context>();
519
522
}
520
523
@@ -581,16 +584,17 @@ void InitializeContextRuntime(Local<Context> context) {
581
584
}
582
585
}
583
586
584
- bool InitializeContextForSnapshot (Local<Context> context) {
587
+ Maybe< bool > InitializeContextForSnapshot (Local<Context> context) {
585
588
Isolate* isolate = context->GetIsolate ();
586
589
HandleScope handle_scope (isolate);
587
590
588
591
context->SetEmbedderData (ContextEmbedderIndex::kAllowWasmCodeGeneration ,
589
592
True (isolate));
593
+
590
594
return InitializePrimordials (context);
591
595
}
592
596
593
- bool InitializePrimordials (Local<Context> context) {
597
+ Maybe< bool > InitializePrimordials (Local<Context> context) {
594
598
// Run per-context JS files.
595
599
Isolate* isolate = context->GetIsolate ();
596
600
Context::Scope context_scope (context);
@@ -603,10 +607,10 @@ bool InitializePrimordials(Local<Context> context) {
603
607
604
608
// Create primordials first and make it available to per-context scripts.
605
609
Local<Object> primordials = Object::New (isolate);
606
- if (! primordials->SetPrototype (context, Null (isolate)).FromJust () ||
610
+ if (primordials->SetPrototype (context, Null (isolate)).IsNothing () ||
607
611
!GetPerContextExports (context).ToLocal (&exports) ||
608
- ! exports->Set (context, primordials_string, primordials).FromJust ()) {
609
- return false ;
612
+ exports->Set (context, primordials_string, primordials).IsNothing ()) {
613
+ return Nothing< bool >() ;
610
614
}
611
615
612
616
static const char * context_files[] = {" internal/per_context/primordials" ,
@@ -623,27 +627,27 @@ bool InitializePrimordials(Local<Context> context) {
623
627
context, *module, ¶meters, nullptr );
624
628
Local<Function> fn;
625
629
if (!maybe_fn.ToLocal (&fn)) {
626
- return false ;
630
+ return Nothing< bool >() ;
627
631
}
628
632
MaybeLocal<Value> result =
629
633
fn->Call (context, Undefined (isolate), arraysize (arguments), arguments);
630
634
// Execution failed during context creation.
631
- // TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
632
635
if (result.IsEmpty ()) {
633
- return false ;
636
+ return Nothing< bool >() ;
634
637
}
635
638
}
636
639
637
- return true ;
640
+ return Just ( true ) ;
638
641
}
639
642
640
- bool InitializeContext (Local<Context> context) {
641
- if (! InitializeContextForSnapshot (context)) {
642
- return false ;
643
+ Maybe< bool > InitializeContext (Local<Context> context) {
644
+ if (InitializeContextForSnapshot (context). IsNothing ( )) {
645
+ return Nothing< bool >() ;
643
646
}
644
647
645
648
InitializeContextRuntime (context);
646
- return true ;
649
+
650
+ return Just (true );
647
651
}
648
652
649
653
uv_loop_t * GetCurrentEventLoop (Isolate* isolate) {
0 commit comments