mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Issue #2053 - Part 4b: Fix measure name to timestamp conversion
Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=1772417
This commit is contained in:
parent
4fc9cde7c1
commit
a0d52c0094
3 changed files with 38 additions and 13 deletions
|
|
@ -108,3 +108,4 @@ MSG_DEF(MSG_PMO_UNKNOWN_MARK_NAME, 1, JSEXN_SYNTAXERR, "Given mark name, {0}, is
|
|||
MSG_DEF(MSG_PMO_CONSTRUCTOR_INACCESSIBLE, 0, JSEXN_TYPEERR, "Can't access PerformanceMark constructor, performance is null.")
|
||||
MSG_DEF(MSG_PMO_INVALID_TIMING_ATTR, 0, JSEXN_SYNTAXERR, "markName cannot be a performance timing attribute.")
|
||||
MSG_DEF(MSG_PMO_UNEXPECTED_START_TIME, 0, JSEXN_TYPEERR, "Expected startTime >= 0.")
|
||||
MSG_DEF(MSG_PMO_INVALID_ATTR_FOR_NON_GLOBAL, 1, JSEXN_TYPEERR, "Cannot get PerformanceTiming attribute values for non-Window global object. Given: {0}.")
|
||||
|
|
|
|||
|
|
@ -326,8 +326,11 @@ DOMHighResTimeStamp
|
|||
Performance::ConvertMarkToTimestampWithString(const nsAString& aName,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (IsPerformanceTimingAttribute(aName)) {
|
||||
return ConvertNameToTimestamp(aName, aRv);
|
||||
}
|
||||
|
||||
AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
|
||||
DOMHighResTimeStamp ts;
|
||||
Optional<nsAString> typeParam;
|
||||
nsAutoString str;
|
||||
str.AssignLiteral("mark");
|
||||
|
|
@ -337,18 +340,8 @@ Performance::ConvertMarkToTimestampWithString(const nsAString& aName,
|
|||
return arr.LastElement()->StartTime();
|
||||
}
|
||||
|
||||
if (!IsPerformanceTimingAttribute(aName)) {
|
||||
aRv.ThrowTypeError<MSG_PMO_UNKNOWN_MARK_NAME>(aName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ts = GetPerformanceTimingFromString(aName);
|
||||
if (!ts) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ts - CreationTime();
|
||||
aRv.ThrowTypeError<MSG_PMO_UNKNOWN_MARK_NAME>(aName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
|
|
@ -390,6 +383,34 @@ Performance::ConvertMarkToTimestamp(
|
|||
aAttribute, aMarkNameOrTimestamp.GetAsDouble(), aRv);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp Performance::ConvertNameToTimestamp(const nsAString& aName,
|
||||
ErrorResult& aRv) {
|
||||
if (!IsGlobalObjectWindow()) {
|
||||
aRv.ThrowTypeError<MSG_PMO_INVALID_ATTR_FOR_NON_GLOBAL>(aName);
|
||||
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(NS_LITERAL_STRING("navigationStart"));
|
||||
const DOMHighResTimeStamp endTime =
|
||||
GetPerformanceTimingFromString(aName);
|
||||
MOZ_ASSERT(endTime >= 0);
|
||||
if (endTime == 0) {
|
||||
// Was given a PerformanceTiming attribute which isn't available yet.
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
Performance::ResolveEndTimeForMeasure(
|
||||
const Optional<nsAString>& aEndMark,
|
||||
|
|
|
|||
|
|
@ -190,6 +190,9 @@ private:
|
|||
const ResolveTimestampAttribute aAttribute,
|
||||
const OwningStringOrDouble& aMarkNameOrTimestamp, ErrorResult& aRv);
|
||||
|
||||
DOMHighResTimeStamp ConvertNameToTimestamp(const nsAString& aName,
|
||||
ErrorResult& aRv);
|
||||
|
||||
DOMHighResTimeStamp ResolveEndTimeForMeasure(
|
||||
const Optional<nsAString>& aEndMark,
|
||||
const PerformanceMeasureOptions* aOptions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue