Use spans in CJS_Object.

Avoid explicitly having to count items in arrays.

Change-Id: I24a91db45e8a8530f38afcc273e824ffb70a6cb9
Reviewed-on: https://pdfium-review.googlesource.com/34710
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp
index e47d189..8a53ebc 100644
--- a/fxjs/cjs_annot.cpp
+++ b/fxjs/cjs_annot.cpp
@@ -37,7 +37,7 @@
 void CJS_Annot::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Annot::kName, FXJSOBJTYPE_DYNAMIC,
                                  JSConstructor<CJS_Annot>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
 }
 
 CJS_Annot::CJS_Annot(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index e953f6b..61eb632 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -87,8 +87,8 @@
 void CJS_App::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_App::kName, FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_App>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_App::CJS_App(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_border.cpp b/fxjs/cjs_border.cpp
index 77d527d..b813cbb 100644
--- a/fxjs/cjs_border.cpp
+++ b/fxjs/cjs_border.cpp
@@ -19,7 +19,7 @@
 void CJS_Border::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("border", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Border::CJS_Border(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_color.cpp b/fxjs/cjs_color.cpp
index 282c58f..a730b2c 100644
--- a/fxjs/cjs_color.cpp
+++ b/fxjs/cjs_color.cpp
@@ -38,8 +38,8 @@
 void CJS_Color::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Color::kName, FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_Color>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 // static
diff --git a/fxjs/cjs_console.cpp b/fxjs/cjs_console.cpp
index 02babea..1ccf72f 100644
--- a/fxjs/cjs_console.cpp
+++ b/fxjs/cjs_console.cpp
@@ -25,7 +25,7 @@
 void CJS_Console::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Console::kName, FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_Console>, JSDestructor);
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_Console::CJS_Console(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_display.cpp b/fxjs/cjs_display.cpp
index 82f2f82..18ecde0 100644
--- a/fxjs/cjs_display.cpp
+++ b/fxjs/cjs_display.cpp
@@ -18,7 +18,7 @@
 void CJS_Display::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("display", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Display::CJS_Display(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 791e9bd..f562991 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -119,8 +119,8 @@
 void CJS_Document::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Document::kName, FXJSOBJTYPE_GLOBAL,
                                  JSConstructor<CJS_Document>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_Document::CJS_Document(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp
index 841d900..397d8b8 100644
--- a/fxjs/cjs_event.cpp
+++ b/fxjs/cjs_event.cpp
@@ -41,7 +41,7 @@
 void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_Event>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
 }
 
 CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index b3a9f53..2ed88ef 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -167,8 +167,8 @@
 void CJS_Field::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Field::kName, FXJSOBJTYPE_DYNAMIC,
                                  JSConstructor<CJS_Field>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_Field::CJS_Field(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_font.cpp b/fxjs/cjs_font.cpp
index 4d18eea..8594da7 100644
--- a/fxjs/cjs_font.cpp
+++ b/fxjs/cjs_font.cpp
@@ -27,7 +27,7 @@
 // static
 void CJS_Font::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj("font", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Font::CJS_Font(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index ffa30a5..977d916 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -195,7 +195,7 @@
 void CJS_Global::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj("global", FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_Global>, JSDestructor);
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
   DefineAllProperties(pEngine);
 }
 
diff --git a/fxjs/cjs_highlight.cpp b/fxjs/cjs_highlight.cpp
index c77a80d..5c95281 100644
--- a/fxjs/cjs_highlight.cpp
+++ b/fxjs/cjs_highlight.cpp
@@ -18,7 +18,7 @@
 void CJS_Highlight::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("highlight", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Highlight::CJS_Highlight(v8::Local<v8::Object> pObject,
diff --git a/fxjs/cjs_icon.cpp b/fxjs/cjs_icon.cpp
index 89b42f1..9cf20fe 100644
--- a/fxjs/cjs_icon.cpp
+++ b/fxjs/cjs_icon.cpp
@@ -21,7 +21,7 @@
 void CJS_Icon::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Icon::kName, FXJSOBJTYPE_DYNAMIC,
                                  JSConstructor<CJS_Icon>, JSDestructor);
-  DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
+  DefineProps(pEngine, ObjDefnID, PropertySpecs);
 }
 
 CJS_Icon::CJS_Icon(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_object.cpp b/fxjs/cjs_object.cpp
index 36fcc74..e30f6b4 100644
--- a/fxjs/cjs_object.cpp
+++ b/fxjs/cjs_object.cpp
@@ -9,35 +9,30 @@
 // static
 void CJS_Object::DefineConsts(CFXJS_Engine* pEngine,
                               int objId,
-                              const JSConstSpec consts[],
-                              size_t count) {
-  for (size_t i = 0; i < count; ++i) {
+                              pdfium::span<const JSConstSpec> consts) {
+  for (const auto& item : consts) {
     pEngine->DefineObjConst(
-        objId, consts[i].pName,
-        consts[i].eType == JSConstSpec::Number
-            ? pEngine->NewNumber(consts[i].number).As<v8::Value>()
-            : pEngine->NewString(consts[i].pStr).As<v8::Value>());
+        objId, item.pName,
+        item.eType == JSConstSpec::Number
+            ? pEngine->NewNumber(item.number).As<v8::Value>()
+            : pEngine->NewString(item.pStr).As<v8::Value>());
   }
 }
 
 // static
 void CJS_Object::DefineProps(CFXJS_Engine* pEngine,
                              int objId,
-                             const JSPropertySpec props[],
-                             size_t count) {
-  for (size_t i = 0; i < count; ++i) {
-    pEngine->DefineObjProperty(objId, props[i].pName, props[i].pPropGet,
-                               props[i].pPropPut);
-  }
+                             pdfium::span<const JSPropertySpec> props) {
+  for (const auto& item : props)
+    pEngine->DefineObjProperty(objId, item.pName, item.pPropGet, item.pPropPut);
 }
 
 // static
 void CJS_Object::DefineMethods(CFXJS_Engine* pEngine,
                                int objId,
-                               const JSMethodSpec methods[],
-                               size_t count) {
-  for (size_t i = 0; i < count; ++i)
-    pEngine->DefineObjMethod(objId, methods[i].pName, methods[i].pMethodCall);
+                               pdfium::span<const JSMethodSpec> methods) {
+  for (const auto& item : methods)
+    pEngine->DefineObjMethod(objId, item.pName, item.pMethodCall);
 }
 
 CJS_Object::CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_object.h b/fxjs/cjs_object.h
index c3766fc..70682cd 100644
--- a/fxjs/cjs_object.h
+++ b/fxjs/cjs_object.h
@@ -14,6 +14,7 @@
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "fxjs/cfxjs_engine.h"
 #include "fxjs/cjs_runtime.h"
+#include "third_party/base/span.h"
 
 struct JSConstSpec {
   enum Type { Number = 0, String = 1 };
@@ -39,16 +40,13 @@
  public:
   static void DefineConsts(CFXJS_Engine* pEngine,
                            int objId,
-                           const JSConstSpec consts[],
-                           size_t count);
+                           pdfium::span<const JSConstSpec> consts);
   static void DefineProps(CFXJS_Engine* pEngine,
                           int objId,
-                          const JSPropertySpec props[],
-                          size_t count);
+                          pdfium::span<const JSPropertySpec> consts);
   static void DefineMethods(CFXJS_Engine* pEngine,
                             int objId,
-                            const JSMethodSpec methods[],
-                            size_t count);
+                            pdfium::span<const JSMethodSpec> consts);
 
   CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
   virtual ~CJS_Object();
diff --git a/fxjs/cjs_position.cpp b/fxjs/cjs_position.cpp
index 0e1fa66..6269863 100644
--- a/fxjs/cjs_position.cpp
+++ b/fxjs/cjs_position.cpp
@@ -21,7 +21,7 @@
 void CJS_Position::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("position", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Position::CJS_Position(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_report.cpp b/fxjs/cjs_report.cpp
index eccba07..868e9c3 100644
--- a/fxjs/cjs_report.cpp
+++ b/fxjs/cjs_report.cpp
@@ -22,7 +22,7 @@
 void CJS_Report::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) {
   ObjDefnID = pEngine->DefineObj(CJS_Report::kName, eObjType,
                                  JSConstructor<CJS_Report>, JSDestructor);
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_Report::CJS_Report(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_scalehow.cpp b/fxjs/cjs_scalehow.cpp
index a29aa38..f284c24 100644
--- a/fxjs/cjs_scalehow.cpp
+++ b/fxjs/cjs_scalehow.cpp
@@ -16,7 +16,7 @@
 void CJS_ScaleHow::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("scaleHow", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_ScaleHow::CJS_ScaleHow(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_scalewhen.cpp b/fxjs/cjs_scalewhen.cpp
index 33f13cb..41dc41a 100644
--- a/fxjs/cjs_scalewhen.cpp
+++ b/fxjs/cjs_scalewhen.cpp
@@ -18,7 +18,7 @@
 void CJS_ScaleWhen::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("scaleWhen", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_ScaleWhen::CJS_ScaleWhen(v8::Local<v8::Object> pObject,
diff --git a/fxjs/cjs_style.cpp b/fxjs/cjs_style.cpp
index 2a172c9..89744a2 100644
--- a/fxjs/cjs_style.cpp
+++ b/fxjs/cjs_style.cpp
@@ -19,7 +19,7 @@
 // static
 void CJS_Style::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj("style", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Style::CJS_Style(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 0ff4083..576a85b 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -71,7 +71,7 @@
 void CJS_Util::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID = pEngine->DefineObj(CJS_Util::kName, FXJSOBJTYPE_STATIC,
                                  JSConstructor<CJS_Util>, JSDestructor);
-  DefineMethods(pEngine, ObjDefnID, MethodSpecs, FX_ArraySize(MethodSpecs));
+  DefineMethods(pEngine, ObjDefnID, MethodSpecs);
 }
 
 CJS_Util::CJS_Util(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
diff --git a/fxjs/cjs_zoomtype.cpp b/fxjs/cjs_zoomtype.cpp
index af56732..85a1b5d 100644
--- a/fxjs/cjs_zoomtype.cpp
+++ b/fxjs/cjs_zoomtype.cpp
@@ -21,7 +21,7 @@
 void CJS_Zoomtype::DefineJSObjects(CFXJS_Engine* pEngine) {
   ObjDefnID =
       pEngine->DefineObj("zoomtype", FXJSOBJTYPE_STATIC, nullptr, nullptr);
-  DefineConsts(pEngine, ObjDefnID, ConstSpecs, FX_ArraySize(ConstSpecs));
+  DefineConsts(pEngine, ObjDefnID, ConstSpecs);
 }
 
 CJS_Zoomtype::CJS_Zoomtype(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)