summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
authorJordan Harband <ljharb@gmail.com>2023-01-09 21:38:36 -0800
committerGitHub <noreply@github.com>2023-01-10 05:38:36 +0000
commit757c10414776b6f035ced453599527a841f47d6e (patch)
tree8d51c5c789eb6832ab71a5cde64813c71a4f8879 /lib/events.js
parent5d9a9a6ba323916a978e737e6cee73c6df956afa (diff)
downloadnode-new-757c10414776b6f035ced453599527a841f47d6e.tar.gz
tools: add `prefer-proto` rule
fixup: add support for `Object.create(null)` fixup: extend to any 1-argument Object.create call fixup: add tests PR-URL: https://github.com/nodejs/node/pull/46083 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/events.js b/lib/events.js
index efce9b9c22..3f3e3d295c 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -35,7 +35,6 @@ const {
FunctionPrototypeCall,
NumberIsNaN,
NumberMAX_SAFE_INTEGER,
- ObjectCreate,
ObjectDefineProperty,
ObjectDefineProperties,
ObjectGetPrototypeOf,
@@ -344,7 +343,7 @@ EventEmitter.init = function(opts) {
if (this._events === undefined ||
this._events === ObjectGetPrototypeOf(this)._events) {
- this._events = ObjectCreate(null);
+ this._events = { __proto__: null };
this._eventsCount = 0;
}
@@ -553,7 +552,7 @@ function _addListener(target, type, listener, prepend) {
events = target._events;
if (events === undefined) {
- events = target._events = ObjectCreate(null);
+ events = target._events = { __proto__: null };
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
@@ -691,7 +690,7 @@ EventEmitter.prototype.removeListener =
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
- this._events = ObjectCreate(null);
+ this._events = { __proto__: null };
else {
delete events[type];
if (events.removeListener)
@@ -746,11 +745,11 @@ EventEmitter.prototype.removeAllListeners =
// Not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
- this._events = ObjectCreate(null);
+ this._events = { __proto__: null };
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
- this._events = ObjectCreate(null);
+ this._events = { __proto__: null };
else
delete events[type];
}
@@ -764,7 +763,7 @@ EventEmitter.prototype.removeAllListeners =
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
- this._events = ObjectCreate(null);
+ this._events = { __proto__: null };
this._eventsCount = 0;
return this;
}