fix: ensure that functions are not retained beyond their context being released (#23207)

This commit is contained in:
Samuel Attard 2020-04-21 18:05:01 -07:00 committed by GitHub
parent aca2e4f968
commit 0cbcee6740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View file

@ -32,6 +32,16 @@ void RenderFrameFunctionStore::OnDestruct() {
delete this;
}
void RenderFrameFunctionStore::WillReleaseScriptContext(
v8::Local<v8::Context> context,
int32_t world_id) {
base::EraseIf(functions_, [context](auto const& pair) {
v8::Local<v8::Context> func_owning_context =
std::get<1>(pair.second).Get(context->GetIsolate());
return func_owning_context == context;
});
}
} // namespace context_bridge
} // namespace api

View file

@ -29,6 +29,8 @@ class RenderFrameFunctionStore final : public content::RenderFrameObserver {
// RenderFrameObserver implementation.
void OnDestruct() override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
int32_t world_id) override;
size_t take_func_id() { return next_func_id_++; }