diff options
author | Brian Smith <brian@dbsoft.org> | 2023-07-12 14:25:06 -0500 |
---|---|---|
committer | Brian Smith <brian@dbsoft.org> | 2023-07-12 14:25:06 -0500 |
commit | f0b08a209d1d2fdc915ca35fc739ac3d02f653ce (patch) | |
tree | 4f46f9107d68fe3caf2f9f76a21024b636518ffc | |
parent | 3284e449a73e610c45214b0a4339866189e6087d (diff) | |
download | uxp-f0b08a209d1d2fdc915ca35fc739ac3d02f653ce.tar.gz |
Issue #2255 - Use Maybe<> in the Performance API.
-rwxr-xr-x | dom/performance/Performance.cpp | 30 | ||||
-rw-r--r-- | dom/performance/Performance.h | 6 |
2 files changed, 19 insertions, 17 deletions
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 109f767557..217faa5afe 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -414,16 +414,16 @@ DOMHighResTimeStamp Performance::ConvertNameToTimestamp(const nsAString& aName, DOMHighResTimeStamp Performance::ResolveEndTimeForMeasure( const Optional<nsAString>& aEndMark, - const PerformanceMeasureOptions* aOptions, + const Maybe<const PerformanceMeasureOptions&>& aOptions, ErrorResult& aRv) { DOMHighResTimeStamp endTime; if (aEndMark.WasPassed()) { endTime = ConvertMarkToTimestampWithString(aEndMark.Value(), aRv); - } else if (aOptions != nullptr && aOptions->mEnd.WasPassed()) { + } else if (aOptions && aOptions->mEnd.WasPassed()) { endTime = ConvertMarkToTimestamp(ResolveTimestampAttribute::End, aOptions->mEnd.Value(), aRv); - } else if (aOptions != nullptr && aOptions->mStart.WasPassed() && + } else if (aOptions && aOptions->mStart.WasPassed() && aOptions->mDuration.WasPassed()) { const DOMHighResTimeStamp start = ConvertMarkToTimestamp( ResolveTimestampAttribute::Start, aOptions->mStart.Value(), aRv); @@ -448,16 +448,16 @@ Performance::ResolveEndTimeForMeasure( DOMHighResTimeStamp Performance::ResolveStartTimeForMeasure( - const nsAString* aStartMark, - const PerformanceMeasureOptions* aOptions, + const Maybe<const nsAString&>& aStartMark, + const Maybe<const PerformanceMeasureOptions&>& aOptions, ErrorResult& aRv) { DOMHighResTimeStamp startTime; - if (aOptions != nullptr && aOptions->mStart.WasPassed()) { + if (aOptions && aOptions->mStart.WasPassed()) { startTime = ConvertMarkToTimestamp(ResolveTimestampAttribute::Start, aOptions->mStart.Value(), aRv); - } else if (aOptions != nullptr && aOptions->mDuration.WasPassed() && + } else if (aOptions && aOptions->mDuration.WasPassed() && aOptions->mEnd.WasPassed()) { const DOMHighResTimeStamp duration = ConvertMarkToTimestampWithDOMHighResTimeStamp( @@ -475,7 +475,7 @@ Performance::ResolveStartTimeForMeasure( } startTime = end - duration; - } else if (aStartMark != nullptr) { + } else if (aStartMark) { startTime = ConvertMarkToTimestampWithString(*aStartMark, aRv); } else { startTime = 0; @@ -497,13 +497,14 @@ Performance::Measure(JSContext* aCx, mUserEntries.Clear(); } - const PerformanceMeasureOptions* options = nullptr; + // Maybe is more readable than using the union type directly. + Maybe<const PerformanceMeasureOptions&> options; if (aStartOrMeasureOptions.IsPerformanceMeasureOptions()) { - options = &aStartOrMeasureOptions.GetAsPerformanceMeasureOptions(); + options.emplace(aStartOrMeasureOptions.GetAsPerformanceMeasureOptions()); } const bool isOptionsNotEmpty = - (options != nullptr) && + options.isSome() && (!options->mDetail.isUndefined() || options->mStart.WasPassed() || options->mEnd.WasPassed() || options->mDuration.WasPassed()); if (isOptionsNotEmpty) { @@ -530,9 +531,10 @@ Performance::Measure(JSContext* aCx, return nullptr; } - const nsAString* startMark = nullptr; + // Convert to Maybe for consistency with options. + Maybe<const nsAString&> startMark; if (aStartOrMeasureOptions.IsString()) { - startMark = &aStartOrMeasureOptions.GetAsString(); + startMark.emplace(aStartOrMeasureOptions.GetAsString()); } const DOMHighResTimeStamp startTime = ResolveStartTimeForMeasure(startMark, options, aRv); @@ -541,7 +543,7 @@ Performance::Measure(JSContext* aCx, } JS::Rooted<JS::Value> detail(aCx); - if (options != nullptr && !options->mDetail.isNullOrUndefined()) { + if (options && !options->mDetail.isNullOrUndefined()) { StructuredSerializeOptions serializeOptions; JS::Rooted<JS::Value> valueToClone(aCx, options->mDetail); nsContentUtils::StructuredClone(aCx, GetParentObject(), valueToClone, diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index dc58322416..7a60eb85a9 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -195,11 +195,11 @@ private: DOMHighResTimeStamp ResolveEndTimeForMeasure( const Optional<nsAString>& aEndMark, - const PerformanceMeasureOptions* aOptions, + const Maybe<const PerformanceMeasureOptions&>& aOptions, ErrorResult& aRv); DOMHighResTimeStamp ResolveStartTimeForMeasure( - const nsAString* aStartMark, - const PerformanceMeasureOptions* aOptions, + const Maybe<const nsAString&>& aStartMark, + const Maybe<const PerformanceMeasureOptions&>& aOptions, ErrorResult& aRv); }; |