Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: small nextTick cleanup, including removing manual args copying #19153

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions lib/internal/process/next_tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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));
Expand Down