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. PR-URL: https://github.com/nodejs/node/pull/17456 Refs: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
694e7baf00
commit
f5eb803c8d
@ -400,7 +400,7 @@ const eventEmit = EventEmitter.prototype.emit;
|
|||||||
EventEmitter.prototype.emit = function emit(...args) {
|
EventEmitter.prototype.emit = function emit(...args) {
|
||||||
const domain = this.domain;
|
const domain = this.domain;
|
||||||
if (domain === null || domain === undefined || this === process) {
|
if (domain === null || domain === undefined || this === process) {
|
||||||
return eventEmit.apply(this, args);
|
return Reflect.apply(eventEmit, this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = args[0];
|
const type = args[0];
|
||||||
@ -415,7 +415,7 @@ EventEmitter.prototype.emit = function emit(...args) {
|
|||||||
|
|
||||||
domain.enter();
|
domain.enter();
|
||||||
try {
|
try {
|
||||||
return eventEmit.apply(this, args);
|
return Reflect.apply(eventEmit, this, args);
|
||||||
} catch (er) {
|
} catch (er) {
|
||||||
if (typeof er === 'object' && er !== null) {
|
if (typeof er === 'object' && er !== null) {
|
||||||
er.domainEmitter = this;
|
er.domainEmitter = this;
|
||||||
|
@ -123,12 +123,12 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (typeof handler === 'function') {
|
if (typeof handler === 'function') {
|
||||||
handler.apply(this, args);
|
Reflect.apply(handler, this, args);
|
||||||
} else {
|
} else {
|
||||||
const len = handler.length;
|
const len = handler.length;
|
||||||
const listeners = arrayClone(handler, len);
|
const listeners = arrayClone(handler, len);
|
||||||
for (var i = 0; i < len; ++i)
|
for (var i = 0; i < len; ++i)
|
||||||
listeners[i].apply(this, args);
|
Reflect.apply(listeners[i], this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -215,7 +215,7 @@ function onceWrapper(...args) {
|
|||||||
if (!this.fired) {
|
if (!this.fired) {
|
||||||
this.target.removeListener(this.type, this.wrapFn);
|
this.target.removeListener(this.type, this.wrapFn);
|
||||||
this.fired = true;
|
this.fired = true;
|
||||||
this.listener.apply(this.target, args);
|
Reflect.apply(this.listener, this.target, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user