Remove useless wrapReason calls in the MessageHandler class

Currently `wrapReason` is manually called at *every* `resolveOrReject` call-site, despite it being completely unnecessary unless there's an actual error being handled. This is obviously inefficient, and it's easy enough to avoid by having `resolveOrReject` handle this only when actually needed.
This commit is contained in:
Jonas Jenwald 2019-07-13 13:08:29 +02:00
parent 421bf62849
commit 17116917f7

View File

@ -52,11 +52,11 @@ function makeReasonSerializable(reason) {
return new UnknownErrorException(reason.message, reason.toString());
}
function resolveOrReject(capability, success, reason) {
if (success) {
function resolveOrReject(capability, data) {
if (data.success) {
capability.resolve();
} else {
capability.reject(reason);
capability.reject(wrapReason(data.reason));
}
}
@ -341,12 +341,10 @@ MessageHandler.prototype = {
switch (data.stream) {
case 'start_complete':
resolveOrReject(this.streamControllers[data.streamId].startCall,
data.success, wrapReason(data.reason));
resolveOrReject(this.streamControllers[data.streamId].startCall, data);
break;
case 'pull_complete':
resolveOrReject(this.streamControllers[data.streamId].pullCall,
data.success, wrapReason(data.reason));
resolveOrReject(this.streamControllers[data.streamId].pullCall, data);
break;
case 'pull':
// Ignore any pull after close is called.
@ -395,8 +393,7 @@ MessageHandler.prototype = {
deleteStreamController();
break;
case 'cancel_complete':
resolveOrReject(this.streamControllers[data.streamId].cancelCall,
data.success, wrapReason(data.reason));
resolveOrReject(this.streamControllers[data.streamId].cancelCall, data);
deleteStreamController();
break;
case 'cancel':