[m125][ios] Don't set the pending messages counter when size is NaN

Some frameworks change the Array.forEach prototype in a way that
provides an undefined index as the 2nd argument in forEach(), which
results in setting `size` to NaN, which can't be parsed by the browser,
resulting a non-crashing dump.

(cherry picked from commit 781ab5e81142534fe31f32a1fe35828979ccb50d)

Change-Id: Ic0b9874808a1acaf4883220fda69686cac894d64
Bug: 40072641
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5488024
Reviewed-by: Ernesto Izquierdo Clua <eic@google.com>
Commit-Queue: Vincent Boisselle <vincb@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1292488}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5497855
Commit-Queue: Krishna Govind <govind@chromium.org>
Reviewed-by: Krishna Govind <govind@chromium.org>
Owners-Override: Krishna Govind <govind@chromium.org>
Cr-Commit-Position: refs/branch-heads/6422@{#473}
Cr-Branched-From: 9012208d0ce02e0cf0adb9b62558627c356f3278-refs/heads/main@{#1287751}
diff --git a/components/autofill/ios/form_util/resources/form_handlers.ts b/components/autofill/ios/form_util/resources/form_handlers.ts
index 538c7a1..7d00c14 100644
--- a/components/autofill/ios/form_util/resources/form_handlers.ts
+++ b/components/autofill/ios/form_util/resources/form_handlers.ts
@@ -224,11 +224,12 @@
       --numberOfPendingMessages;
       if (insertMetadata && numberOfPendingMessages === 0) {
         // Add the metadata.
+        const size = i + 1;
         msg = {
           ...msg,
           metadata: {
             dropCount: formMsgBatchMetadata.dropCount,
-            size: i + 1,
+            size: isNaN(size) ? null : size,
           },
         };