Remove IsArrayObject and IsDateObject methods

This CL removes the IsArrayObject and IsDateObject methods and asks the
v8 objects directly.

Change-Id: I4e2b957dbdfcddb426270f72666fce83854d92e0
Reviewed-on: https://pdfium-review.googlesource.com/16616
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 0ed0594..35b808c 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -879,7 +879,7 @@
   std::vector<uint32_t> array;
   if (vp.ToV8Value()->IsNumber()) {
     array.push_back(pRuntime->ToInt32(vp.ToV8Value()));
-  } else if (vp.IsArrayObject()) {
+  } else if (!vp.ToV8Value().IsEmpty() && vp.ToV8Value()->IsArray()) {
     CJS_Array SelArray(pRuntime->ToArray(vp.ToV8Value()));
     for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++)
       array.push_back(
@@ -1210,7 +1210,7 @@
     return false;
   }
 
-  return m_bCanSet && vp.IsArrayObject();
+  return m_bCanSet && !vp.ToV8Value().IsEmpty() && vp.ToV8Value()->IsArray();
 }
 
 bool Field::get_file_select(CJS_Runtime* pRuntime,
@@ -1297,7 +1297,7 @@
     return false;
   if (!m_bCanSet)
     return false;
-  if (!vp.IsArrayObject())
+  if (vp.ToV8Value().IsEmpty() || !vp.ToV8Value()->IsArray())
     return false;
   return true;
 }
@@ -1797,7 +1797,7 @@
                      WideString* sError) {
   if (!m_bCanSet)
     return false;
-  if (!vp.IsArrayObject())
+  if (vp.ToV8Value().IsEmpty() || !vp.ToV8Value()->IsArray())
     return false;
 
   CJS_Array rcArray(pRuntime->ToArray(vp.ToV8Value()));
@@ -2017,7 +2017,7 @@
                              WideString* sError) {
   if (!m_bCanSet)
     return false;
-  if (!vp.IsArrayObject())
+  if (vp.ToV8Value().IsEmpty() || !vp.ToV8Value()->IsArray())
     return false;
   return true;
 }
@@ -2131,7 +2131,7 @@
                            WideString* sError) {
   if (!m_bCanSet)
     return false;
-  if (!vp.IsArrayObject())
+  if (vp.ToV8Value().IsEmpty() || !vp.ToV8Value()->IsArray())
     return false;
   return true;
 }
@@ -2342,7 +2342,7 @@
     return false;
 
   std::vector<WideString> strArray;
-  if (vp.IsArrayObject()) {
+  if (!vp.ToV8Value().IsEmpty() && vp.ToV8Value()->IsArray()) {
     CJS_Array ValueArray(pRuntime->ToArray(vp.ToV8Value()));
     for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
       CJS_Value ElementValue(ValueArray.GetElement(pRuntime, i));
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index f535f69..9275de3 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -216,14 +216,6 @@
   m_pValue = num;
 }
 
-bool CJS_Value::IsArrayObject() const {
-  return !m_pValue.IsEmpty() && m_pValue->IsArray();
-}
-
-bool CJS_Value::IsDateObject() const {
-  return !m_pValue.IsEmpty() && m_pValue->IsDate();
-}
-
 CJS_Array::CJS_Array() {}
 
 CJS_Array::CJS_Array(v8::Local<v8::Array> pArray) : m_pArray(pArray) {}
@@ -436,7 +428,7 @@
     result[i] = originals[i];
 
   if (originals.size() != 1 || !originals[0].ToV8Value()->IsObject() ||
-      originals[0].IsArrayObject()) {
+      originals[0].ToV8Value()->IsArray()) {
     return result;
   }
   v8::Local<v8::Object> pObj = pRuntime->ToObject(originals[0].ToV8Value());
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 5e77e0b..ff3bf9c 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -33,9 +33,6 @@
   // to make one from the current |m_pValue|.
   void MaybeCoerceToNumber(CJS_Runtime* pRuntime);
 
-  bool IsArrayObject() const;
-  bool IsDateObject() const;
-
  private:
   v8::Local<v8::Value> m_pValue;
 };
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 68fc305..200e7d1 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -247,7 +247,7 @@
 
 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
                                                   CJS_Value val) {
-  if (val.IsArrayObject())
+  if (!val.ToV8Value().IsEmpty() && val.ToV8Value()->IsArray())
     return CJS_Array(pRuntime->ToArray(val.ToV8Value()));
 
   WideString wsStr = pRuntime->ToWideString(val.ToV8Value());
@@ -1675,7 +1675,8 @@
   }
 
   CJS_Value params1(params[1]);
