fix: CHECK when adding view as its own child (#42067)

This commit is contained in:
Shelley Vohr 2024-05-09 15:47:47 +02:00 committed by GitHub
parent 731bc7a334
commit 6675f3ae65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -189,6 +189,14 @@ void View::AddChildViewAt(gin::Handle<View> child,
// has a View, possibly a wrapper view around the underlying platform View.
if (!view_)
return;
// This will CHECK and crash in View::AddChildViewAtImpl if not handled here.
if (view_ == child->view()) {
gin_helper::ErrorThrower(isolate()).ThrowError(
"A view cannot be added as its own child");
return;
}
size_t index =
std::min(child_views_.size(), maybe_index.value_or(child_views_.size()));
child_views_.emplace(child_views_.begin() + index, // index