From 6a40cde1d8b20d1862f2fc01a880ad552f617771 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Wed, 17 Dec 2014 21:56:30 -0500 Subject: [PATCH] try our best to prevent deopt --- lib/backburner.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/backburner.js b/lib/backburner.js index 64668f9e..59ee566d 100644 --- a/lib/backburner.js +++ b/lib/backburner.js @@ -119,18 +119,34 @@ Backburner.prototype = { } }, - join: function(target, method /*, args */) { + join: function(/* target, method , args */) { + var method, target; + if (this.currentInstance) { - if (!method) { - method = target; + var length = arguments.length; + if (length === 1) { + method = arguments[0]; target = null; + } else { + target = arguments[0]; + method = arguments[1]; } if (isString(method)) { method = target[method]; } - return method.apply(target, slice.call(arguments, 2)); + if (length === 1) { + return method(); + } else if (length === 2) { + return method.call(target); + } else { + var args = new Array(length - 2); + for (var i =0, l = length - 2; i < l; i++) { + args[i] = arguments[i + 2]; + } + return method.apply(target, args); + } } else { return this.run.apply(this, arguments); }