Skip to content

Commit a4ade04

Browse files
authored
fix(performanceTimer): throwing in axe catch clause (#4852)
I ran into a problem with this: https://github.com/dequelabs/axe-core/blob/e7dae4ec48cbfef74de9f833fdcfb178c1002985/lib/core/base/rule.js#L297-L300 If the end mark isn't set, performance.measure throws an error. Since we call performance.measure in the catch, it is quite possible that the end mark doesn't exist. And then throwing from a catch completely throws the run. I don't think axe should fail if the performance measure fails, so instead I'm going to have it just log the error and move forward.
1 parent e7dae4e commit a4ade04

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/core/utils/performance-timer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ const performanceTimer = (() => {
9393
if (!window.performance?.measure) {
9494
return;
9595
}
96-
window.performance.measure(measureName, startMark, endMark);
96+
try {
97+
window.performance.measure(measureName, startMark, endMark);
98+
} catch (e) {
99+
this._log(e);
100+
}
97101
if (!keepMarks) {
98102
this.clearMark(startMark, endMark);
99103
}

test/core/utils/performance-timer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ describe('performance timer', () => {
8181
assert.match(messages[0], /Measure audit_start_to_end took [0-9.]+ms/);
8282
});
8383

84+
describe('.measure', () => {
85+
it('logs an error if the start mark is not present', () => {
86+
performanceTimer.mark('foo_end');
87+
performanceTimer.measure('foo', 'foo_start', 'foo_end');
88+
assert.equal(messages.length, 1);
89+
// non-specific message, Firefox has a different message from Chromium
90+
assert.match(messages[0], /foo_start/);
91+
});
92+
93+
it('logs an error if the end mark is not present', () => {
94+
performanceTimer.mark('foo_start');
95+
performanceTimer.measure('foo', 'foo_start', 'foo_end');
96+
assert.equal(messages.length, 1);
97+
// non-specific message, Firefox has a different message from Chromium
98+
assert.match(messages[0], /foo_end/);
99+
});
100+
});
101+
84102
describe('logMeasures', () => {
85103
beforeEach(() => {
86104
performanceTimer.start();

0 commit comments

Comments
 (0)