Skip to content

Commit

Permalink
Bug 1276351 - Move away from mozilla::tuple to std::tuple. r=necko-re…
Browse files Browse the repository at this point in the history
…viewers,sergesanspaille

Differential Revision: https://phabricator.services.mozilla.com/D173256
  • Loading branch information
abpostelnicu committed Mar 27, 2023
1 parent f580576 commit 4efa1bd
Show file tree
Hide file tree
Showing 137 changed files with 571 additions and 677 deletions.
1 change: 0 additions & 1 deletion accessible/base/NotificationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "EventQueue.h"

#include "mozilla/Tuple.h"
#include "nsClassHashtable.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIFrame.h"
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,21 +1356,21 @@ void BrowsingContext::SetTriggeringAndInheritPrincipals(
}
}

Tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
std::tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
BrowsingContext::GetTriggeringAndInheritPrincipalsForCurrentLoad() {
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
GetSavedPrincipal(mTriggeringPrincipal);
nsCOMPtr<nsIPrincipal> principalToInherit =
GetSavedPrincipal(mPrincipalToInherit);
return MakeTuple(triggeringPrincipal, principalToInherit);
return std::make_tuple(triggeringPrincipal, principalToInherit);
}

nsIPrincipal* BrowsingContext::GetSavedPrincipal(
Maybe<PrincipalWithLoadIdentifierTuple> aPrincipalTuple) {
if (aPrincipalTuple) {
nsCOMPtr<nsIPrincipal> principal;
uint64_t loadIdentifier;
Tie(principal, loadIdentifier) = *aPrincipalTuple;
std::tie(principal, loadIdentifier) = *aPrincipalTuple;
// We want to return a principal only if the load identifier for it
// matches the current one for this BC.
if (auto current = GetCurrentLoadIdentifier();
Expand Down
6 changes: 3 additions & 3 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Span.h"
#include "mozilla/Tuple.h"

#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/LocationBase.h"
#include "mozilla/dom/MaybeDiscarded.h"
Expand Down Expand Up @@ -878,7 +878,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {

// Return mTriggeringPrincipal and mPrincipalToInherit if the load id
// saved with the principal matches the current load identifier of this BC.
Tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
std::tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
GetTriggeringAndInheritPrincipalsForCurrentLoad();

void HistoryGo(int32_t aOffset, uint64_t aHistoryEpoch,
Expand Down Expand Up @@ -1259,7 +1259,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void CreateChildSHistory();

using PrincipalWithLoadIdentifierTuple =
Tuple<nsCOMPtr<nsIPrincipal>, uint64_t>;
std::tuple<nsCOMPtr<nsIPrincipal>, uint64_t>;

nsIPrincipal* GetSavedPrincipal(
Maybe<PrincipalWithLoadIdentifierTuple> aPrincipalTuple);
Expand Down
10 changes: 5 additions & 5 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,13 +2373,13 @@ void CanonicalBrowsingContext::SynchronizeLayoutHistoryState() {
cp->SendGetLayoutHistoryState(this)->Then(
GetCurrentSerialEventTarget(), __func__,
[activeEntry = mActiveEntry](
const Tuple<RefPtr<nsILayoutHistoryState>, Maybe<Wireframe>>&
const std::tuple<RefPtr<nsILayoutHistoryState>, Maybe<Wireframe>>&
aResult) {
if (mozilla::Get<0>(aResult)) {
activeEntry->SetLayoutHistoryState(mozilla::Get<0>(aResult));
if (std::get<0>(aResult)) {
activeEntry->SetLayoutHistoryState(std::get<0>(aResult));
}
if (mozilla::Get<1>(aResult)) {
activeEntry->SetWireframe(mozilla::Get<1>(aResult));
if (std::get<1>(aResult)) {
activeEntry->SetWireframe(std::get<1>(aResult));
}
},
[]() {});
Expand Down
20 changes: 10 additions & 10 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "mozilla/StorageAccess.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Tuple.h"

#include "mozilla/Unused.h"
#include "mozilla/WidgetUtils.h"

Expand Down Expand Up @@ -4089,8 +4089,8 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
mBrowsingContext, forceReload,
[docShell, doc, loadType, browsingContext, currentURI, referrerInfo,
loadGroup, stopDetector](
Tuple<bool, Maybe<NotNull<RefPtr<nsDocShellLoadState>>>,
Maybe<bool>>&& aResult) {
std::tuple<bool, Maybe<NotNull<RefPtr<nsDocShellLoadState>>>,
Maybe<bool>>&& aResult) {
auto scopeExit = MakeScopeExit([loadGroup, stopDetector]() {
if (loadGroup) {
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
Expand All @@ -4109,7 +4109,7 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
Maybe<NotNull<RefPtr<nsDocShellLoadState>>> loadState;
Maybe<bool> reloadingActiveEntry;

Tie(canReload, loadState, reloadingActiveEntry) = aResult;
std::tie(canReload, loadState, reloadingActiveEntry) = aResult;

if (!canReload) {
return;
Expand Down Expand Up @@ -5297,7 +5297,7 @@ static const char16_t* SkipASCIIWhitespace(const char16_t* aStart,
return iter;
}

static Tuple<const char16_t*, const char16_t*> ExtractURLString(
static std::tuple<const char16_t*, const char16_t*> ExtractURLString(
const char16_t* aPosition, const char16_t* aEnd) {
MOZ_ASSERT(aPosition != aEnd);

Expand All @@ -5316,7 +5316,7 @@ static Tuple<const char16_t*, const char16_t*> ExtractURLString(
// U+0072 (r), then advance position to the next code point.
// Otherwise, jump to the step labeled parse.
if (aPosition == aEnd || (*aPosition != 'R' && *aPosition != 'r')) {
return MakeTuple(urlStart, urlEnd);
return std::make_tuple(urlStart, urlEnd);
}

++aPosition;
Expand All @@ -5325,7 +5325,7 @@ static Tuple<const char16_t*, const char16_t*> ExtractURLString(
// U+006C (l), then advance position to the next code point.
// Otherwise, jump to the step labeled parse.
if (aPosition == aEnd || (*aPosition != 'L' && *aPosition != 'l')) {
return MakeTuple(urlStart, urlEnd);
return std::make_tuple(urlStart, urlEnd);
}

++aPosition;
Expand All @@ -5337,7 +5337,7 @@ static Tuple<const char16_t*, const char16_t*> ExtractURLString(
// then advance position to the next code point. Otherwise, jump to
// the step labeled parse.
if (aPosition == aEnd || *aPosition != '=') {
return MakeTuple(urlStart, urlEnd);
return std::make_tuple(urlStart, urlEnd);
}

++aPosition;
Expand Down Expand Up @@ -5371,7 +5371,7 @@ static Tuple<const char16_t*, const char16_t*> ExtractURLString(
urlEnd = quotePos;
}

return MakeTuple(urlStart, urlEnd);
return std::make_tuple(urlStart, urlEnd);
}

void nsDocShell::SetupRefreshURIFromHeader(Document* aDocument,
Expand Down Expand Up @@ -5467,7 +5467,7 @@ void nsDocShell::SetupRefreshURIFromHeader(Document* aDocument,
const char16_t* urlEnd;

// 1-10. See ExtractURLString.
Tie(urlStart, urlEnd) = ExtractURLString(position, end);
std::tie(urlStart, urlEnd) = ExtractURLString(position, end);

// 11. Parse: Parse urlString relative to document. If that fails, return.
// Otherwise, set urlRecord to the resulting URL record.
Expand Down
14 changes: 7 additions & 7 deletions docshell/shistory/SessionHistoryEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "nsXULAppAPI.h"
#include "mozilla/PresState.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/Tuple.h"

#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
Expand Down Expand Up @@ -1521,15 +1521,15 @@ void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
const dom::SessionHistoryInfo& aParam) {
nsCOMPtr<nsIInputStream> postData = aParam.GetPostData();

Maybe<Tuple<uint32_t, dom::ClonedMessageData>> stateData;
Maybe<std::tuple<uint32_t, dom::ClonedMessageData>> stateData;
if (aParam.mStateData) {
stateData.emplace();
// FIXME: We should fail more aggressively if this fails, as currently we'll
// just early return and the deserialization will break.
NS_ENSURE_SUCCESS_VOID(
aParam.mStateData->GetFormatVersion(&Get<0>(*stateData)));
aParam.mStateData->GetFormatVersion(&std::get<0>(*stateData)));
NS_ENSURE_TRUE_VOID(
aParam.mStateData->BuildClonedMessageData(Get<1>(*stateData)));
aParam.mStateData->BuildClonedMessageData(std::get<1>(*stateData)));
}

WriteIPDLParam(aWriter, aActor, aParam.mURI);
Expand Down Expand Up @@ -1572,7 +1572,7 @@ void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
IPC::MessageReader* aReader, IProtocol* aActor,
dom::SessionHistoryInfo* aResult) {
Maybe<Tuple<uint32_t, dom::ClonedMessageData>> stateData;
Maybe<std::tuple<uint32_t, dom::ClonedMessageData>> stateData;
uint64_t sharedId;
if (!ReadIPDLParam(aReader, aActor, &aResult->mURI) ||
!ReadIPDLParam(aReader, aActor, &aResult->mOriginalURI) ||
Expand Down Expand Up @@ -1679,9 +1679,9 @@ bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
}

if (stateData.isSome()) {
uint32_t version = Get<0>(*stateData);
uint32_t version = std::get<0>(*stateData);
aResult->mStateData = new nsStructuredCloneContainer(version);
aResult->mStateData->StealFromClonedMessageData(Get<1>(*stateData));
aResult->mStateData->StealFromClonedMessageData(std::get<1>(*stateData));
}
MOZ_ASSERT_IF(stateData.isNothing(), !aResult->mStateData);
return true;
Expand Down
6 changes: 3 additions & 3 deletions dom/base/ChromeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,10 +1806,10 @@ already_AddRefed<Promise> ChromeUtils::CollectScrollingData(

extPromise->Then(
GetCurrentSerialEventTarget(), __func__,
[promise](const Tuple<uint32_t, uint32_t>& aResult) {
[promise](const std::tuple<uint32_t, uint32_t>& aResult) {
InteractionData out = {};
out.mInteractionTimeInMilliseconds = Get<0>(aResult);
out.mScrollingDistanceInPixels = Get<1>(aResult);
out.mInteractionTimeInMilliseconds = std::get<0>(aResult);
out.mScrollingDistanceInPixels = std::get<1>(aResult);
promise->MaybeResolve(out);
},
[promise](bool aValue) { promise->MaybeReject(NS_ERROR_FAILURE); });
Expand Down
21 changes: 10 additions & 11 deletions dom/base/ScrollingMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ ScrollingMetrics* ScrollingMetrics::GetSingleton() {
}

struct ScrollingMetricsCollector {
void AppendScrollingMetrics(const Tuple<uint32_t, uint32_t>& aMetrics,
void AppendScrollingMetrics(const std::tuple<uint32_t, uint32_t>& aMetrics,
dom::ContentParent* aParent) {
mTimeScrolledMS += Get<0>(aMetrics);
mDistanceScrolledPixels += Get<1>(aMetrics);
mTimeScrolledMS += std::get<0>(aMetrics);
mDistanceScrolledPixels += std::get<1>(aMetrics);
}

~ScrollingMetricsCollector() {
mPromiseHolder.Resolve(MakeTuple(mTimeScrolledMS, mDistanceScrolledPixels),
__func__);
mPromiseHolder.Resolve(
std::make_tuple(mTimeScrolledMS, mDistanceScrolledPixels), __func__);
}

uint32_t mTimeScrolledMS = 0;
Expand All @@ -101,8 +101,7 @@ auto ScrollingMetrics::CollectScrollingMetricsInternal()
for (dom::ContentParent* parent : contentParents) {
RefPtr<dom::ContentParent> parentRef = parent;
parent->SendCollectScrollingMetrics(
[collector,
parentRef](const mozilla::Tuple<uint32_t, uint32_t>& aMetrics) {
[collector, parentRef](const std::tuple<uint32_t, uint32_t>& aMetrics) {
collector->AppendScrollingMetrics(aMetrics, parentRef.get());
},
[](mozilla::ipc::ResponseRejectReason) {});
Expand All @@ -111,13 +110,13 @@ auto ScrollingMetrics::CollectScrollingMetricsInternal()
return collector->mPromiseHolder.Ensure(__func__);
}

Tuple<uint32_t, uint32_t>
std::tuple<uint32_t, uint32_t>
ScrollingMetrics::CollectLocalScrollingMetricsInternal() {
OnScrollingInteractionEnded();

Tuple<uint32_t, uint32_t> metrics =
MakeTuple(gScrollingInteraction.mInteractionTimeInMilliseconds,
gScrollingInteraction.mScrollingDistanceInPixels);
std::tuple<uint32_t, uint32_t> metrics =
std::make_tuple(gScrollingInteraction.mInteractionTimeInMilliseconds,
gScrollingInteraction.mScrollingDistanceInPixels);
gScrollingInteraction = {};
return metrics;
}
Expand Down
6 changes: 3 additions & 3 deletions dom/base/ScrollingMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace mozilla {
class ScrollingMetrics {
public:
using ScrollingMetricsPromise =
MozPromise<Tuple<uint32_t, uint32_t>, bool, true>;
MozPromise<std::tuple<uint32_t, uint32_t>, bool, true>;

static RefPtr<ScrollingMetricsPromise> CollectScrollingMetrics() {
return GetSingleton()->CollectScrollingMetricsInternal();
}

// Return the tuple of <scrollingTimeInMilliseconds,
// ScrollingDistanceInPixels>
static Tuple<uint32_t, uint32_t> CollectLocalScrollingMetrics() {
static std::tuple<uint32_t, uint32_t> CollectLocalScrollingMetrics() {
return GetSingleton()->CollectLocalScrollingMetricsInternal();
}

Expand All @@ -43,7 +43,7 @@ class ScrollingMetrics {
static ScrollingMetrics* GetSingleton();
static StaticAutoPtr<ScrollingMetrics> sSingleton;
RefPtr<ScrollingMetricsPromise> CollectScrollingMetricsInternal();
Tuple<uint32_t, uint32_t> CollectLocalScrollingMetricsInternal();
std::tuple<uint32_t, uint32_t> CollectLocalScrollingMetricsInternal();
};

} // namespace mozilla
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsJSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ inline bool AssignJSString(JSContext* cx, T& dest, JSString* s) {

size_t read;
size_t written;
Tie(read, written) = *maybe;
std::tie(read, written) = *maybe;

MOZ_ASSERT(read == JS::GetStringLength(s));
handle.Finish(written, kAllowShrinking);
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/IterableIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline void ResolvePromiseForFinished(Promise* aPromise) {
template <typename Key, typename Value>
void ResolvePromiseWithKeyAndValue(Promise* aPromise, const Key& aKey,
const Value& aValue) {
aPromise->MaybeResolve(MakeTuple(aKey, aValue));
aPromise->MaybeResolve(std::make_tuple(aKey, aValue));
}

} // namespace iterator_utils
Expand Down
8 changes: 5 additions & 3 deletions dom/bindings/ToJSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ template <typename T>
// Accept tuple of other things we accept. The result will be a JS array object.
template <typename... Elements>
[[nodiscard]] bool ToJSValue(JSContext* aCx,
const Tuple<Elements...>& aArguments,
const std::tuple<Elements...>& aArguments,
JS::MutableHandle<JS::Value> aValue) {
// Make sure we're called in a compartment
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
Expand All @@ -420,9 +420,11 @@ template <typename... Elements>
}
bool ok = true;
size_t i = 0;
ForEach(aArguments, [aCx, &ok, &v, &i](auto& aElem) {
auto Callable = [aCx, &ok, &v, &i](auto& aElem) {
ok = ok && ToJSValue(aCx, aElem, v[i++]);
});
};
std::apply([Callable](auto&&... args) { (Callable(args), ...); }, aArguments);

if (!ok) {
return false;
}
Expand Down
Loading

0 comments on commit 4efa1bd

Please sign in to comment.