Repository: electron/electron
File: shell/renderer/api/electron_api_context_bridge.cc (C++)

Code before:
                       error_target)
                       .ToLocal(&setter_proxy))
                continue;
            }

            v8::PropertyDescriptor prop_desc(getter_proxy, setter_proxy);
            std::ignore = proxy.GetHandle()->DefineProperty(
                destination_context, key.As<v8::Name>(), prop_desc);
          }
          continue;
        }
      }

      {
        v8::Context::Scope source_context_scope(source_context);
        v8::Local<v8::Value> value;
        if (!api.Get(key, &value))
          continue;

        auto passed_value = PassValueToOtherContextInner(
            source_context, source_execution_context, destination_context,
            value, api.GetHandle(), object_cache, support_dynamic_properties,
            recursion_depth + 1, error_target);
        if (passed_value.IsEmpty())
          return {};
        proxy.Set(key, passed_value.ToLocalChecked());
      }
    }

    return proxy.GetHandle();
  }
}

namespace {

void ExposeAPI(v8::Isolate* isolate,
               v8::Local<v8::Context> source_context,
               v8::Local<v8::Context> target_context,
               const std::string& key,
               v8::Local<v8::Value> api,
               gin_helper::Arguments* args) {
  DCHECK(!target_context.IsEmpty());
  v8::Context::Scope target_context_scope(target_context);
  gin_helper::Dictionary global(target_context->GetIsolate(),
                                target_context->Global());

  if (global.Has(key)) {
    args->ThrowError(
        "Cannot bind an API on top of an existing property on the window "
        "object");
    return;

Review comment (suggestion):
I think _technically_ this `proxy.Set` call should be within a `destination_context_scope`

Code after:
                       error_target)
                       .ToLocal(&setter_proxy))
                continue;
            }

            v8::PropertyDescriptor prop_desc(getter_proxy, setter_proxy);
            std::ignore = proxy.GetHandle()->DefineProperty(
                destination_context, key.As<v8::Name>(), prop_desc);
          }
          continue;
        }
      }

      {
        v8::Context::Scope source_context_scope(source_context);
        v8::Local<v8::Value> value;
        if (!api.Get(key, &value))
          continue;

        auto passed_value = PassValueToOtherContextInner(
            source_context, source_execution_context, destination_context,
            value, api.GetHandle(), object_cache, support_dynamic_properties,
            recursion_depth + 1, error_target);
        if (passed_value.IsEmpty())
          return {};

        {
          v8::Context::Scope inner_destination_context_scope(
              destination_context);
          proxy.Set(key, passed_value.ToLocalChecked());
        }
      }
    }

    return proxy.GetHandle();
  }
}

namespace {

void ExposeAPI(v8::Isolate* isolate,
               v8::Local<v8::Context> source_context,
               v8::Local<v8::Context> target_context,
               const std::string& key,
               v8::Local<v8::Value> api,
               gin_helper::Arguments* args) {
  DCHECK(!target_context.IsEmpty());
  v8::Context::Scope target_context_scope(target_context);
  gin_helper::Dictionary global(target_context->GetIsolate(),
                                target_context->Global());