diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 3c3eacf76409..1d6eab926ee7 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -398,19 +398,19 @@ v8::MaybeLocal CreateProxyForAPI( context_bridge::ObjectCache* object_cache, int recursion_depth) { gin_helper::Dictionary api(source_context->GetIsolate(), api_object); - gin_helper::Dictionary proxy = - gin::Dictionary::CreateEmpty(destination_context->GetIsolate()); - object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle()); - auto maybe_keys = api.GetHandle()->GetOwnPropertyNames( - source_context, - static_cast(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS), - v8::KeyConversionMode::kConvertToString); - if (maybe_keys.IsEmpty()) - return v8::MaybeLocal(proxy.GetHandle()); - auto keys = maybe_keys.ToLocalChecked(); - v8::Context::Scope destination_context_scope(destination_context); { + gin_helper::Dictionary proxy = + gin::Dictionary::CreateEmpty(destination_context->GetIsolate()); + object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle()); + auto maybe_keys = api.GetHandle()->GetOwnPropertyNames( + source_context, + static_cast(v8::ONLY_ENUMERABLE | v8::SKIP_SYMBOLS), + v8::KeyConversionMode::kConvertToString); + if (maybe_keys.IsEmpty()) + return v8::MaybeLocal(proxy.GetHandle()); + auto keys = maybe_keys.ToLocalChecked(); + uint32_t length = keys->Length(); std::string key_str; for (uint32_t i = 0; i < length; i++) { diff --git a/spec-main/api-context-bridge-spec.ts b/spec-main/api-context-bridge-spec.ts index f081f4602dce..c471d5cb8a5b 100644 --- a/spec-main/api-context-bridge-spec.ts +++ b/spec-main/api-context-bridge-spec.ts @@ -422,6 +422,7 @@ describe('contextBridge', () => { string: 'string', boolean: true, arr: [123, 'string', true, ['foo']], + getObject: () => ({ thing: 123 }), getNumber: () => 123, getString: () => 'string', getBoolean: () => true, @@ -455,6 +456,7 @@ describe('contextBridge', () => { [example.arr[3][0], String], [example.getNumber, Function], [example.getNumber(), Number], + [example.getObject(), Object], [example.getString(), String], [example.getBoolean(), Boolean], [example.getArr(), Array],