Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 2 - BroadcastChannel, r=asuth

This commit is contained in:
Andrea Marchesini 2018-04-17 20:51:02 +02:00
parent 8cb037ae07
commit ba519b7136
3 changed files with 20 additions and 8 deletions

View File

@ -311,15 +311,15 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
// We are already shutting down the worker. Let's return a non-active
// object.
if (NS_WARN_IF(!workerRef)) {
bc->mState = StateClosed;
return bc.forget();
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<ThreadSafeWorkerRef> tsr = new ThreadSafeWorkerRef(workerRef);
RefPtr<InitializeRunnable> runnable =
new InitializeRunnable(tsr, origin, principalInfo, aRv);
runnable->Dispatch(Closing, aRv);
runnable->Dispatch(Canceling, aRv);
if (aRv.Failed()) {
return nullptr;
}

View File

@ -68,11 +68,6 @@ private:
~BroadcastChannel();
void PostMessageData(BroadcastChannelMessage* aData);
void PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
ErrorResult& aRv);
void RemoveDocFromBFCache();
void DisconnectFromOwner() override;

View File

@ -121,4 +121,21 @@ async_test(t => {
}
}, 'BroadcastChannel created after a worker self.close()');
async_test(t => {
function workerCode() {
close();
var bc = new BroadcastChannel('worker-test-after-close');
bc.postMessage(true);
}
var bc = new BroadcastChannel('worker-test-after-close');
bc.onmessage = function(e) {
assert_true(e.data, "BroadcastChannel created on worker shutdown.");
t.done();
}
var workerBlob = new Blob([workerCode.toString() + ";workerCode();"], {type:"application/javascript"});
new Worker(URL.createObjectURL(workerBlob));
}, 'BroadcastChannel used after a worker self.close()');
</script>