-  if (!params1.IsArrayObject() && !params1.ToV8Value()->IsString()) {
+  if ((params[1].ToV8Value().IsEmpty() || !params[1].ToV8Value()->IsArray()) &&
+      !params1.ToV8Value()->IsString()) {
     sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
     return false;
   }
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index 26f28f5..cb07a0e 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -414,21 +414,17 @@
   }
 
   WideString swMsg;
-  if (newParams[0].ToV8Value()->IsObject()) {
-    if (newParams[0].IsArrayObject()) {
-      CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value()));
-      swMsg = L"[";
-      for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
-        if (i)
-          swMsg += L", ";
+  if (newParams[0].ToV8Value()->IsArray()) {
+    CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value()));
+    swMsg = L"[";
+    for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
+      if (i)
+        swMsg += L", ";
 
-        CJS_Value element(carray.GetElement(pRuntime, i));
-        swMsg += pRuntime->ToWideString(element.ToV8Value());
-      }
-      swMsg += L"]";
-    } else {
-      swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
+      CJS_Value element(carray.GetElement(pRuntime, i));
+      swMsg += pRuntime->ToWideString(element.ToV8Value());
     }
+    swMsg += L"]";
   } else {
     swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
   }
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index 56baa59..c095678 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -289,7 +289,7 @@
 bool color::SetPropertyHelper(CJS_Runtime* pRuntime,
                               const CJS_Value& vp,
                               CFX_Color* var) {
-  if (!vp.IsArrayObject())
+  if (vp.ToV8Value().IsEmpty() || !vp.ToV8Value()->IsArray())
     return false;
 
   *var = ConvertArrayToPWLColor(pRuntime,
@@ -304,7 +304,7 @@
   int iSize = params.size();
   if (iSize < 2)
     return false;
-  if (!params[0].IsArrayObject())
+  if (params[0].ToV8Value().IsEmpty() || !params[0].ToV8Value()->IsArray())
     return false;
 
   WideString sDestSpace = pRuntime->ToWideString(params[1].ToV8Value());
@@ -337,8 +337,10 @@
                   WideString& sError) {
   if (params.size() < 2)
     return false;
-  if (!params[0].IsArrayObject() || !params[1].IsArrayObject())
+  if (params[0].ToV8Value().IsEmpty() || !params[0].ToV8Value()->IsArray() ||
+      params[1].ToV8Value().IsEmpty() || !params[1].ToV8Value()->IsArray()) {
     return false;
+  }
 
   CFX_Color color1 = ConvertArrayToPWLColor(
       pRuntime, CJS_Array(pRuntime->ToArray(params[0].ToV8Value())));
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index 28ab0bb..4a7e148 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -149,12 +149,12 @@
 
   const CJS_Value& p1 = params[0];
   const CJS_Value& p2 = params[1];
-  if (!p2.IsDateObject()) {
+  if (p2.ToV8Value().IsEmpty() || !p2.ToV8Value()->IsDate()) {
     sError = JSGetStringFromID(IDS_STRING_JSPRINT1);
     return false;
   }
 
-  ASSERT(p2.IsDateObject());
+  ASSERT(!p2.ToV8Value().IsEmpty() && p2.ToV8Value()->IsDate());
   v8::Local<v8::Value> mutable_value = p2.ToV8Value();
   CJS_Date jsDate(mutable_value.As<v8::Date>());
   if (!jsDate.IsValidDate(pRuntime)) {