@@ -668,28 +668,41 @@ ContextPtr NewContext(IsolatePtr iso,
668
668
return ctx;
669
669
}
670
670
671
- ContextPtr NewContextFromSnapshot (IsolatePtr iso,
671
+ RtnContext NewContextFromSnapshot (IsolatePtr iso,
672
672
size_t snapshot_blob_index,
673
673
int ref) {
674
674
Locker locker (iso);
675
675
Isolate::Scope isolate_scope (iso);
676
676
HandleScope handle_scope (iso);
677
677
678
+ RtnContext rtn = {};
679
+
678
680
// For function callbacks we need a reference to the context, but because of
679
681
// the complexities of C -> Go function pointers, we store a reference to the
680
682
// context as a simple integer identifier; this can then be used on the Go
681
683
// side to lookup the context in the context registry. We use slot 1 as slot 0
682
684
// has special meaning for the Chrome debugger.
683
685
684
- Local<Context> local_ctx =
685
- Context::FromSnapshot (iso, snapshot_blob_index).ToLocalChecked ();
686
+ Local<Context> local_ctx;
687
+ MaybeLocal<Context> maybe_local_ctx =
688
+ Context::FromSnapshot (iso, snapshot_blob_index);
689
+
690
+ if (!maybe_local_ctx.ToLocal (&local_ctx)) {
691
+ RtnError error = {nullptr , nullptr , nullptr };
692
+ error.msg = CopyString (" Failed to create context from snapshot index: " +
693
+ std::to_string (snapshot_blob_index));
694
+ rtn.error = error;
695
+ return rtn;
696
+ }
697
+
686
698
local_ctx->SetEmbedderData (1 , Integer::New (iso, ref));
687
699
688
700
m_ctx* ctx = new m_ctx;
689
701
ctx->ptr .Reset (iso, local_ctx);
690
702
ctx->iso = iso;
691
703
ctx->startup_data = nullptr ;
692
- return ctx;
704
+ rtn.context = ctx;
705
+ return rtn;
693
706
}
694
707
695
708
void ContextFree (ContextPtr ctx) {
0 commit comments