Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,30 @@ export class PerformanceObserver {
return observerHandle;
}

#validateObserveOptions(options: PerformanceObserverInit): void {
const {type, entryTypes, durationThreshold} = options;
#validateObserveOptions(options: ?PerformanceObserverInit): void {
if (options == null) {
throw new TypeError(
"Failed to execute 'observe' on 'PerformanceObserver': 1 argument required, but only 0 present.",
);
}

const {type, entryTypes, durationThreshold, buffered} = options;

if (!type && !entryTypes) {
throw new TypeError(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and type arguments.",
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must include either entryTypes or type arguments.",
);
}

if (entryTypes && type) {
throw new TypeError(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must include either entryTypes or type arguments.",
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and type arguments.",
);
}

if (entryTypes && buffered != null) {
throw new TypeError(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and buffered arguments.",
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ describe('PerformanceObserver', () => {
expect(entries2.getEntries()[1]).toBe(measure);
});

describe('observe()', () => {
it('rejects invalid entry type option combinations before registering with native', () => {
const callback = jest.fn();
const observer = new PerformanceObserver(callback);

// $FlowExpectedError[incompatible-call]
expect(() => observer.observe()).toThrow(
"Failed to execute 'observe' on 'PerformanceObserver': 1 argument required, but only 0 present.",
);
expect(() => observer.observe({})).toThrow(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must include either entryTypes or type arguments.",
);
expect(() =>
observer.observe({entryTypes: ['mark'], type: 'measure'}),
).toThrow(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and type arguments.",
);
expect(() =>
observer.observe({entryTypes: ['mark'], buffered: true}),
).toThrow(
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and buffered arguments.",
);
});
});

describe('takeRecords()', () => {
it('provides all buffered events and clears the buffer', () => {
const callback = jest.fn();
Expand Down
Loading