Bug 1915589 - Allow co-existing entrypTypes and buffered options in PerformanceObserver.observe() method. r=sefeng, a=RyanVM

It's allowed, but the buffered option is ignored. This is what Blink
does [1], what WebKit does [2]. (Both code blocks are inside the else
branch of if `has entryTypes`)

The web-platform-test in this change was originally copied from
buffered-flag-after-timeout.any.js and modified.

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/performance_observer.cc;l=264-273;drc=78780a188fe3c79fe815b170f4ea33e62ceb6e04
[2] https://searchfox.org/wubkat/rev/6c800745251d53d6486443d63b35828504446c5d/Source/WebCore/page/PerformanceObserver.cpp#90-100
[3] https://searchfox.org/mozilla-central/rev/e24277e20c492b4a785b4488af02cca062ec7c2c/testing/web-platform/tests/performance-timeline/buffered-flag-after-timeout.any.js

Differential Revision: https://phabricator.services.mozilla.com/D233447
This commit is contained in:
Hiroyuki Ikezoe 2025-01-09 21:01:13 +00:00
parent e05d864125
commit 2b5bb21c90
2 changed files with 20 additions and 2 deletions

View file

@ -170,9 +170,14 @@ void PerformanceObserver::Observe(const PerformanceObserverInit& aOptions,
return;
}
if (maybeEntryTypes.WasPassed() &&
(maybeType.WasPassed() || maybeBuffered.WasPassed())) {
if (maybeEntryTypes.WasPassed() && maybeType.WasPassed()) {
/* Per spec (3.3.1.3), this, too, should be a syntax error. */
/*
* As per the spec we also need to throw a type error if there are both
* `entryTypes` and `buffered` options, but either Blink or WebKit doesn't
* throw the error so we don't throw to align the behavior with them.
* https://github.com/w3c/performance-timeline/issues/215
*/
aRv.ThrowTypeError("Can't call observe with both `type` and `entryTypes`");
return;
}

View file

@ -0,0 +1,13 @@
async_test(t => {
performance.mark('foo');
// Use a timeout to ensure the remainder of the test runs after the entry is created.
t.step_timeout(() => {
// `buffered` flag set to true but with entryTypes so that
// the `buffered` flag should be ignored, thus there should be no entry.
new PerformanceObserver(() => {
assert_unreached('Should not have observed any entry!');
}).observe({entryTypes: ['mark'], buffered: true});
// Use a timeout to give time to the observer.
t.step_timeout(t.step_func_done(() => {}), 100);
}, 0);
}, 'PerformanceObserver without buffered flag set to false cannot see past entries.');