refactor: return null when passing empty menu templates (#23364)
This commit is contained in:
parent
59c1c12e0b
commit
0f0cc51b35
4 changed files with 11 additions and 13 deletions
|
@ -689,10 +689,16 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
|||
if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
|
||||
gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
|
||||
menu_.Reset(isolate, menu.ToV8());
|
||||
window_->SetMenu(menu->model());
|
||||
|
||||
// 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) {
|
||||
RemoveMenu();
|
||||
} else {
|
||||
window_->SetMenu(menu->model());
|
||||
}
|
||||
} else if (value->IsNull()) {
|
||||
menu_.Reset();
|
||||
window_->SetMenu(nullptr);
|
||||
RemoveMenu();
|
||||
} else {
|
||||
isolate->ThrowException(
|
||||
v8::Exception::TypeError(gin::StringToV8(isolate, "Invalid Menu")));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue