  void CopyResultToCallingContextAndFinalize(
      v8::Isolate* isolate,
      const v8::Local<v8::Object>& result) {
    v8::MaybeLocal<v8::Value> maybe_result;
    bool success = true;
    std::string error_message =
        "An unknown exception occurred while getting the result of the script";
    {
      v8::TryCatch try_catch(isolate);
      context_bridge::ObjectCache object_cache;
      maybe_result = PassValueToOtherContext(result->CreationContext(),
                                             promise_.GetContext(), result,
                                             &object_cache, false, 0);
      if (maybe_result.IsEmpty() || try_catch.HasCaught()) {
        success = false;
      }
      if (try_catch.HasCaught()) {
        auto message = try_catch.Message();

        if (!message.IsEmpty()) {
          gin::ConvertFromV8(isolate, message->Get(), &error_message);
        }
      }
    }
    if (!success) {
      // Failed convert so we send undefined everywhere
      if (callback_)
        std::move(callback_).Run(
            v8::Undefined(isolate),
            v8::Exception::Error(
                v8::String::NewFromUtf8(isolate, error_message.c_str())
                    .ToLocalChecked()));
      promise_.RejectWithErrorMessage(error_message);
    } else {
      v8::Local<v8::Context> context = promise_.GetContext();
      v8::Context::Scope context_scope(context);
      v8::Local<v8::Value> cloned_value = maybe_result.ToLocalChecked();
      if (callback_)
        std::move(callback_).Run(cloned_value, v8::Undefined(isolate));
      promise_.Resolve(cloned_value);
    }
  }
  void CopyResultToCallingContextAndFinalize(
      v8::Isolate* isolate,
      const v8::Local<v8::Object>& result) {
    v8::MaybeLocal<v8::Value> maybe_result;
    bool success = true;
    std::string error_message =
        "An unknown exception occurred while getting the result of the script";
    {
      v8::TryCatch try_catch(isolate);
      context_bridge::ObjectCache object_cache;
      maybe_result = PassValueToOtherContext(result->CreationContext(),
                                             promise_.GetContext(), result,
                                             &object_cache, false, 0);
      if (maybe_result.IsEmpty() || try_catch.HasCaught()) {
        success = false;
      }
      if (try_catch.HasCaught()) {
        auto message = try_catch.Message();

        if (!message.IsEmpty()) {
          gin::ConvertFromV8(isolate, message->Get(), &error_message);
        }
      }
    }
    if (!success) {
       
      if (callback_)
        std::move(callback_).Run(
            v8::Undefined(isolate),
            v8::Exception::Error(
                v8::String::NewFromUtf8(isolate, error_message.c_str())
                    .ToLocalChecked()));
      promise_.RejectWithErrorMessage(error_message);
    } else {
      v8::Local<v8::Context> context = promise_.GetContext();
      v8::Context::Scope context_scope(context);
      v8::Local<v8::Value> cloned_value = maybe_result.ToLocalChecked();
      if (callback_)
        std::move(callback_).Run(cloned_value, v8::Undefined(isolate));
      promise_.Resolve(cloned_value);
    }
  }