From a837f95b77e07a754b331a884778a9eb0b3350be Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Wed, 26 Oct 2016 22:35:53 -0400 Subject: [PATCH 1/2] Fix callbacks sometimes getting array of arguments Closes #133 --- node-phantom-simple.js | 12 +----------- test/test_page_push_notifications.js | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/node-phantom-simple.js b/node-phantom-simple.js index 24d0ab6..4d84961 100644 --- a/node-phantom-simple.js +++ b/node-phantom-simple.js @@ -65,10 +65,6 @@ function callbackOrDummy(callback, poll_func) { return callback; } -function unwrapArray(arr) { - return arr && arr.length === 1 ? arr[0] : arr; -} - function wrapArray(arr) { // Ensure that arr is an Array return (arr instanceof Array) ? arr : [ arr ]; @@ -628,13 +624,7 @@ function setup_long_poll(phantom, port, pages, setup_new_page) { } else if (pages[r.page_id] && pages[r.page_id][r.callback]) { callbackFunc = pages[r.page_id][r.callback]; - if (callbackFunc.length > 1) { - // We use `apply` if the function is expecting multiple args - callbackFunc.apply(pages[r.page_id], wrapArray(r.args)); - } else { - // Old `call` behaviour is deprecated - callbackFunc.call(pages[r.page_id], unwrapArray(r.args)); - } + callbackFunc.apply(pages[r.page_id], wrapArray(r.args)); } } else { cb = callbackOrDummy(phantom[r.callback]); diff --git a/test/test_page_push_notifications.js b/test/test_page_push_notifications.js index 58d0416..c210f21 100644 --- a/test/test_page_push_notifications.js +++ b/test/test_page_push_notifications.js @@ -209,7 +209,7 @@ describe('push notifications', function () { return; } - page.onLoadFinished = function () { + page.onLoadFinished = function (status) { browser.exit(done); }; @@ -219,7 +219,7 @@ describe('push notifications', function () { return; } - assert.equal(status, 'success'); + assert.strictEqual(status, 'success'); }); }); }); From 8f4f24081612e2f527dba8181972c130d74d5380 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Wed, 26 Oct 2016 22:41:22 -0400 Subject: [PATCH 2/2] Remove lint --- test/test_page_push_notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_page_push_notifications.js b/test/test_page_push_notifications.js index c210f21..d16bc70 100644 --- a/test/test_page_push_notifications.js +++ b/test/test_page_push_notifications.js @@ -209,7 +209,7 @@ describe('push notifications', function () { return; } - page.onLoadFinished = function (status) { + page.onLoadFinished = function () { browser.exit(done); };