refactor: simplify NativeWindow-to-BaseWindow lookup (#49520)

refactor: simplify native window to base window lookup
This commit is contained in:
Charles Kerr
2026-01-26 05:28:57 -06:00
committed by GitHub
parent 75be2fe8d6
commit 6766343173
10 changed files with 40 additions and 78 deletions

View File

@@ -111,8 +111,8 @@ BaseWindow::BaseWindow(v8::Isolate* isolate,
}
// Creates NativeWindow.
window_ = NativeWindow::Create(
options, parent.IsEmpty() ? nullptr : parent->window_.get());
NativeWindow* parent_native = parent.IsEmpty() ? nullptr : parent->window();
window_ = NativeWindow::Create(GetID(), options, parent_native);
window_->AddObserver(this);
SetContentView(View::Create(isolate));
@@ -146,7 +146,6 @@ BaseWindow::~BaseWindow() {
}
void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
AttachAsUserData(window_.get());
gin_helper::TrackableObject<BaseWindow>::InitWith(isolate, wrapper);
// We can only append this window to parent window's child windows after this

View File

@@ -336,11 +336,12 @@ void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
// static
v8::Local<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
NativeWindow* native_window) {
auto* existing = TrackableObject::FromWrappedClass(isolate, native_window);
if (existing)
return existing->GetWrapper();
else
return v8::Null(isolate);
if (native_window != nullptr) {
if (auto* base = FromWeakMapID(isolate, native_window->base_window_id()))
return base->GetWrapper();
}
return v8::Null(isolate);
}
} // namespace electron::api