diff --git a/lib/internal/process/next_tick.js b/lib/internal/process/next_tick.js index f95d9cc1b82ebf..242c61dea3aab2 100644 --- a/lib/internal/process/next_tick.js +++ b/lib/internal/process/next_tick.js @@ -123,11 +123,8 @@ function setupNextTick() { class TickObject { constructor(callback, args, triggerAsyncId) { - // this must be set to null first to avoid function tracking - // on the hidden class, revisit in V8 versions after 6.2 - this.callback = null; this.callback = callback; - this.args = args; + this.args = args.length > 0 ? args : undefined; const asyncId = newAsyncId(); this[async_id_symbol] = asyncId; @@ -144,31 +141,19 @@ function setupNextTick() { // `nextTick()` will not enqueue any callback when the process is about to // exit since the callback would not have a chance to be executed. - function nextTick(callback) { + function nextTick(callback, ...args) { if (typeof callback !== 'function') throw new errors.TypeError('ERR_INVALID_CALLBACK'); if (process._exiting) return; - var args; - switch (arguments.length) { - case 1: break; - case 2: args = [arguments[1]]; break; - case 3: args = [arguments[1], arguments[2]]; break; - case 4: args = [arguments[1], arguments[2], arguments[3]]; break; - default: - args = new Array(arguments.length - 1); - for (var i = 1; i < arguments.length; i++) - args[i - 1] = arguments[i]; - } - push(new TickObject(callback, args, getDefaultTriggerAsyncId())); } // `internalNextTick()` will not enqueue any callback when the process is // about to exit since the callback would not have a chance to be executed. - function internalNextTick(triggerAsyncId, callback) { + function internalNextTick(triggerAsyncId, callback, ...args) { if (typeof callback !== 'function') throw new errors.TypeError('ERR_INVALID_CALLBACK'); // CHECK(Number.isSafeInteger(triggerAsyncId) || triggerAsyncId === null) @@ -177,18 +162,6 @@ function setupNextTick() { if (process._exiting) return; - var args; - switch (arguments.length) { - case 2: break; - case 3: args = [arguments[2]]; break; - case 4: args = [arguments[2], arguments[3]]; break; - case 5: args = [arguments[2], arguments[3], arguments[4]]; break; - default: - args = new Array(arguments.length - 2); - for (var i = 2; i < arguments.length; i++) - args[i - 2] = arguments[i]; - } - if (triggerAsyncId === null) triggerAsyncId = getDefaultTriggerAsyncId(); push(new TickObject(callback, args, triggerAsyncId));