Commit 51060891 authored by Tom McKee's avatar Tom McKee Committed by Commit Bot

[UserTimingL3] Replace SyntaxError with TypeError.

The User Timing L3 specification requires TypeErrors to be thrown when
calls to `performance.measure()` are malformed. The User Timing L2
specification used SyntaxErrors for similar error conditions.

This CL changes our use of SyntaxError to TypeError when L3 conformance
is active.

Bug: 953960
Change-Id: I87bb0717687f4a3b149eaeb6fc190fa9a98d1f9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1647342Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Auto-Submit: Tom McKee <tommckee@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668488}
parent ebcf8f94
...@@ -742,8 +742,7 @@ PerformanceMeasure* Performance::MeasureInternal( ...@@ -742,8 +742,7 @@ PerformanceMeasure* Performance::MeasureInternal(
if (start_or_options.IsPerformanceMeasureOptions()) { if (start_or_options.IsPerformanceMeasureOptions()) {
// measure("name", {}, *) // measure("name", {}, *)
if (end) { if (end) {
exception_state.ThrowDOMException( exception_state.ThrowTypeError(
DOMExceptionCode::kSyntaxError,
"If a PerformanceMeasureOptions object was passed, |end| must be " "If a PerformanceMeasureOptions object was passed, |end| must be "
"null."); "null.");
return nullptr; return nullptr;
......
...@@ -5,7 +5,13 @@ ...@@ -5,7 +5,13 @@
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="resources/user-timing-helper.js"></script> <script src="resources/user-timing-helper.js"></script>
<script> <script>
function cleanupPerformanceTimeline() {
performance.clearMarks();
performance.clearMeasures();
}
async_test(function (t) { async_test(function (t) {
this.add_cleanup(cleanupPerformanceTimeline);
let measureEntries = []; let measureEntries = [];
const timeStamp1 = 784.4; const timeStamp1 = 784.4;
const timeStamp2 = 1234.5; const timeStamp2 = 1234.5;
...@@ -40,8 +46,6 @@ ...@@ -40,8 +46,6 @@
} }
}) })
); );
self.performance.clearMarks();
self.performance.clearMeasures();
observer.observe({ entryTypes: ["measure"] }); observer.observe({ entryTypes: ["measure"] });
self.performance.mark("mark1", { detail: { randomInfo: 3 }, startTime: timeStamp1 }); self.performance.mark("mark1", { detail: { randomInfo: 3 }, startTime: timeStamp1 });
self.performance.mark("mark2", { startTime: timeStamp2 }); self.performance.mark("mark2", { startTime: timeStamp2 });
...@@ -80,10 +84,16 @@ ...@@ -80,10 +84,16 @@
checkEntries(returnedEntries, expectedEntries); checkEntries(returnedEntries, expectedEntries);
}, "measure entries' detail and start/end are customizable"); }, "measure entries' detail and start/end are customizable");
async_test(function (t) { test(function () {
assert_throws("SyntaxError", function() { this.add_cleanup(cleanupPerformanceTimeline);
assert_throws(new TypeError(), function() {
self.performance.measure("wrongUsage1", {}, 12); self.performance.measure("wrongUsage1", {}, 12);
}); }, "measure should throw a TypeError when passed an options object and an end time");
t.done(); assert_throws(new TypeError(), function() {
}, "measure should throw exception when passing option object and end at the same time"); self.performance.measure("wrongUsage2", {'startTime': 2}, 12);
}, "measure should throw a TypeError when passed an options object and an end time");
assert_throws(new TypeError(), function() {
self.performance.measure("wrongUsage3", {'startTime': 2}, 'mark1');
}, "measure should throw a TypeError when passed an options object and an end mark");
}, "measure should throw a TypeError when passed an invalid argument combination");
</script> </script>
This is a testharness.js-based test. This is a testharness.js-based test.
FAIL measure entries' detail and start/end are customizable Failed to execute 'measure' on 'Performance': The mark '[object Object]' does not exist. FAIL measure entries' detail and start/end are customizable Failed to execute 'measure' on 'Performance': The mark '[object Object]' does not exist.
PASS measure should throw exception when passing option object and end at the same time FAIL measure should throw a TypeError when passed an invalid argument combination assert_throws: measure should throw a TypeError when passed an options object and an end time function "function() {
self.performance.measure("wrongUsage1", {}, 12);
}" threw object "SyntaxError: Failed to execute 'measure' on 'Performance': The mark '[object Object]' does not exist." ("SyntaxError") expected object "TypeError" ("TypeError")
Harness: the test ran to completion. Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment