From 8b05b6e59b29d29fba66b3978ec17c4209279e0d Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:08:34 +0100 Subject: [PATCH] fix: crash when drag-dropping some files (#46312) * fix: crash when drag-dropping some files Co-authored-by: Shelley Vohr * fix: extra destination context scope Co-authored-by: Shelley Vohr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- .../api/electron_api_context_bridge.cc | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 119b869c9f25..ff91fee761af 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -687,17 +687,26 @@ v8::MaybeLocal CreateProxyForAPI( continue; } } - v8::Local 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()); + { + v8::Context::Scope source_context_scope(source_context); + v8::Local 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();