fix: dangling pointer warning when updating menus (#38643)

This commit is contained in:
Charles Kerr 2023-06-08 09:29:32 -05:00 committed by GitHub
parent 95d6a932ca
commit 9d8da7839e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -706,8 +706,6 @@ void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
v8::Local<v8::Object> object;
if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
menu_.Reset(isolate, menu.ToV8());
// We only want to update the menu if the menu has a non-zero item count,
// or we risk crashes.
if (menu->model()->GetItemCount() == 0) {
@ -715,6 +713,8 @@ void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
} else {
window_->SetMenu(menu->model());
}
menu_.Reset(isolate, menu.ToV8());
} else if (value->IsNull()) {
RemoveMenu();
} else {