Bug 998474 - SharedWorker should allow MessagePort to be opened asynchronously, r=khuey

This commit is contained in:
Andrea Marchesini 2014-06-27 10:04:45 -07:00
parent 3a3b025f95
commit ebc077e9f1
4 changed files with 73 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIDOMEvent.h"
#include "SharedWorker.h"
@ -17,6 +18,7 @@ using mozilla::dom::EventHandlerNonNull;
using mozilla::dom::MessagePortBase;
using mozilla::dom::Optional;
using mozilla::dom::Sequence;
using mozilla::dom::AutoNoJSAPI;
using namespace mozilla;
USING_WORKERS_NAMESPACE
@ -42,6 +44,28 @@ public:
mEvents.SwapElements(aEvents);
}
bool PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
if (mBehavior == WorkerThreadModifyBusyCount) {
return aWorkerPrivate->ModifyBusyCount(aCx, true);
}
return true;
}
void PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
if (!aDispatchResult) {
if (mBehavior == WorkerThreadModifyBusyCount) {
aWorkerPrivate->ModifyBusyCount(aCx, false);
}
if (aCx) {
JS_ReportPendingException(aCx);
}
}
}
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
};
@ -281,6 +305,8 @@ DelayedEventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
mMessagePort->AssertCorrectThread();
MOZ_ASSERT(mEvents.Length());
AutoNoJSAPI nojsapi;
bool ignored;
for (uint32_t i = 0; i < mEvents.Length(); i++) {
mMessagePort->DispatchEvent(mEvents[i], &ignored);

View File

@ -0,0 +1,6 @@
self.addEventListener("connect", function(e) {
var port = e.ports[0];
port.onmessage = function(e) {
port.postMessage(eval(e.data));
};
});

View File

@ -7,6 +7,7 @@ support-files =
bug1014466_worker.js
bug1020226_worker.js
bug1020226_frame.html
bug998474_worker.js
clearTimeouts_worker.js
closeOnGC_server.sjs
closeOnGC_worker.js
@ -85,6 +86,7 @@ support-files =
[test_bug1010784.html]
[test_bug1014466.html]
[test_bug1020226.html]
[test_bug998474.html]
[test_chromeWorker.html]
[test_clearTimeouts.html]
[test_close.html]

View File

@ -0,0 +1,39 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for bug 998474</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="boom();">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
function boom()
{
var worker = new SharedWorker("bug998474_worker.js");
setTimeout(function() {
port = worker.port;
port.postMessage("");
setTimeout(function() {
port.start();
ok(true, "Still alive!");
SimpleTest.finish();
}, 150);
}, 150);
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>