Commit bdfea9ac authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Do not produce module code cache on destoryed contexts

Since we produce code cache asynchronously, content might
already be invalid, e.g. due to frame detach.

Added a test which catches the issue in 2 of 10 runs.

Bug: none
Change-Id: Ie4368b2a9dce68d236a7310900488056a9e20765
Reviewed-on: https://chromium-review.googlesource.com/c/1483365Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635153}
parent ecc7fb6e
...@@ -263,6 +263,10 @@ ModulatorImplBase::ModuleRequestsFromScriptModule(ScriptModule script_module) { ...@@ -263,6 +263,10 @@ ModulatorImplBase::ModuleRequestsFromScriptModule(ScriptModule script_module) {
void ModulatorImplBase::ProduceCacheModuleTreeTopLevel( void ModulatorImplBase::ProduceCacheModuleTreeTopLevel(
ModuleScript* module_script) { ModuleScript* module_script) {
DCHECK(module_script); DCHECK(module_script);
// Since we run this asynchronously, context might be gone already,
// for example because the frame was detached.
if (!script_state_->ContextIsValid())
return;
HeapHashSet<Member<const ModuleScript>> discovered_set; HeapHashSet<Member<const ModuleScript>> discovered_set;
ProduceCacheModuleTree(module_script, &discovered_set); ProduceCacheModuleTree(module_script, &discovered_set);
} }
......
Tests that storing module cache does not crash with detached frame. Note that crash does only reproduce in ~20% of the runs, depending on timing.
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<iframe srcdoc='
<script type="module">
if (!localStorage["step"]) {
localStorage["step"] = "reload1";
window.parent.location.reload();
} else if (localStorage["step"] === "reload1") {
localStorage["step"] = "reload2";
window.parent.location.reload();
} else {
window.parent.document.querySelector("iframe").remove();
}
</script>
'></iframe>
Tests that storing module cache does not crash with detached frame.
Note that crash does only reproduce in ~20% of the runs, depending on timing.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment