mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +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",
|
{ value: "TransformStreamDefaultController",
|
||||||
configurable: true });
|
configurable: true });
|
||||||
|
|
||||||
|
function errorReadableController(controller, error) {
|
||||||
|
try {
|
||||||
|
controller.error(error);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
function TransformStream(transformer, writableStrategy, readableStrategy) {
|
function TransformStream(transformer, writableStrategy, readableStrategy) {
|
||||||
if (!(this instanceof TransformStream))
|
if (!(this instanceof TransformStream))
|
||||||
throw new TypeError("TransformStream must be constructed with new");
|
throw new TypeError("TransformStream must be constructed with new");
|
||||||
|
|
@ -6421,16 +6427,33 @@ js::InitStreamExtras(JSContext* cx, HandleObject global)
|
||||||
var startPromise = startAlgorithm
|
var startPromise = startAlgorithm
|
||||||
? promiseCall(startAlgorithm, transformer, [controller])
|
? promiseCall(startAlgorithm, transformer, [controller])
|
||||||
: Promise.resolve(undefined);
|
: Promise.resolve(undefined);
|
||||||
|
startPromise = startPromise.then(undefined, function(error) {
|
||||||
|
if (readableController)
|
||||||
|
errorReadableController(readableController, error);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
var writable = new WritableStream({
|
var writable = new WritableStream({
|
||||||
start: function() {
|
start: function() {
|
||||||
return startPromise;
|
return startPromise;
|
||||||
},
|
},
|
||||||
write: function(chunk) {
|
write: function(chunk) {
|
||||||
if (transformAlgorithm)
|
var result;
|
||||||
return transformAlgorithm.call(transformer, chunk, controller);
|
try {
|
||||||
|
if (transformAlgorithm) {
|
||||||
|
result = transformAlgorithm.call(transformer, chunk, controller);
|
||||||
|
} else {
|
||||||
controller.enqueue(chunk);
|
controller.enqueue(chunk);
|
||||||
return undefined;
|
result = undefined;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
errorReadableController(readableController, error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
return Promise.resolve(result).then(undefined, function(error) {
|
||||||
|
errorReadableController(readableController, error);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
var result = flushAlgorithm
|
var result = flushAlgorithm
|
||||||
|
|
@ -6438,6 +6461,9 @@ js::InitStreamExtras(JSContext* cx, HandleObject global)
|
||||||
: Promise.resolve(undefined);
|
: Promise.resolve(undefined);
|
||||||
return result.then(function() {
|
return result.then(function() {
|
||||||
readableController.close();
|
readableController.close();
|
||||||
|
}, function(error) {
|
||||||
|
errorReadableController(readableController, error);
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
abort: function(reason) {
|
abort: function(reason) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue