Bug 1387503 - FestStreamReader should cancel the reader when the worker shutdowns, r=jorendorff

This commit is contained in:
Andrea Marchesini 2018-11-12 14:44:39 +01:00
parent 9674abaaa8
commit 7797a1a972
3 changed files with 75 additions and 4 deletions

View File

@ -66,10 +66,14 @@ FetchStreamReader::Create(JSContext* aCx, nsIGlobalObject* aGlobal,
RefPtr<WeakWorkerRef> workerRef =
WeakWorkerRef::Create(workerPrivate, [streamReader]() {
// The WorkerPrivate does have a context available, and we could pass
// it here to trigger cancellation of the reader, but the author of
// this comment chickened out.
streamReader->CloseAndRelease(nullptr, NS_ERROR_DOM_INVALID_STATE_ERR);
MOZ_ASSERT(streamReader);
MOZ_ASSERT(streamReader->mWorkerRef);
WorkerPrivate* workerPrivate = streamReader->mWorkerRef->GetPrivate();
MOZ_ASSERT(workerPrivate);
streamReader->CloseAndRelease(workerPrivate->GetJSContext(),
NS_ERROR_DOM_INVALID_STATE_ERR);
});
if (NS_WARN_IF(!workerRef)) {

View File

@ -83,3 +83,4 @@ skip-if = (os == 'linux') # Bug 1244409
[test_sharedWorker_privateBrowsing.html]
[test_shutdownCheck.xul]
support-files = worker_shutdownCheck.js
[test_readableStream_when_closing.html]

View File

@ -0,0 +1,66 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for ReadableStream+fetch when the worker is closing</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
</head>
<body>
<script>
function workerCode() {
onmessage = () => {
const BIG_BUFFER_SIZE = 1000000;
const fibStream = new ReadableStream({
start(controller) {},
pull(controller) {
const buffer = new Uint8Array(BIG_BUFFER_SIZE);
buffer.fill(42);
controller.enqueue(buffer);
}
});
const r = new Response(fibStream);
const p = r.blob();
self.postMessage("reading");
p.then(() => {
// really?
});
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["javascript.options.streams", true],
]}).then(() => {
const b = new Blob([workerCode+'workerCode();']);
const url = URL.createObjectURL(b);
const w = new Worker(url);
w.onmessage = function(e) {
ok(true, 'Worker is reading');
const wdm = Cc["@mozilla.org/dom/workers/workerdebuggermanager;1"].
getService(Ci.nsIWorkerDebuggerManager);
wdm.addListener({
onUnregister: function (dbg) {
if (dbg.url == url) {
ok(true, "Debugger with url " + url + " should be unregistered.");
wdm.removeListener(this);
SimpleTest.finish();
}
}
});
w.terminate();
}
w.postMessage("start");
});
</script>
</body>
</html>