Skip to content

Commit 173e528

Browse files
committed
lib, doc: standardize params in PerformanceObserver.observe
1 parent c733cc0 commit 173e528

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

doc/api/perf_hooks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ changes:
12721272
* `buffered` {boolean} If true, the observer callback is called with a
12731273
list global `PerformanceEntry` buffered entries. If false, only
12741274
`PerformanceEntry`s created after the time point are sent to the
1275-
observer callback. **Default:** `false`.
1275+
observer callback. Must be used only with `options.type`.
12761276

12771277
Subscribes the {PerformanceObserver} instance to notifications of new
12781278
{PerformanceEntry} instances identified either by `options.entryTypes`

lib/internal/perf/observe.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ class PerformanceObserver {
260260
} = { ...options };
261261
if (entryTypes === undefined && type === undefined)
262262
throw new ERR_MISSING_ARGS('options.entryTypes', 'options.type');
263-
if (entryTypes != null && type != null)
263+
if (entryTypes != null && (type != null || buffered))
264264
throw new ERR_INVALID_ARG_VALUE('options.entryTypes',
265265
entryTypes,
266266
'options.entryTypes can not set with ' +
267-
'options.type together');
267+
'options.type or options.buffered together');
268268

269269
switch (this.#type) {
270270
case undefined:

test/fixtures/wpt/performance-timeline/po-observe-type.any.js

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ test(() => {
3333
});
3434
}, "Calling observe() with type and entryTypes should throw a TypeError");
3535

36+
test(() => {
37+
const obs = new PerformanceObserver(() =>{});
38+
assert_throws_js(TypeError, function () {
39+
obs.observe({buffered: true, entryTypes: ["measure"]});
40+
});
41+
}, "Calling observe() with buffered and entryTypes should throw a TypeError");
42+
3643
test(function () {
3744
const obs = new PerformanceObserver(() =>{});
3845
// Definitely not an entry type.

0 commit comments

Comments
 (0)