@@ -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;
@@ -501,7 +504,7 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
501504
502505 Local<Object> exports = Object::New (isolate);
503506 if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
504- ! InitializePrimordials (context))
507+ InitializePrimordials (context). IsNothing ( ))
505508 return MaybeLocal<Object>();
506509 return handle_scope.Escape (exports);
507510}
@@ -514,7 +517,7 @@ Local<Context> NewContext(Isolate* isolate,
514517 auto context = Context::New (isolate, nullptr , object_template);
515518 if (context.IsEmpty ()) return context;
516519
517- if (! InitializeContext (context)) {
520+ if (InitializeContext (context). IsNothing ( )) {
518521 return Local<Context>();
519522 }
520523
@@ -581,16 +584,17 @@ void InitializeContextRuntime(Local<Context> context) {
581584 }
582585}
583586
584- bool InitializeContextForSnapshot (Local<Context> context) {
587+ Maybe< bool > InitializeContextForSnapshot (Local<Context> context) {
585588 Isolate* isolate = context->GetIsolate ();
586589 HandleScope handle_scope (isolate);
587590
588591 context->SetEmbedderData (ContextEmbedderIndex::kAllowWasmCodeGeneration ,
589592 True (isolate));
593+
590594 return InitializePrimordials (context);
591595}
592596
593- bool InitializePrimordials (Local<Context> context) {
597+ Maybe< bool > InitializePrimordials (Local<Context> context) {
594598 // Run per-context JS files.
595599 Isolate* isolate = context->GetIsolate ();
596600 Context::Scope context_scope (context);
@@ -603,10 +607,10 @@ bool InitializePrimordials(Local<Context> context) {
603607
604608 // Create primordials first and make it available to per-context scripts.
605609 Local<Object> primordials = Object::New (isolate);
606- if (! primordials->SetPrototype (context, Null (isolate)).FromJust () ||
610+ if (primordials->SetPrototype (context, Null (isolate)).IsNothing () ||
607611 !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 >() ;
610614 }
611615
612616 static const char * context_files[] = {" internal/per_context/primordials" ,
@@ -623,27 +627,27 @@ bool InitializePrimordials(Local<Context> context) {
623627 context, *module , ¶meters, nullptr );
624628 Local<Function> fn;
625629 if (!maybe_fn.ToLocal (&fn)) {
626- return false ;
630+ return Nothing< bool >() ;
627631 }
628632 MaybeLocal<Value> result =
629633 fn->Call (context, Undefined (isolate), arraysize (arguments), arguments);
630634 // Execution failed during context creation.
631- // TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
632635 if (result.IsEmpty ()) {
633- return false ;
636+ return Nothing< bool >() ;
634637 }
635638 }
636639
637- return true ;
640+ return Just ( true ) ;
638641}
639642
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 >() ;
643646 }
644647
645648 InitializeContextRuntime (context);
646- return true ;
649+
650+ return Just (true );
647651}
648652
649653uv_loop_t * GetCurrentEventLoop (Isolate* isolate) {
0 commit comments