Skip to content

lib, doc: standardize params in PerformanceObserver.observe #47025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/perf_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ changes:
* `buffered` {boolean} If true, the observer callback is called with a
list global `PerformanceEntry` buffered entries. If false, only
`PerformanceEntry`s created after the time point are sent to the
observer callback. **Default:** `false`.
observer callback. Must be used only with `options.type`.

Subscribes the {PerformanceObserver} instance to notifications of new
{PerformanceEntry} instances identified either by `options.entryTypes`
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/perf/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ class PerformanceObserver {
} = { ...options };
if (entryTypes === undefined && type === undefined)
throw new ERR_MISSING_ARGS('options.entryTypes', 'options.type');
if (entryTypes != null && type != null)
if (entryTypes != null && (type != null || buffered != null))
throw new ERR_INVALID_ARG_VALUE('options.entryTypes',
entryTypes,
'options.entryTypes can not set with ' +
'options.type together');
'options.type or options.buffered together');

switch (this.#type) {
case undefined:
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/wpt/performance-timeline/po-observe-type.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ test(() => {
});
}, "Calling observe() with type and entryTypes should throw a TypeError");

test(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in WPT should be submitted to the upstream first: https://github.com/web-platform-tests/wpt.

In the meantime, you can move this test case to test/parallel/ directory. That's where Node.js' test cases are located at.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have the changes been upstreamed?

const obs = new PerformanceObserver(() =>{});
assert_throws_js(TypeError, function () {
obs.observe({buffered: true, entryTypes: ["measure"]});
});
}, "Calling observe() with buffered and entryTypes should throw a TypeError");

test(function () {
const obs = new PerformanceObserver(() =>{});
// Definitely not an entry type.
Expand Down