Skip to content
Closed
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
Next Next commit
move cache assignment to toPrimitive call
  • Loading branch information
bmeck committed Mar 29, 2018
commit 6101d5283ad9e565c87a365140fa4823825d0e91
5 changes: 3 additions & 2 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ const KNOWN_TIMERS = Object.create(null);
// Schedule or re-schedule a timer.
// The item must have been enroll()'d first.
const active = exports.active = function(item) {
KNOWN_TIMERS[item[async_id_symbol]] = item;
insert(item, false);
};

Expand Down Expand Up @@ -537,7 +536,9 @@ function unrefdHandle(timer, now) {
}

Timeout.prototype[Symbol.toPrimitive] = function() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why @@toPrimitive rather than valueOf?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see https://codepen.io/bradleymeck/pen/eMMpdR?editors=0012 , .valueOf is not safe for using as a key. toPrimitive handles both string and number coercion.

return this[async_id_symbol];
const id = this[async_id_symbol];
KNOWN_TIMERS[id] = this;
return id;
};

Timeout.prototype.unref = function() {
Expand Down