mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1387503 - FestStreamReader should cancel the reader when the worker shutdowns, r=jorendorff
This commit is contained in:
parent
9674abaaa8
commit
7797a1a972
@ -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)) {
|
||||
|
@ -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]
|
||||
|
66
dom/workers/test/test_readableStream_when_closing.html
Normal file
66
dom/workers/test/test_readableStream_when_closing.html
Normal 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>
|
||||
|
Loading…
Reference in New Issue
Block a user