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

timers: cleanup extraneous property on Immediates #16355

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
25 changes: 11 additions & 14 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,6 @@ function processImmediate() {
if (domain)
domain.enter();

immediate._callback = immediate._onImmediate;

// Save next in case `clearImmediate(immediate)` is called from callback
var next = immediate._idleNext;

Expand Down Expand Up @@ -764,8 +762,8 @@ function tryOnImmediate(immediate, oldTail) {
runCallback(immediate);
threw = false;
} finally {
// clearImmediate checks _callback === null for kDestroy hooks.
immediate._callback = null;
// clearImmediate checks _onImmediate === null for kDestroy hooks.
immediate._onImmediate = null;
if (!threw)
emitAfter(immediate[async_id_symbol]);
if (async_hook_fields[kDestroy] > 0 && !immediate._destroyed) {
Expand Down Expand Up @@ -794,21 +792,21 @@ function tryOnImmediate(immediate, oldTail) {
function runCallback(timer) {
const argv = timer._argv;
const argc = argv ? argv.length : 0;
if (typeof timer._callback !== 'function')
return promiseResolve(timer._callback, argv[0]);
if (typeof timer._onImmediate !== 'function')
return promiseResolve(timer._onImmediate, argv[0]);
switch (argc) {
// fast-path callbacks with 0-3 arguments
case 0:
return timer._callback();
return timer._onImmediate();
case 1:
return timer._callback(argv[0]);
return timer._onImmediate(argv[0]);
case 2:
return timer._callback(argv[0], argv[1]);
return timer._onImmediate(argv[0], argv[1]);
case 3:
return timer._callback(argv[0], argv[1], argv[2]);
return timer._onImmediate(argv[0], argv[1], argv[2]);
// more than 3 arguments run slower with .apply
default:
return Function.prototype.apply.call(timer._callback, timer, argv);
return Function.prototype.apply.call(timer._onImmediate, timer, argv);
}
}

Expand All @@ -818,7 +816,7 @@ function Immediate() {
// so have caller annotate the object (node v6.0.0, v8 5.0.71.35)
this._idleNext = null;
this._idlePrev = null;
this._callback = null;
this._onImmediate = null;
this._argv = null;
this._onImmediate = null;
this._destroyed = false;
Expand Down Expand Up @@ -869,7 +867,6 @@ exports.setImmediate = setImmediate;
function createImmediate(args, callback) {
// declaring it `const immediate` causes v6.0.0 to deoptimize this function
var immediate = new Immediate();
immediate._callback = callback;
immediate._argv = args;
immediate._onImmediate = callback;

Expand All @@ -888,7 +885,7 @@ exports.clearImmediate = function(immediate) {
if (!immediate) return;

if (async_hook_fields[kDestroy] > 0 &&
immediate._callback !== null &&
immediate._onImmediate !== null &&
!immediate._destroyed) {
emitDestroy(immediate[async_id_symbol]);
immediate._destroyed = true;
Expand Down
2 changes: 1 addition & 1 deletion test/message/unhandled_promise_trace_warnings.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
at rejectionHandled (internal/process/promises.js:*)
at *
at Promise.catch *
at Immediate.setImmediate [as _onImmediate] (*test*message*unhandled_promise_trace_warnings.js:*)
at Immediate.setImmediate (*test*message*unhandled_promise_trace_warnings.js:*)
at *
at *
at *