Bug 1278340 - BroadcastChannel should check for closed flag before dispatching events, r=smaug

This commit is contained in:
Andrea Marchesini 2016-06-07 00:37:47 +02:00
parent 05f6aaf959
commit f8c6086792
4 changed files with 42 additions and 8 deletions

View File

@ -105,11 +105,6 @@ private:
return mIsKeptAlive;
}
bool IsClosed() const
{
return mState != StateActive;
}
void RemoveDocFromBFCache();
RefPtr<BroadcastChannelChild> mActor;

View File

@ -58,9 +58,8 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
nsCOMPtr<DOMEventTargetHelper> helper = mBC;
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(helper);
// This object has been already closed by content or is going to be deleted
// soon. No notify is required.
if (!eventTarget || mBC->IsClosed()) {
// The object is going to be deleted soon. No notify is required.
if (!eventTarget) {
return true;
}

View File

@ -15,6 +15,7 @@ support-files =
[test_broadcastchannel_any.html]
[test_broadcastchannel_basic.html]
[test_broadcastchannel_close.html]
[test_broadcastchannel_close2.html]
[test_broadcastchannel_self.html]
[test_broadcastchannel_sharedWorker.html]
[test_broadcastchannel_worker.html]

View File

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for BroadcastChannel</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="content"></div>
<script type="application/javascript">
function runTest() {
var c1 = new BroadcastChannel('foo');
var c2 = new BroadcastChannel('foo');
var status = [];
c2.onmessage = function(e) {
status.push(e.data);
if (status.length == 2) {
is (status[0], 'first', "First message has been received");
is (status[1], 'second', "Second message has been received");
SimpleTest.finish();
}
c2.close();
}
c1.postMessage('first');
c1.postMessage('second');
}
SimpleTest.waitForExplicitFinish();
runTest();
</script>
</body>
</html>