Skip to content

Commit

Permalink
[Squash] nits
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine du Hamel <[email protected]>
  • Loading branch information
jasnell and aduh95 authored Jan 30, 2021
1 parent bb6f2ba commit 1d7fc41
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
8 changes: 2 additions & 6 deletions lib/internal/perf/event_loop_delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ class ELDHistogram extends Histogram {
}

function monitorEventLoopDelay(options = {}) {
if (typeof options !== 'object' || options === null)
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
validateObject(options, 'options');

const { resolution = 10 } = options;
if (typeof resolution !== 'number') {
throw new ERR_INVALID_ARG_TYPE('options.resolution',
'number', resolution);
}
validateNumber(resolution, 'options.resolution');
if (resolution <= 0 || !NumberIsSafeInteger(resolution))
throw new ERR_INVALID_ARG_VALUE.RangeError('resolution', resolution);

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/perf/nodetiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function getMilestoneTimestamp(milestoneIdx) {
return ns / 1e6 - timeOrigin;
}

const readOnlyAttributes = new SafeSet([
const readOnlyAttributes = new SafeSet(new SafeArrayIterator([
'nodeStart',
'v8Start',
'environment',
'loopStart',
'loopExit',
'bootstrapComplete',
]);
]));

class PerformanceNodeTiming {
constructor() {
Expand Down
13 changes: 6 additions & 7 deletions lib/internal/perf/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ function queuePending() {
isPending = true;
setImmediate(() => {
isPending = false;
const pending = ArrayFrom(kPending);
for(const pending of kPending)
pending[kDispatch]();
kPending.clear();
for (let n = 0; n < pending.length; n++)
pending[n][kDispatch]();
});
}

Expand Down Expand Up @@ -158,7 +157,7 @@ class PerformanceObserverEntryList {
}

getEntries() {
return Array(...this[kBuffer]);
return ArrayPrototypeSlice(this[kBuffer]);
}

getEntriesByType(type) {
Expand Down Expand Up @@ -231,13 +230,13 @@ class PerformanceObserver {
maybeDecrementObserverCounts(this[kEntryTypes]);
this[kEntryTypes].clear();
for (let n = 0; n < entryTypes.length; n++) {
if (kSupportedEntryTypes.includes(entryTypes[n])) {
if (ArrayPrototypeIncludes(kSupportedEntryTypes, entryTypes[n])) {
this[kEntryTypes].add(entryTypes[n]);
maybeIncrementObserverCount(entryTypes[n]);
}
}
} else {
if (!kSupportedEntryTypes.includes(type))
if (!ArrayPrototypeIncludes(kSupportedEntryTypes, type))
return;
this[kEntryTypes].add(type);
maybeIncrementObserverCount(type);
Expand Down Expand Up @@ -271,7 +270,7 @@ class PerformanceObserver {
[kMaybeBuffer](entry) {
if (!this[kEntryTypes].has(entry.entryType))
return;
this[kBuffer].push(entry);
ArrayPrototypePush(this[kBuffer], entry);
kPending.add(this);
if (kPending.size)
queuePending();
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/perf/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = primordials;

const {
timeOrigin
timeOrigin,
} = internalBinding('performance');

const {
Expand All @@ -29,8 +29,7 @@ function now() {
}

function isPerformanceEntry(obj) {
if (obj == null || typeof obj !== 'object') return false;
return obj[kName] !== undefined;
return obj?.[kName] !== undefined;
}

class PerformanceEntry {
Expand Down
17 changes: 6 additions & 11 deletions lib/internal/perf/usertiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function calculateStartDuration(startOrMeasureOptions, endMark) {
let end;
let duration;
if (typeof startOrMeasureOptions === 'object' &&
ObjectEntries(startOrMeasureOptions).length) {
ObjectKeys(startOrMeasureOptions).length) {
({
start,
end,
Expand All @@ -113,18 +113,13 @@ function calculateStartDuration(startOrMeasureOptions, endMark) {
start = getMark(startOrMeasureOptions);
}

end = getMark(endMark || end);
if (end === undefined) {
end = (start !== undefined && duration !== undefined) ?
start + duration : now();
}
end = getMark(endMark || end) ??
(start !== undefined && duration !== undefined) ?
start + duration : now();

if (start === undefined) {
start = (duration !== undefined) ? end - duration : 0;
}
start ??= (duration !== undefined) ? end - duration : 0;

if (duration === undefined)
duration = end - start;
duration ??= end - start;

return { start, duration, detail };
}
Expand Down

0 comments on commit 1d7fc41

Please sign in to comment.