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 82393ae

Browse filesBrowse files
aduh95danielleadams
authored andcommitted
events: refactor to use more primordials
PR-URL: #36304 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 5645b21 commit 82393ae
Copy full SHA for 82393ae

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+17
-12
lines changed
Open diff view settings
Collapse file

‎lib/events.js‎

Copy file name to clipboardExpand all lines: lib/events.js
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
'use strict';
2323

2424
const {
25+
ArrayPrototypeForEach,
2526
ArrayPrototypePush,
27+
ArrayPrototypeSlice,
2628
Boolean,
2729
Error,
2830
ErrorCaptureStackTrace,
31+
FunctionPrototypeCall,
2932
MathMin,
3033
NumberIsNaN,
3134
ObjectCreate,
@@ -81,7 +84,7 @@ const lazyDOMException = hideStackFrames((message, name) => {
8184

8285

8386
function EventEmitter(opts) {
84-
EventEmitter.init.call(this, opts);
87+
FunctionPrototypeCall(EventEmitter.init, this, opts);
8588
}
8689
module.exports = EventEmitter;
8790
module.exports.once = once;
@@ -173,7 +176,7 @@ EventEmitter.setMaxListeners =
173176
isEventTarget = require('internal/event_target').isEventTarget;
174177

175178
// Performance for forEach is now comparable with regular for-loop
176-
eventTargets.forEach((target) => {
179+
ArrayPrototypeForEach(eventTargets, (target) => {
177180
if (isEventTarget(target)) {
178181
target[kMaxEventTargetListeners] = n;
179182
target[kMaxEventTargetListenersWarned] = false;
@@ -224,7 +227,7 @@ function addCatch(that, promise, type, args) {
224227
const then = promise.then;
225228

226229
if (typeof then === 'function') {
227-
then.call(promise, undefined, function(err) {
230+
FunctionPrototypeCall(then, promise, undefined, function(err) {
228231
// The callback is called with nextTick to avoid a follow-up
229232
// rejection from this promise.
230233
process.nextTick(emitUnhandledRejectionOrErr, that, err, type, args);
@@ -670,7 +673,7 @@ function arrayClone(arr) {
670673
case 5: return [arr[0], arr[1], arr[2], arr[3], arr[4]];
671674
case 6: return [arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]];
672675
}
673-
return arr.slice();
676+
return ArrayPrototypeSlice(arr);
674677
}
675678

676679
function unwrapListeners(arr) {
@@ -813,7 +816,7 @@ function on(emitter, event, options) {
813816

814817
// Wait until an event happens
815818
return new Promise(function(resolve, reject) {
816-
unconsumedPromises.push({ resolve, reject });
819+
ArrayPrototypePush(unconsumedPromises, { resolve, reject });
817820
});
818821
},
819822

@@ -877,7 +880,7 @@ function on(emitter, event, options) {
877880
if (promise) {
878881
promise.resolve(createIterResult(args, false));
879882
} else {
880-
unconsumedEvents.push(args);
883+
ArrayPrototypePush(unconsumedEvents, args);
881884
}
882885
}
883886

Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayFrom,
55
Boolean,
66
Error,
7+
FunctionPrototypeBind,
78
FunctionPrototypeCall,
89
NumberIsInteger,
910
ObjectAssign,
@@ -212,7 +213,7 @@ class Listener {
212213
this.callback =
213214
typeof listener === 'function' ?
214215
listener :
215-
listener.handleEvent.bind(listener);
216+
FunctionPrototypeBind(listener.handleEvent, listener);
216217
}
217218

218219
same(listener, capture) {
@@ -419,7 +420,7 @@ class EventTarget {
419420
} else {
420421
arg = createEvent();
421422
}
422-
const result = handler.callback.call(this, arg);
423+
const result = FunctionPrototypeCall(handler.callback, this, arg);
423424
if (result !== undefined && result !== null)
424425
addCatch(this, result, createEvent());
425426
} catch (err) {
@@ -590,7 +591,7 @@ function isEventTarget(obj) {
590591
function addCatch(that, promise, event) {
591592
const then = promise.then;
592593
if (typeof then === 'function') {
593-
then.call(promise, undefined, function(err) {
594+
FunctionPrototypeCall(then, promise, undefined, function(err) {
594595
// The callback is called with nextTick to avoid a follow-up
595596
// rejection from this promise.
596597
process.nextTick(emitUnhandledRejectionOrErr, that, err, event);
Collapse file

‎lib/trace_events.js‎

Copy file name to clipboardExpand all lines: lib/trace_events.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const {
44
ArrayIsArray,
5-
Set,
5+
ArrayPrototypeJoin,
6+
SafeSet,
67
Symbol,
78
} = primordials;
89

@@ -27,7 +28,7 @@ const { CategorySet, getEnabledCategories } = internalBinding('trace_events');
2728
const { customInspectSymbol } = require('internal/util');
2829
const { format } = require('internal/util/inspect');
2930

30-
const enabledTracingObjects = new Set();
31+
const enabledTracingObjects = new SafeSet();
3132

3233
class Tracing {
3334
constructor(categories) {
@@ -63,7 +64,7 @@ class Tracing {
6364
}
6465

6566
get categories() {
66-
return this[kCategories].join(',');
67+
return ArrayPrototypeJoin(this[kCategories], ',');
6768
}
6869

6970
[customInspectSymbol](depth, opts) {

0 commit comments

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