Bug 1344830: Convert to range-based 'for' loops in U2F.cpp. r?jcj draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 06 Mar 2017 11:16:54 -0800
changeset 494181 f40b7a33ddc5941a8cd5b6fccd3b15a06db7724b
parent 494168 bb2103358f8447a56b59fa84ddb910cf1af6c581
child 548025 e9859b021850a882e48d8c1a60962235ed236379
push id47950
push userdholbert@mozilla.com
push dateMon, 06 Mar 2017 19:17:19 +0000
reviewersjcj
bugs1344830
milestone54.0a1
Bug 1344830: Convert to range-based 'for' loops in U2F.cpp. r?jcj MozReview-Commit-ID: 2PRQw4Pxquq
dom/u2f/U2F.cpp
--- a/dom/u2f/U2F.cpp
+++ b/dom/u2f/U2F.cpp
@@ -530,19 +530,17 @@ U2FRegisterRunnable::U2FRegisterRunnable
   // U2FRegisterCallback does not support threadsafe refcounting, and must be
   // used and destroyed on main.
   , mCallback(new nsMainThreadPtrHolder<U2FRegisterCallback>(aCallback))
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // The WebIDL dictionary types RegisterRequest and RegisteredKey cannot
   // be copied to this thread, so store them serialized.
-  for (size_t i = 0; i < aRegisterRequests.Length(); ++i) {
-    RegisterRequest req(aRegisterRequests[i]);
-
+  for (const RegisterRequest& req : aRegisterRequests) {
     // Check for required attributes
     if (!req.mChallenge.WasPassed() || !req.mVersion.WasPassed()) {
       continue;
     }
 
     LocalRegisterRequest localReq;
     localReq.mVersion = req.mVersion.Value();
     localReq.mChallenge = req.mChallenge.Value();
@@ -551,19 +549,17 @@ U2FRegisterRunnable::U2FRegisterRunnable
                                      localReq.mChallenge, localReq.mClientData);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       continue;
     }
 
     mRegisterRequests.AppendElement(localReq);
   }
 
-  for (size_t i = 0; i < aRegisteredKeys.Length(); ++i) {
-    RegisteredKey key(aRegisteredKeys[i]);
-
+  for (const RegisteredKey& key : aRegisteredKeys) {
     // Check for required attributes
     if (!key.mVersion.WasPassed() || !key.mKeyHandle.WasPassed()) {
       continue;
     }
 
     LocalRegisteredKey localKey;
     localKey.mVersion = key.mVersion.Value();
     localKey.mKeyHandle = key.mKeyHandle.Value();
@@ -619,20 +615,19 @@ U2FRegisterRunnable::Run()
   // Evaluate the AppID
   ErrorCode appIdResult = EvaluateAppID();
   if (appIdResult != ErrorCode::OK) {
     status->Stop(appIdResult);
   }
 
   // First, we must determine if any of the RegisteredKeys are already
   // registered, e.g., in the whitelist.
-  for (LocalRegisteredKey key: mRegisteredKeys) {
+  for (LocalRegisteredKey key : mRegisteredKeys) {
     nsTArray<RefPtr<U2FPrepPromise>> prepPromiseList;
-    for (size_t a = 0; a < mAuthenticators.Length(); ++a) {
-      Authenticator token(mAuthenticators[a]);
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FIsRegisteredTask> compTask =
         new U2FIsRegisteredTask(token, key, mAbstractMainThread);
       prepPromiseList.AppendElement(compTask->Execute());
     }
 
     // Treat each call to Promise::All as a work unit, as it completes together
     status->WaitGroupAdd();
 
@@ -699,18 +694,17 @@ U2FRegisterRunnable::Run()
     }
 
     srv = PK11_HashBuf(SEC_OID_SHA256, challengeParam.Elements(),
                        req.mClientData.Elements(), req.mClientData.Length());
     if (srv != SECSuccess) {
       continue;
     }
 
-    for (size_t a = 0; a < mAuthenticators.Length(); ++a) {
-      Authenticator token(mAuthenticators[a]);
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FRegisterTask> registerTask = new U2FRegisterTask(mOrigin, mAppId,
                                                                  token, appParam,
                                                                  challengeParam,
                                                                  req,
                                                                  mAbstractMainThread);
       status->WaitGroupAdd();
 
       registerTask->Execute()->Then(mAbstractMainThread, __func__,
@@ -769,19 +763,17 @@ U2FSignRunnable::U2FSignRunnable(const n
   , mAuthenticators(aAuthenticators)
   // U2FSignCallback does not support threadsafe refcounting, and must be used
   // and destroyed on main.
   , mCallback(new nsMainThreadPtrHolder<U2FSignCallback>(aCallback))
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Convert WebIDL objects to generic structs to pass between threads
-  for (size_t i = 0; i < aRegisteredKeys.Length(); ++i) {
-    RegisteredKey key(aRegisteredKeys[i]);
-
+  for (const RegisteredKey& key : aRegisteredKeys) {
     // Check for required attributes
     if (!key.mVersion.WasPassed() || !key.mKeyHandle.WasPassed()) {
       continue;
     }
 
     LocalRegisteredKey localKey;
     localKey.mVersion = key.mVersion.Value();
     localKey.mKeyHandle = key.mKeyHandle.Value();
@@ -884,19 +876,17 @@ U2FSignRunnable::Run()
     nsresult rv = keyHandle.FromJwkBase64(key.mKeyHandle);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       continue;
     }
 
     // We ignore mTransports, as it is intended to be used for sorting the
     // available devices by preference, but is not an exclusion factor.
 
-    for (size_t a = 0; a < mAuthenticators.Length() ; ++a) {
-      Authenticator token(mAuthenticators[a]);
-
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FSignTask> signTask = new U2FSignTask(mOrigin, mAppId,
                                                      key.mVersion, token,
                                                      appParam, challengeParam,
                                                      mClientData, keyHandle,
                                                      mAbstractMainThread);
       status->WaitGroupAdd();
 
       signTask->Execute()->Then(mAbstractMainThread, __func__,