mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1772417 - correct web-platform convert name to timestamp. r=sefeng
This fixes the performance-measure-invalid.worker.html test. The test failed because User Timing L3 section 4.2, "Convert a name to a timestamp", was not implemented - the code was presumably residual from an earlier version of User Timing. In particular, we never threw if the global object was not a Window. We also corrected the code order for section 4.1, "Convert a mark to a timestamp", which was incorrect but didn't cause any tests to fail. Differential Revision: https://phabricator.services.mozilla.com/D154820
This commit is contained in:
parent
312bff454e
commit
2f4dbb0e6b
@ -431,6 +431,10 @@ bool Performance::IsPerformanceTimingAttribute(const nsAString& aName) const {
|
||||
|
||||
DOMHighResTimeStamp Performance::ConvertMarkToTimestampWithString(
|
||||
const nsAString& aName, ErrorResult& aRv) {
|
||||
if (IsPerformanceTimingAttribute(aName)) {
|
||||
return ConvertNameToTimestamp(aName, aRv);
|
||||
}
|
||||
|
||||
AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
|
||||
Optional<nsAString> typeParam;
|
||||
nsAutoString str;
|
||||
@ -441,20 +445,10 @@ DOMHighResTimeStamp Performance::ConvertMarkToTimestampWithString(
|
||||
return arr.LastElement()->StartTime();
|
||||
}
|
||||
|
||||
if (!IsPerformanceTimingAttribute(aName)) {
|
||||
nsPrintfCString errorMsg("Given mark name, %s, is unknown",
|
||||
NS_ConvertUTF16toUTF8(aName).get());
|
||||
aRv.ThrowSyntaxError(errorMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp ts = GetPerformanceTimingFromString(aName);
|
||||
if (!ts) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ts - CreationTime();
|
||||
nsPrintfCString errorMsg("Given mark name, %s, is unknown",
|
||||
NS_ConvertUTF16toUTF8(aName).get());
|
||||
aRv.ThrowSyntaxError(errorMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp Performance::ConvertMarkToTimestampWithDOMHighResTimeStamp(
|
||||
@ -493,6 +487,39 @@ DOMHighResTimeStamp Performance::ConvertMarkToTimestamp(
|
||||
aAttribute, aMarkNameOrTimestamp.GetAsDouble(), aRv);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp Performance::ConvertNameToTimestamp(const nsAString& aName,
|
||||
ErrorResult& aRv) {
|
||||
if (!IsGlobalObjectWindow()) {
|
||||
nsPrintfCString errorMsg(
|
||||
"Cannot get PerformanceTiming attribute values for non-Window global "
|
||||
"object. Given: %s",
|
||||
NS_ConvertUTF16toUTF8(aName).get());
|
||||
aRv.ThrowTypeError(errorMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (aName.EqualsASCII("navigationStart")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We use GetPerformanceTimingFromString, rather than calling the
|
||||
// navigationStart method timing function directly, because the former handles
|
||||
// reducing precision against timing attacks.
|
||||
const DOMHighResTimeStamp startTime =
|
||||
GetPerformanceTimingFromString(u"navigationStart"_ns);
|
||||
const DOMHighResTimeStamp endTime = GetPerformanceTimingFromString(aName);
|
||||
MOZ_ASSERT(endTime >= 0);
|
||||
if (endTime == 0) {
|
||||
nsPrintfCString errorMsg(
|
||||
"Given PerformanceTiming attribute, %s, isn't available yet",
|
||||
NS_ConvertUTF16toUTF8(aName).get());
|
||||
aRv.ThrowInvalidAccessError(errorMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp Performance::ResolveEndTimeForMeasure(
|
||||
const Optional<nsAString>& aEndMark,
|
||||
const Maybe<const PerformanceMeasureOptions&>& aOptions, ErrorResult& aRv) {
|
||||
|
@ -223,6 +223,9 @@ class Performance : public DOMEventTargetHelper {
|
||||
const ResolveTimestampAttribute aAttribute,
|
||||
const OwningStringOrDouble& aMarkNameOrTimestamp, ErrorResult& aRv);
|
||||
|
||||
DOMHighResTimeStamp ConvertNameToTimestamp(const nsAString& aName,
|
||||
ErrorResult& aRv);
|
||||
|
||||
DOMHighResTimeStamp ResolveEndTimeForMeasure(
|
||||
const Optional<nsAString>& aEndMark,
|
||||
const Maybe<const PerformanceMeasureOptions&>& aOptions,
|
||||
|
@ -1,4 +0,0 @@
|
||||
[performance-measure-invalid.worker.html]
|
||||
[When converting 'navigationStart' to a timestamp, the global object has to be a Window object.]
|
||||
expected: FAIL
|
||||
|
Loading…
Reference in New Issue
Block a user