async function test_nativeStream_continue(r, that) {
that.ok(r.body instanceof that.ReadableStream, "We have a ReadableStream");
let a = r.clone();
that.ok(a instanceof that.Response, "We have a cloned Response");
that.ok(a.body instanceof that.ReadableStream, "We have a ReadableStream");
let b = a.clone();
that.ok(b instanceof that.Response, "We have a cloned Response");
that.ok(b.body instanceof that.ReadableStream, "We have a ReadableStream");
let blob = await r.blob();
that.ok(blob instanceof that.Blob, "We have a blob");
let d = await a.body.getReader().read();
that.ok(!d.done, "We have read something!");
blob = await b.blob();
that.ok(blob instanceof that.Blob, "We have a blob");
}
async function test_timeout(compartment) {
info("test_timeout");
let blob = new Blob([""]);
let r = await fetch(URL.createObjectURL(blob));
async function test_nonNativeStream_continue(data, that) {
that.ok(
data.r.body instanceof that.ReadableStream, "We have a ReadableStream"
);
let a = data.r.clone();
that.ok(a instanceof that.Response, "We have a cloned Response");
that.ok(a.body instanceof that.ReadableStream, "We have a ReadableStream");
let b = a.clone();
that.ok(b instanceof that.Response, "We have a cloned Response");
that.ok(b.body instanceof that.ReadableStream, "We have a ReadableStream");
let blob = await data.r.blob();
that.ok(blob instanceof that.Blob, "We have a blob");
let d = await a.body.getReader().read();
that.ok(!d.done, "We have read something!");
blob = await b.blob();
that.ok(blob instanceof that.Blob, "We have a blob");
that.is(blob.size, data.buffer.byteLength, "Blob size matches");
}
async function test_noUint8Array(compartment) {
info("test_noUint8Array");
let r = new Response( new ReadableStream({
start: controller => {
controller.enqueue("hello world!");
controller.close();
},
})
);
async function test_noUint8Array_continue(r, that) {
that.ok(r.body instanceof that.ReadableStream, "We have a ReadableStream");
try {
await r.blob();
that.ok(false, "We cannot have a blob here!");
} catch (ex) {
that.ok(true, "We cannot have a blob here!");
}
}
async function test_pendingStream(compartment) {
let r = new Response( new ReadableStream({
start: controller => {
controller.enqueue(makeBuffer(BIG_BUFFER_SIZE)); // Let's keep this controler open.
self.ccc = controller;
},
})
);
async function test_nativeStream_cache_continue(data, that) {
that.info("Retrieving the stored value");
let cacheResponse = await data.cache.match(data.url);
that.info("Converting the response to text");
let cacheBody = await cacheResponse.text();
async function test_nonNativeStream_cache(compartment) {
info("test_nonNativeStream_cache");
let url = "/nonNativeStream";
let cache = await caches.open("nonNativeStream");
let buffer = makeBuffer(BIG_BUFFER_SIZE);
info("Buffer size: " + buffer.byteLength);
info("Storing a body as a string");
let r = new Response( new ReadableStream({
start: controller => {
controller.enqueue(buffer);
controller.close();
},
})
);
async function test_nonNativeStream_cache_continue(data, that) {
await data.cache.put(data.url, data.r);
that.info("Retrieving the stored value");
let cacheResponse = await data.cache.match(data.url);
that.info("Converting the response to text");
let cacheBody = await cacheResponse.arrayBuffer();
that.ok(cacheBody instanceof that.ArrayBuffer, "Body is an array buffer");
that.is(cacheBody.byteLength, BIG_BUFFER_SIZE, "Body length is correct");
let value = 0; for (let i = 0; i < 1000000; i += 1000) {
that.is( new Uint8Array(cacheBody)[i],
++value % 255, "byte in position " + i + " is correct"
);
}
await data.caches.delete("nonNativeStream");
}
async function test_codeExecution(compartment) {
info("test_codeExecution");
let r = new Response( new ReadableStream({
start(c) {
controller = c;
},
pull() {
console.log("pull called");
},
})
);
// This is intended to just be a drop-in replacement for an old observer // notification. function addConsoleStorageListener(listener) { const ConsoleAPIStorage = SpecialPowers.Cc[ "@mozilla.org/consoleAPI-storage;1"
].getService(SpecialPowers.Ci.nsIConsoleAPIStorage);
listener.__handler = (message, id) => {
listener.observe(message, id);
};
ConsoleAPIStorage.addLogEventListener(
listener.__handler,
SpecialPowers.wrap(document).nodePrincipal
);
}
async function test_global(compartment) {
info("test_global: " + compartment);
self.foo = 42;
self.iter = ITER_MAX;
let r = new Response( new ReadableStream({
start(c) {
self.controller = c;
},
pull() { if (!("iter" in self) || self.iter < 0 || self.iter > ITER_MAX) { throw"Something bad is happening here!";
}
let buffer = new Uint8Array(1);
buffer.fill(self.foo);
self.controller.enqueue(buffer);
if (--self.iter == 0) {
controller.close();
}
},
})
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.