@@ -668,28 +668,41 @@ ContextPtr NewContext(IsolatePtr iso,
668668 return ctx;
669669}
670670
671- ContextPtr NewContextFromSnapshot (IsolatePtr iso,
671+ RtnContext NewContextFromSnapshot (IsolatePtr iso,
672672 size_t snapshot_blob_index,
673673 int ref) {
674674 Locker locker (iso);
675675 Isolate::Scope isolate_scope (iso);
676676 HandleScope handle_scope (iso);
677677
678+ RtnContext rtn = {};
679+
678680 // For function callbacks we need a reference to the context, but because of
679681 // the complexities of C -> Go function pointers, we store a reference to the
680682 // context as a simple integer identifier; this can then be used on the Go
681683 // side to lookup the context in the context registry. We use slot 1 as slot 0
682684 // has special meaning for the Chrome debugger.
683685
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+
686698 local_ctx->SetEmbedderData (1 , Integer::New (iso, ref));
687699
688700 m_ctx* ctx = new m_ctx;
689701 ctx->ptr .Reset (iso, local_ctx);
690702 ctx->iso = iso;
691703 ctx->startup_data = nullptr ;
692- return ctx;
704+ rtn.context = ctx;
705+ return rtn;
693706}
694707
695708void ContextFree (ContextPtr ctx) {
0 commit comments