From 6708e2a3028b6b8810539a88554df799e2108008 Mon Sep 17 00:00:00 2001 From: Steve Kinney Date: Sat, 7 May 2016 08:52:52 -0600 Subject: [PATCH 1/3] :lipstick: Cache last argument in parseArgs This is to eliminate the need to access the array twice. --- lib/browser/api/dialog.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index 6669d8cab8..3410618027 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -35,8 +35,9 @@ var parseArgs = function (window, options, callback, ...args) { } // Fallback to using very last argument as the callback function - if ((callback == null) && typeof args[args.length - 1] === 'function') { - callback = args[args.length - 1] + var lastArgument = args[args.length - 1] + if ((callback == null) && typeof lastArgument === 'function') { + callback = lastArgument } return [window, options, callback] From f3e633eb2c8187e2fe346882794f38dcd692525d Mon Sep 17 00:00:00 2001 From: Steve Kinney Date: Sat, 7 May 2016 08:55:26 -0600 Subject: [PATCH 2/3] :lipstick: Use destructuring to shift arguments --- lib/browser/api/dialog.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index 3410618027..9b43b7b936 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -23,15 +23,12 @@ var messageBoxOptions = { var parseArgs = function (window, options, callback, ...args) { if (!(window === null || (window != null ? window.constructor : void 0) === BrowserWindow)) { // Shift. - callback = options - options = window - window = null + [callback, options, window] = [options, window, null] } if ((callback == null) && typeof options === 'function') { // Shift. - callback = options - options = null + [callback, options] = [options, null] } // Fallback to using very last argument as the callback function From 91220f2a98ec6b2a441b18786262372c9fba91bd Mon Sep 17 00:00:00 2001 From: Steve Kinney Date: Sat, 7 May 2016 09:13:40 -0600 Subject: [PATCH 3/3] :lipstick: Simplify conditional check for BrowserWindow --- lib/browser/api/dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/dialog.js b/lib/browser/api/dialog.js index 9b43b7b936..a41d1fa46e 100644 --- a/lib/browser/api/dialog.js +++ b/lib/browser/api/dialog.js @@ -21,7 +21,7 @@ var messageBoxOptions = { } var parseArgs = function (window, options, callback, ...args) { - if (!(window === null || (window != null ? window.constructor : void 0) === BrowserWindow)) { + if (window !== null && window.constructor !== BrowserWindow) { // Shift. [callback, options, window] = [options, window, null] }