Skip to content

Commit

Permalink
Avoid panic when postMessage targets closed window.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Jul 11, 2017
1 parent 4b91014 commit 4c54129
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/script/dom/window.rs
Expand Up @@ -2000,7 +2000,8 @@ impl Runnable for PostMessageHandler {
impl Window {
pub fn post_message(&self, origin: Option<ImmutableOrigin>, data: StructuredCloneData) {
let runnable = PostMessageHandler::new(self, origin, data);
let msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::DomEvent, box runnable);
let runnable = self.get_runnable_wrapper().wrap_runnable(box runnable);
let msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::DomEvent, runnable);
// TODO(#12718): Use the "posted message task source".
let _ = self.script_chan.send(msg);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -13929,6 +13929,12 @@
{}
]
],
"mozilla/postmessage_closed.html": [
[
"/_mozilla/mozilla/postmessage_closed.html",
{}
]
],
"mozilla/preferences.html": [
[
"/_mozilla/mozilla/preferences.html",
Expand Down Expand Up @@ -26770,6 +26776,10 @@
"47c91f505cb8120a7f4b310b260f13408f06b8fc",
"testharness"
],
"mozilla/postmessage_closed.html": [
"70fc1b9dad5f611285f8f4ed04454800283e223c",
"testharness"
],
"mozilla/preferences.html": [
"7584699a938adf516ea3b7d6f22fd11d0b0942cf",
"testharness"
Expand Down
14 changes: 14 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/postmessage_closed.html
@@ -0,0 +1,14 @@
<!doctype html>
<meta charset="utf-8">
<title>Window.postMessage does not panic when a window is closed before the message is received</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe></iframe>
<script>
async_test(function(t) {
var i = document.querySelector('iframe');
i.contentWindow.postMessage('hi', '*');
i.remove();
t.step_timeout(function() { t.done() }, 0);
});
</script>

0 comments on commit 4c54129

Please sign in to comment.