Skip to content

Commit 69460be

Browse files
committed
perf_hooks: fix performance timeline wpt failures
1 parent 062f8e3 commit 69460be

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

lib/internal/perf/observe.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const {
5353
const {
5454
customInspectSymbol: kInspect,
5555
deprecate,
56+
lazyDOMException,
5657
} = require('internal/util');
5758

5859
const {
@@ -106,9 +107,10 @@ function queuePending() {
106107
isPending = true;
107108
setImmediate(() => {
108109
isPending = false;
109-
for (const pending of kPending)
110-
pending[kDispatch]();
110+
const pendings = ArrayFrom(kPending.values());
111111
kPending.clear();
112+
for (const pending of pendings)
113+
pending[kDispatch]();
112114
});
113115
}
114116

@@ -168,8 +170,13 @@ class PerformanceObserverEntryList {
168170
(entry) => entry.entryType === type);
169171
}
170172

171-
getEntriesByName(name) {
173+
getEntriesByName(name, type) {
172174
name = `${name}`;
175+
if (type != null /** not nullish */) {
176+
return ArrayPrototypeFilter(
177+
this[kBuffer],
178+
(entry) => entry.name === name && entry.entryType === type);
179+
}
173180
return ArrayPrototypeFilter(
174181
this[kBuffer],
175182
(entry) => entry.name === name);
@@ -208,6 +215,8 @@ class PerformanceObserver {
208215
} = { ...options };
209216
if (entryTypes === undefined && type === undefined)
210217
throw new ERR_MISSING_ARGS('options.entryTypes', 'options.type');
218+
if (entryTypes != null && type != null)
219+
throw new ERR_INVALID_ARG_VALUE('options.entryTypes', entryTypes, 'options.entryTypes can not set with options.type together');
211220

212221
switch (this[kType]) {
213222
case undefined:
@@ -216,11 +225,11 @@ class PerformanceObserver {
216225
break;
217226
case kTypeSingle:
218227
if (entryTypes !== undefined)
219-
throw new ERR_INVALID_ARG_VALUE('options.entryTypes', entryTypes);
228+
throw lazyDOMException('PerformanceObserver can not change to multiple observations', 'InvalidModificationError');
220229
break;
221230
case kTypeMultiple:
222231
if (type !== undefined)
223-
throw new ERR_INVALID_ARG_VALUE('options.type', type);
232+
throw lazyDOMException('PerformanceObserver can not change to single observation', 'InvalidModificationError');
224233
break;
225234
}
226235

@@ -271,7 +280,7 @@ class PerformanceObserver {
271280
takeRecords() {
272281
const list = this[kBuffer];
273282
this[kBuffer] = [];
274-
return new PerformanceObserverEntryList(list);
283+
return list;
275284
}
276285

277286
static get supportedEntryTypes() {
@@ -287,7 +296,7 @@ class PerformanceObserver {
287296
queuePending();
288297
}
289298

290-
[kDispatch]() { this[kCallback](this.takeRecords(), this); }
299+
[kDispatch]() { this[kCallback](new PerformanceObserverEntryList(this.takeRecords()), this); }
291300

292301
[kInspect](depth, options) {
293302
if (depth < 0) return this;
@@ -367,6 +376,7 @@ function clearEntriesFromBuffer(type, name) {
367376

368377
let head = null;
369378
let tail = null;
379+
let count = 0;
370380
for (let entry = buffer.head; entry !== null; entry = entry[kBufferNext]) {
371381
if (entry.name !== name) {
372382
head = head ?? entry;
@@ -377,9 +387,11 @@ function clearEntriesFromBuffer(type, name) {
377387
continue;
378388
}
379389
tail[kBufferNext] = entry[kBufferNext];
390+
count++;
380391
}
381392
buffer.head = head;
382393
buffer.tail = tail;
394+
buffer.count = count;
383395
}
384396

385397
function filterBufferMapByNameAndType(name, type) {
@@ -469,6 +481,7 @@ function resetBuffer(buffer) {
469481

470482
module.exports = {
471483
PerformanceObserver,
484+
PerformanceObserverEntryList,
472485
enqueue,
473486
hasObserver,
474487
clearEntriesFromBuffer,

lib/perf_hooks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
} = internalBinding('performance');
1010

1111
const { PerformanceEntry } = require('internal/perf/performance_entry');
12-
const { PerformanceObserver } = require('internal/perf/observe');
12+
const { PerformanceObserver, PerformanceObserverEntryList } = require('internal/perf/observe');
1313
const {
1414
PerformanceMark,
1515
PerformanceMeasure,
@@ -27,6 +27,7 @@ module.exports = {
2727
PerformanceMark,
2828
PerformanceMeasure,
2929
PerformanceObserver,
30+
PerformanceObserverEntryList,
3031
monitorEventLoopDelay,
3132
createHistogram,
3233
performance: new InternalPerformance(),
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
{}
1+
{
2+
"case-sensitivity.any.js": {
3+
"fail": "resource entry type not supported"
4+
},
5+
"idlharness.any.js": {
6+
"skip": "idlharness cannot recognize Node.js environment"
7+
},
8+
"webtiming-resolution.any.js": {
9+
"skip": "flaky"
10+
}
11+
}

test/wpt/test-performance-timeline.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require('../common');
33
const { WPTRunner } = require('../common/wpt');
44

5-
const runner = new WPTRunner('user-timing');
5+
const runner = new WPTRunner('performance-timeline');
66

77
// Needed to access to DOMException.
88
runner.setFlags(['--expose-internals']);
@@ -12,11 +12,13 @@ runner.setInitScript(`
1212
PerformanceMark,
1313
PerformanceMeasure,
1414
PerformanceObserver,
15+
PerformanceObserverEntryList,
1516
performance,
1617
} = require('perf_hooks');
1718
global.PerformanceMark = performance;
1819
global.PerformanceMeasure = performance;
1920
global.PerformanceObserver = PerformanceObserver;
21+
global.PerformanceObserverEntryList = PerformanceObserverEntryList;
2022
global.performance = performance;
2123
2224
const { internalBinding } = require('internal/test/binding');

0 commit comments

Comments
 (0)