Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixup! lib,src: standardize owner_symbol for handles
  • Loading branch information
addaleax committed Aug 24, 2018
commit cba837442c3f5c0ce87b6c578e8145630f8f75f3
18 changes: 13 additions & 5 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const {
// The needed emit*() functions.
emitBefore,
emitAfter,
emitDestroy
emitDestroy,
symbols: { owner_symbol }
} = require('internal/async_hooks');

// *Must* match Environment::ImmediateInfo::Fields in src/env.h.
Expand Down Expand Up @@ -206,8 +207,8 @@ function TimersList(msecs, unrefed) {
}

function processTimers(now) {
if (this.owner)
return unrefdHandle(this.owner, now);
if (this[owner_symbol])
return unrefdHandle(this[owner_symbol], now);
return listOnTimeout(this, now);
}

Expand Down Expand Up @@ -268,7 +269,7 @@ function listOnTimeout(handle, now) {

// Do not close the underlying handle if its ownership has changed
// (e.g it was unrefed in its callback).
if (!handle.owner)
if (!handle[owner_symbol])
handle.close();

return true;
Expand Down Expand Up @@ -540,7 +541,7 @@ Timeout.prototype.unref = function() {
}

this._handle = handle || new TimerWrap();
this._handle.owner = this;
this._handle[owner_symbol] = this;
this._handle.start(delay);
this._handle.unref();
}
Expand Down Expand Up @@ -788,3 +789,10 @@ exports.clearImmediate = function clearImmediate(immediate) {

immediateQueue.remove(immediate);
};

// Legacy alias on the C++ wrapper object. This is not public API, so we may
// want to runtime-deprecate it at some point. There's no hurry, though.
Object.defineProperty(TimerWrap.prototype, 'owner', {
get() { return this[owner_symbol]; },
set(v) { return this[owner_symbol] = v; }
});
2 changes: 1 addition & 1 deletion src/timer_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class TimerWrap : public HandleWrap {
!env->tick_info()->has_thrown() &&
env->can_call_into_js() &&
wrap->object()->Get(env->context(),
env->owner_string()).ToLocalChecked()
env->owner_symbol()).ToLocalChecked()
->IsUndefined());
}

Expand Down