From a3ae3cab799dc9bd25509f01b26b0a5d20468a96 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 13 Jul 2015 14:57:17 -0700 Subject: [PATCH] Use Promise.reject for simplicity The following are equivalent, except that the first is longer and invokes an extra function call. ``` return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); return Promise.reject(new Error("Unknown Group")); ``` --- js/libtextsecure.js | 12 ++++++------ libtextsecure/sendmessage.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index bbf65db7..a701f75d 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -40074,7 +40074,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); var promises = []; for (var i in attachments) @@ -40123,7 +40123,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.addNumbers(groupId, numbers).then(function(numbers) { if (numbers === undefined) { - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); } proto.group.members = numbers; @@ -40150,7 +40150,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.addNumbers(groupId, [number]).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return sendGroupProto(numbers, proto); @@ -40166,7 +40166,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return sendGroupProto(numbers, proto); @@ -40181,7 +40181,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return makeAttachmentPointer(avatar).then(function(attachment) { @@ -40199,7 +40199,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); return textsecure.storage.groups.deleteGroup(groupId).then(function() { return sendGroupProto(numbers, proto); }); diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 489a5cba..2459a983 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -379,7 +379,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); var promises = []; for (var i in attachments) @@ -428,7 +428,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.addNumbers(groupId, numbers).then(function(numbers) { if (numbers === undefined) { - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); } proto.group.members = numbers; @@ -455,7 +455,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.addNumbers(groupId, [number]).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return sendGroupProto(numbers, proto); @@ -471,7 +471,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return sendGroupProto(numbers, proto); @@ -486,7 +486,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); proto.group.members = numbers; return makeAttachmentPointer(avatar).then(function(attachment) { @@ -504,7 +504,7 @@ window.textsecure.messaging = function() { return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) { if (numbers === undefined) - return new Promise(function(resolve, reject) { reject(new Error("Unknown Group")); }); + return Promise.reject(new Error("Unknown Group")); return textsecure.storage.groups.deleteGroup(groupId).then(function() { return sendGroupProto(numbers, proto); });