diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/stream | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/stream')
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1387503-1.js | 37 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1387503-2.js | 39 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1503399-1.js | 18 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1503399-2.js | 11 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1503406.js | 13 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1512008.js | 8 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1513266.js | 16 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/bug-1515816.js | 17 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/proper-realm-cancel.js | 6 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/proper-realm-pull.js | 6 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/reader-closedPromise-handled-2.js | 33 | ||||
-rw-r--r-- | js/src/jit-test/tests/stream/reader-closedPromise-handled.js | 23 |
12 files changed, 227 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/stream/bug-1387503-1.js b/js/src/jit-test/tests/stream/bug-1387503-1.js new file mode 100644 index 0000000000..149d68d51d --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1387503-1.js @@ -0,0 +1,37 @@ +// Test uncatchable error when a stream source's pull() method is called. + +// Make `debugger;` raise an uncatchable error. +let g = newGlobal({newCompartment: true}); +g.parent = this; +g.hit = false; +g.eval(` + new Debugger(parent).onDebuggerStatement = _frame => (hit = true, null); +`); + +// Create a stream whose pull() method raises an uncatchable error, +// and try reading from it. +let readerCreated = false; +let fnFinished = false; +async function fn() { + try { + let stream = new ReadableStream({ + start(controller) {}, + pull(controller) { + debugger; + } + }); + + let reader = stream.getReader(); + let p = reader.read(); + readerCreated = true; + await p; + } finally { + fnFinished = true; + } +} + +fn(); +drainJobQueue(); +assertEq(readerCreated, true); +assertEq(g.hit, true); +assertEq(fnFinished, false); diff --git a/js/src/jit-test/tests/stream/bug-1387503-2.js b/js/src/jit-test/tests/stream/bug-1387503-2.js new file mode 100644 index 0000000000..de1f01e1a5 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1387503-2.js @@ -0,0 +1,39 @@ +// Test uncatchable error when a stream's queuing strategy's size() method is called. + +// Make `debugger;` raise an uncatchable exception. +let g = newGlobal({newCompartment: true}); +g.parent = this; +g.hit = false; +g.eval(` + var dbg = new Debugger(parent); + dbg.onDebuggerStatement = (_frame, exc) => (hit = true, null); +`); + +let fnFinished = false; +async function fn() { + // Await once to postpone the uncatchable error until we're running inside + // a reaction job. We don't want the rest of the test to be terminated. + // (`drainJobQueue` catches uncatchable errors!) + await 1; + + try { + // Create a stream with a strategy whose .size() method raises an + // uncatchable exception, and have it call that method. + new ReadableStream({ + start(controller) { + controller.enqueue("FIRST POST"); // this calls .size() + } + }, { + size() { + debugger; + } + }); + } finally { + fnFinished = true; + } +} + +fn(); +drainJobQueue(); +assertEq(g.hit, true); +assertEq(fnFinished, false); diff --git a/js/src/jit-test/tests/stream/bug-1503399-1.js b/js/src/jit-test/tests/stream/bug-1503399-1.js new file mode 100644 index 0000000000..fb3cdac44f --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1503399-1.js @@ -0,0 +1,18 @@ +// Don't assert if the wrapper that's the value of stream.[[reader]] gets nuked. + +load(libdir + "asserts.js"); + +ignoreUnhandledRejections(); + +let g = newGlobal({newCompartment: true}); +let stream = new ReadableStream({ + start(controller) { + controller.enqueue("ponies"); + controller.close(); + } +}); +g.stream = stream; +g.eval("var reader = ReadableStream.prototype.getReader.call(stream);"); +nukeCCW(g.reader); +assertErrorMessage(() => g.eval("reader.read()"), g.TypeError, "can't access dead object"); +g.eval("reader.releaseLock();"); diff --git a/js/src/jit-test/tests/stream/bug-1503399-2.js b/js/src/jit-test/tests/stream/bug-1503399-2.js new file mode 100644 index 0000000000..c8704e6447 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1503399-2.js @@ -0,0 +1,11 @@ +// Don't assert if the wrapper that's the value of reader.[[stream]] gets nuked. + +load(libdir + "asserts.js"); + +let g = newGlobal({newCompartment: true}); +let stream = new g.ReadableStream({}); +let reader = ReadableStream.prototype.getReader.call(stream); +nukeCCW(stream); + +assertErrorMessage(() => reader.read(), TypeError, "can't access dead object"); +assertErrorMessage(() => reader.releaseLock(), TypeError, "can't access dead object"); diff --git a/js/src/jit-test/tests/stream/bug-1503406.js b/js/src/jit-test/tests/stream/bug-1503406.js new file mode 100644 index 0000000000..4c598d6b43 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1503406.js @@ -0,0 +1,13 @@ +let g = newGlobal(); +let reader = g.eval(` + let stream = new ReadableStream({ + start(controller) { + controller.enqueue([]); + }, + }); + let [b1, b2] = stream.tee(); + b1.getReader(); +`); +let read = new ReadableStream({}).getReader().read; +drainJobQueue(); // let the stream be started before reading +read.call(reader); diff --git a/js/src/jit-test/tests/stream/bug-1512008.js b/js/src/jit-test/tests/stream/bug-1512008.js new file mode 100644 index 0000000000..9634123bc0 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1512008.js @@ -0,0 +1,8 @@ +ignoreUnhandledRejections(); + +Object.defineProperty(Promise, Symbol.species, { + value: function(g) { + g(function() {}, function() {}) + } +}); +new ReadableStream().tee(); diff --git a/js/src/jit-test/tests/stream/bug-1513266.js b/js/src/jit-test/tests/stream/bug-1513266.js new file mode 100644 index 0000000000..f6a2df01f2 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1513266.js @@ -0,0 +1,16 @@ +// |jit-test| --no-ion; --no-baseline; skip-if: !('oomTest' in this) + +ignoreUnhandledRejections(); + +function test() { + let controller; + let stream = new ReadableStream({ + start(c) {} + }); + stream.getReader(); + drainJobQueue(); +} + +// Force lazy parsing to happen before oomTest starts (see `help(oomTest)`). +test(); +oomTest(test, {verbose: true, keepFailing: false}); diff --git a/js/src/jit-test/tests/stream/bug-1515816.js b/js/src/jit-test/tests/stream/bug-1515816.js new file mode 100644 index 0000000000..ccc1b70d10 --- /dev/null +++ b/js/src/jit-test/tests/stream/bug-1515816.js @@ -0,0 +1,17 @@ +// |jit-test| --no-ion; --no-baseline; --no-blinterp; skip-if: !('oomAfterAllocations' in this) +// Don't crash on OOM in ReadableStreamDefaultReader.prototype.read(). + +for (let n = 1; n < 1000; n++) { + let stream = new ReadableStream({ + start(controller) { + controller.enqueue(7); + } + }); + let reader = stream.getReader(); + oomAfterAllocations(n); + try { + reader.read(); + n = 1000; + } catch {} + resetOOMFailure(); +} diff --git a/js/src/jit-test/tests/stream/proper-realm-cancel.js b/js/src/jit-test/tests/stream/proper-realm-cancel.js new file mode 100644 index 0000000000..43c9555980 --- /dev/null +++ b/js/src/jit-test/tests/stream/proper-realm-cancel.js @@ -0,0 +1,6 @@ +ignoreUnhandledRejections(); + +var g = newGlobal({ newCompartment: true }); +var ccwCancelMethod = new g.Function("return 17;"); + +new ReadableStream({ cancel: ccwCancelMethod }).cancel("bye"); diff --git a/js/src/jit-test/tests/stream/proper-realm-pull.js b/js/src/jit-test/tests/stream/proper-realm-pull.js new file mode 100644 index 0000000000..d376e15436 --- /dev/null +++ b/js/src/jit-test/tests/stream/proper-realm-pull.js @@ -0,0 +1,6 @@ +ignoreUnhandledRejections(); + +var g = newGlobal({ newCompartment: true }); +var ccwPullMethod = new g.Function("return 17;"); + +new ReadableStream({ pull: ccwPullMethod }); diff --git a/js/src/jit-test/tests/stream/reader-closedPromise-handled-2.js b/js/src/jit-test/tests/stream/reader-closedPromise-handled-2.js new file mode 100644 index 0000000000..73c7c492f4 --- /dev/null +++ b/js/src/jit-test/tests/stream/reader-closedPromise-handled-2.js @@ -0,0 +1,33 @@ +// Releasing a reader should not result in a promise being tracked as +// unhandled. + +function test(readable) { + // Create an errored stream. + let controller; + let stream = new ReadableStream({ + start(c) { + controller = c; + } + }); + drainJobQueue(); + + // Track promises. + let status = new Map; + setPromiseRejectionTrackerCallback((p, x) => { status.set(p, x); }); + + // Per Streams spec 3.7.5 step 5, this creates a rejected promise + // (reader.closed) but marks it as handled. + let reader = stream.getReader(); + if (!readable) { + controller.close(); + } + reader.releaseLock(); + + // Check that the promise's status is not 0 (unhandled); + // it may be either 1 (handled) or undefined (never tracked). + let result = status.get(reader.closed); + assertEq(result === 1 || result === undefined, true); +} + +test(true); +test(false); diff --git a/js/src/jit-test/tests/stream/reader-closedPromise-handled.js b/js/src/jit-test/tests/stream/reader-closedPromise-handled.js new file mode 100644 index 0000000000..a3ebdfe22e --- /dev/null +++ b/js/src/jit-test/tests/stream/reader-closedPromise-handled.js @@ -0,0 +1,23 @@ +// Creating a reader from an errored stream should not result in a promise +// being tracked as unhandled. + +// Create an errored stream. +let stream = new ReadableStream({ + start(controller) { + controller.error(new Error("splines insufficiently reticulated")); + } +}); +drainJobQueue(); + +// Track promises. +let status = new Map; +setPromiseRejectionTrackerCallback((p, x) => { status.set(p, x); }); + +// Per Streams spec 3.7.4 step 5.c, this creates a rejected promise +// (reader.closed) but marks it as handled. +let reader = stream.getReader(); + +// Check that the promise's status is not 0 (unhandled); +// it may be either 1 (handled) or undefined (never tracked). +let result = status.get(reader.closed); +assertEq(result === 1 || result === undefined, true); |