Ensure that Errors are handled correctly when using postMessage with Streams in MessageHandler

Having recently worked with this code, it struck me that most of the `postMessage` calls where `Error`s are involved have never been correctly implemented (i.e. missing `wrapReason` calls).
This commit is contained in:
Jonas Jenwald 2019-09-02 13:18:39 +02:00
parent e59b11860d
commit 02bdacef42
2 changed files with 11 additions and 9 deletions

View File

@ -231,7 +231,7 @@ MessageHandler.prototype = {
targetName,
stream: StreamKind.CANCEL,
streamId,
reason,
reason: wrapReason(reason),
});
// Return Promise to signal success or failure.
return cancelCapability.promise;
@ -296,7 +296,7 @@ MessageHandler.prototype = {
targetName,
stream: StreamKind.ERROR,
streamId,
reason,
reason: wrapReason(reason),
});
},
@ -327,7 +327,7 @@ MessageHandler.prototype = {
targetName,
stream: StreamKind.START_COMPLETE,
streamId,
reason,
reason: wrapReason(reason),
});
});
},
@ -397,7 +397,7 @@ MessageHandler.prototype = {
targetName,
stream: StreamKind.PULL_COMPLETE,
streamId,
reason,
reason: wrapReason(reason),
});
});
break;
@ -450,7 +450,7 @@ MessageHandler.prototype = {
targetName,
stream: StreamKind.CANCEL_COMPLETE,
streamId,
reason,
reason: wrapReason(reason),
});
});
this.streamSinks[data.streamId].sinkCapability.

View File

@ -142,11 +142,13 @@ describe('message_handler', function () {
sink.onCancel = function (reason) {
log += 'c';
};
log += '0';
sink.ready.then(() => {
log += '1';
sink.enqueue([1, 2, 3, 4], 4);
return sink.ready;
}).then(() => {
log += 'error';
log += 'e';
sink.error('error');
});
});
@ -161,14 +163,14 @@ describe('message_handler', function () {
let reader = readable.getReader();
sleep(10).then(() => {
expect(log).toEqual('');
expect(log).toEqual('01');
return reader.read();
}).then((result) => {
expect(result.value).toEqual([1, 2, 3, 4]);
expect(result.done).toEqual(false);
return reader.read();
}).then(() => {
}, (reason) => {
}).catch((reason) => {
expect(log).toEqual('01pe');
expect(reason).toEqual('error');
done();
});