Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28edc1d

Browse filesBrowse files
apapirovskiMylesBorins
authored andcommitted
events: use Reflect.apply
Instead of callback bound apply, instead use the standard Reflect.apply. This is both safer and appears to offer a slight performance benefit. Backport-PR-URL: #18487 PR-URL: #17456 Refs: #12956 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 3ae5cf2 commit 28edc1d
Copy full SHA for 28edc1d

File tree

Expand file treeCollapse file tree

2 files changed

+5
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-5
lines changed
Open diff view settings
Collapse file

‎lib/domain.js‎

Copy file name to clipboardExpand all lines: lib/domain.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ const eventEmit = EventEmitter.prototype.emit;
400400
EventEmitter.prototype.emit = function emit(...args) {
401401
const domain = this.domain;
402402
if (domain === null || domain === undefined || this === process) {
403-
return eventEmit.apply(this, args);
403+
return Reflect.apply(eventEmit, this, args);
404404
}
405405

406406
const type = args[0];
@@ -415,7 +415,7 @@ EventEmitter.prototype.emit = function emit(...args) {
415415

416416
domain.enter();
417417
try {
418-
return eventEmit.apply(this, args);
418+
return Reflect.apply(eventEmit, this, args);
419419
} catch (er) {
420420
if (typeof er === 'object' && er !== null) {
421421
er.domainEmitter = this;
Collapse file

‎lib/events.js‎

Copy file name to clipboardExpand all lines: lib/events.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
124124
return false;
125125

126126
if (typeof handler === 'function') {
127-
handler.apply(this, args);
127+
Reflect.apply(handler, this, args);
128128
} else {
129129
const len = handler.length;
130130
const listeners = arrayClone(handler, len);
131131
for (var i = 0; i < len; ++i)
132-
listeners[i].apply(this, args);
132+
Reflect.apply(listeners[i], this, args);
133133
}
134134

135135
return true;
@@ -216,7 +216,7 @@ function onceWrapper(...args) {
216216
if (!this.fired) {
217217
this.target.removeListener(this.type, this.wrapFn);
218218
this.fired = true;
219-
this.listener.apply(this.target, args);
219+
Reflect.apply(this.listener, this.target, args);
220220
}
221221
}
222222

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.