From 173e528f3ff4f9ca940ba94d77301afa332d108a Mon Sep 17 00:00:00 2001 From: Umuoy Date: Thu, 9 Mar 2023 15:37:56 +0800 Subject: [PATCH 1/2] lib, doc: standardize params in PerformanceObserver.observe --- doc/api/perf_hooks.md | 2 +- lib/internal/perf/observe.js | 4 ++-- .../wpt/performance-timeline/po-observe-type.any.js | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 1c18395662f171..df388293b44201 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -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` diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index b97ae08402260a..c15ccd7e645c99 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -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)) 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: diff --git a/test/fixtures/wpt/performance-timeline/po-observe-type.any.js b/test/fixtures/wpt/performance-timeline/po-observe-type.any.js index b9854cc1466fa7..754531357c7069 100644 --- a/test/fixtures/wpt/performance-timeline/po-observe-type.any.js +++ b/test/fixtures/wpt/performance-timeline/po-observe-type.any.js @@ -33,6 +33,13 @@ test(() => { }); }, "Calling observe() with type and entryTypes should throw a TypeError"); +test(() => { + 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. From e34733d116814ae76dd61b5edcffe3b0b9d7ce3e Mon Sep 17 00:00:00 2001 From: Umuoy Date: Thu, 9 Mar 2023 15:45:23 +0800 Subject: [PATCH 2/2] Fixup --- lib/internal/perf/observe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index c15ccd7e645c99..c424fb0ae44db0 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -260,7 +260,7 @@ class PerformanceObserver { } = { ...options }; if (entryTypes === undefined && type === undefined) throw new ERR_MISSING_ARGS('options.entryTypes', 'options.type'); - if (entryTypes != null && (type != null || buffered)) + if (entryTypes != null && (type != null || buffered != null)) throw new ERR_INVALID_ARG_VALUE('options.entryTypes', entryTypes, 'options.entryTypes can not set with ' +