Skip to content

Commit

Permalink
events: use property, primordials
Browse files Browse the repository at this point in the history
PR-URL: #33775
Fixes: #33773
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
benjamingr authored and codebytere committed Jun 22, 2020
1 parent 1791d57 commit eb01214
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
Set,
Symbol,
NumberIsNaN,
SymbolToStringTag,
} = primordials;

const {
Expand Down Expand Up @@ -67,7 +68,6 @@ class Event {
// isTrusted is special (LegacyUnforgeable)
Object.defineProperty(this, 'isTrusted', {
get() { return false; },
set(ignoredValue) { return false; },
enumerable: true,
configurable: false
});
Expand Down Expand Up @@ -132,10 +132,15 @@ class Event {
stopPropagation() {
this.#propagationStopped = true;
}

get [Symbol.toStringTag]() { return 'Event'; }
}

Object.defineProperty(Event.prototype, SymbolToStringTag, {
writable: false,
enumerable: false,
configurable: true,
value: 'Event',
});

// The listeners for an EventTarget are maintained as a linked list.
// Unfortunately, the way EventTarget is defined, listeners are accounted
// using the tuple [handler,capture], and even if we don't actually make
Expand Down Expand Up @@ -305,14 +310,19 @@ class EventTarget {

return `${name} ${inspect({}, opts)}`;
}
get [Symbol.toStringTag]() { return 'EventTarget'; }
}

Object.defineProperties(EventTarget.prototype, {
addEventListener: { enumerable: true },
removeEventListener: { enumerable: true },
dispatchEvent: { enumerable: true }
});
Object.defineProperty(EventTarget.prototype, SymbolToStringTag, {
writable: false,
enumerable: false,
configurable: true,
value: 'EventTarget',
});

class NodeEventTarget extends EventTarget {
static defaultMaxListeners = 10;
Expand Down

0 comments on commit eb01214

Please sign in to comment.