mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +09:00
Propagate transform stream errors
This commit is contained in:
parent
936a862591
commit
7ed26747c2
1 changed files with 30 additions and 4 deletions
|
|
@ -6382,6 +6382,12 @@ js::InitStreamExtras(JSContext* cx, HandleObject global)
|
|||
{ value: "TransformStreamDefaultController",
|
||||
configurable: true });
|
||||
|
||||
function errorReadableController(controller, error) {
|
||||
try {
|
||||
controller.error(error);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function TransformStream(transformer, writableStrategy, readableStrategy) {
|
||||
if (!(this instanceof TransformStream))
|
||||
throw new TypeError("TransformStream must be constructed with new");
|
||||
|
|
@ -6421,16 +6427,33 @@ js::InitStreamExtras(JSContext* cx, HandleObject global)
|
|||
var startPromise = startAlgorithm
|
||||
? promiseCall(startAlgorithm, transformer, [controller])
|
||||
: Promise.resolve(undefined);
|
||||
startPromise = startPromise.then(undefined, function(error) {
|
||||
if (readableController)
|
||||
errorReadableController(readableController, error);
|
||||
throw error;
|
||||
});
|
||||
|
||||
var writable = new WritableStream({
|
||||
start: function() {
|
||||
return startPromise;
|
||||
},
|
||||
write: function(chunk) {
|
||||
if (transformAlgorithm)
|
||||
return transformAlgorithm.call(transformer, chunk, controller);
|
||||
controller.enqueue(chunk);
|
||||
return undefined;
|
||||
var result;
|
||||
try {
|
||||
if (transformAlgorithm) {
|
||||
result = transformAlgorithm.call(transformer, chunk, controller);
|
||||
} else {
|
||||
controller.enqueue(chunk);
|
||||
result = undefined;
|
||||
}
|
||||
} catch (error) {
|
||||
errorReadableController(readableController, error);
|
||||
throw error;
|
||||
}
|
||||
return Promise.resolve(result).then(undefined, function(error) {
|
||||
errorReadableController(readableController, error);
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
close: function() {
|
||||
var result = flushAlgorithm
|
||||
|
|
@ -6438,6 +6461,9 @@ js::InitStreamExtras(JSContext* cx, HandleObject global)
|
|||
: Promise.resolve(undefined);
|
||||
return result.then(function() {
|
||||
readableController.close();
|
||||
}, function(error) {
|
||||
errorReadableController(readableController, error);
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
abort: function(reason) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue