Move some single-use CJX_Object property getters to subclasses.

Also remove uninstantiated CJX_Image class, and call common methods
directly.

Change-Id: I40925597795420fc783b9c61d1e3f0e044a0be96
Reviewed-on: https://pdfium-review.googlesource.com/c/50530
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index af81d21..cb0dd1b 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -179,8 +179,6 @@
         "xfa/cjx_handler.h",
         "xfa/cjx_hostpseudomodel.cpp",
         "xfa/cjx_hostpseudomodel.h",
-        "xfa/cjx_image.cpp",
-        "xfa/cjx_image.h",
         "xfa/cjx_instancemanager.cpp",
         "xfa/cjx_instancemanager.h",
         "xfa/cjx_integer.cpp",
diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp
index d2ed193..cb68916 100644
--- a/fxjs/xfa/cjx_exclgroup.cpp
+++ b/fxjs/xfa/cjx_exclgroup.cpp
@@ -159,6 +159,13 @@
   ScriptSomBorderWidth(pValue, bSetting, eAttribute);
 }
 
+void CJX_ExclGroup::errorText(CFXJSE_Value* pValue,
+                              bool bSetting,
+                              XFA_Attribute eAttribute) {
+  if (bSetting)
+    ThrowInvalidPropertyException();
+}
+
 void CJX_ExclGroup::fillColor(CFXJSE_Value* pValue,
                               bool bSetting,
                               XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_exclgroup.h b/fxjs/xfa/cjx_exclgroup.h
index 0fa3fc6..f71bb5f 100644
--- a/fxjs/xfa/cjx_exclgroup.h
+++ b/fxjs/xfa/cjx_exclgroup.h
@@ -29,6 +29,7 @@
   JSE_PROP(defaultValue); /* {default} */
   JSE_PROP(borderColor);
   JSE_PROP(borderWidth);
+  JSE_PROP(errorText);
   JSE_PROP(fillColor);
   JSE_PROP(mandatory);
   JSE_PROP(mandatoryMessage);
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index 7f0d05f..53cf91b 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -333,6 +333,22 @@
       node->GetValue(XFA_VALUEPICTURE_Display).ToUTF8().AsStringView());
 }
 
+void CJX_Field::length(CFXJSE_Value* pValue,
+                       bool bSetting,
+                       XFA_Attribute eAttribute) {
+  if (bSetting) {
+    ThrowInvalidPropertyException();
+    return;
+  }
+
+  CXFA_Node* node = GetXFANode();
+  if (!node->IsWidgetReady()) {
+    pValue->SetInteger(0);
+    return;
+  }
+  pValue->SetInteger(node->CountChoiceListItems(true));
+}
+
 void CJX_Field::parentSubform(CFXJSE_Value* pValue,
                               bool bSetting,
                               XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_field.h b/fxjs/xfa/cjx_field.h
index 182c592..cceaea3 100644
--- a/fxjs/xfa/cjx_field.h
+++ b/fxjs/xfa/cjx_field.h
@@ -41,6 +41,7 @@
   JSE_PROP(fontColor);
   JSE_PROP(formatMessage);
   JSE_PROP(formattedValue);
+  JSE_PROP(length);
   JSE_PROP(mandatory);
   JSE_PROP(mandatoryMessage);
   JSE_PROP(parentSubform);
diff --git a/fxjs/xfa/cjx_form.cpp b/fxjs/xfa/cjx_form.cpp
index c67688b..0a65286 100644
--- a/fxjs/xfa/cjx_form.cpp
+++ b/fxjs/xfa/cjx_form.cpp
@@ -126,3 +126,16 @@
                                                false, true);
   return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
 }
+
+void CJX_Form::checksumS(CFXJSE_Value* pValue,
+                         bool bSetting,
+                         XFA_Attribute eAttribute) {
+  if (bSetting) {
+    SetAttribute(XFA_Attribute::Checksum, pValue->ToWideString().AsStringView(),
+                 false);
+    return;
+  }
+
+  Optional<WideString> checksum = TryAttribute(XFA_Attribute::Checksum, false);
+  pValue->SetString(checksum ? checksum->ToUTF8().AsStringView() : "");
+}
diff --git a/fxjs/xfa/cjx_form.h b/fxjs/xfa/cjx_form.h
index 0968c55..c7b1ce3 100644
--- a/fxjs/xfa/cjx_form.h
+++ b/fxjs/xfa/cjx_form.h
@@ -27,6 +27,8 @@
   JSE_METHOD(recalculate);
   JSE_METHOD(remerge);
 
+  JSE_PROP(checksumS);
+
  private:
   using Type__ = CJX_Form;
   using ParentType__ = CJX_Model;
diff --git a/fxjs/xfa/cjx_image.cpp b/fxjs/xfa/cjx_image.cpp
deleted file mode 100644
index 794f353..0000000
--- a/fxjs/xfa/cjx_image.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "fxjs/xfa/cjx_image.h"
-
-#include "xfa/fxfa/parser/cxfa_image.h"
-
-CJX_Image::CJX_Image(CXFA_Image* node) : CJX_Node(node) {}
-
-CJX_Image::~CJX_Image() = default;
-
-bool CJX_Image::DynamicTypeIs(TypeTag eType) const {
-  return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
-}
-
-void CJX_Image::defaultValue(CFXJSE_Value* pValue,
-                             bool bSetting,
-                             XFA_Attribute eAttribute) {
-  ScriptSomDefaultValue_Read(pValue, bSetting, eAttribute);
-}
-
-void CJX_Image::value(CFXJSE_Value* pValue,
-                      bool bSetting,
-                      XFA_Attribute eAttribute) {
-  ScriptSomDefaultValue_Read(pValue, bSetting, eAttribute);
-}
diff --git a/fxjs/xfa/cjx_image.h b/fxjs/xfa/cjx_image.h
deleted file mode 100644
index ad9a113..0000000
--- a/fxjs/xfa/cjx_image.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJS_XFA_CJX_IMAGE_H_
-#define FXJS_XFA_CJX_IMAGE_H_
-
-#include "fxjs/xfa/cjx_node.h"
-#include "fxjs/xfa/jse_define.h"
-
-class CXFA_Image;
-
-class CJX_Image final : public CJX_Node {
- public:
-  explicit CJX_Image(CXFA_Image* node);
-  ~CJX_Image() override;
-
-  // CJX_Object:
-  bool DynamicTypeIs(TypeTag eType) const override;
-
-  JSE_PROP(defaultValue); /* {default} */
-  JSE_PROP(value);
-
- private:
-  using Type__ = CJX_Image;
-  using ParentType__ = CJX_Node;
-
-  static const TypeTag static_type__ = TypeTag::Image;
-};
-
-#endif  // FXJS_XFA_CJX_IMAGE_H_
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 5cec0c7..860a612 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -1393,22 +1393,6 @@
   ScriptSomMessage(pValue, bSetting, XFA_SOM_MandatoryMessage);
 }
 
-void CJX_Object::ScriptFieldLength(CFXJSE_Value* pValue,
-                                   bool bSetting,
-                                   XFA_Attribute eAttribute) {
-  if (bSetting) {
-    ThrowInvalidPropertyException();
-    return;
-  }
-
-  CXFA_Node* node = ToNode(object_.Get());
-  if (!node->IsWidgetReady()) {
-    pValue->SetInteger(0);
-    return;
-  }
-  pValue->SetInteger(node->CountChoiceListItems(true));
-}
-
 void CJX_Object::ScriptSomDefaultValue(CFXJSE_Value* pValue,
                                        bool bSetting,
                                        XFA_Attribute /* unused */) {
@@ -1571,57 +1555,7 @@
   }
 }
 
-void CJX_Object::ScriptSubformInstanceManager(CFXJSE_Value* pValue,
-                                              bool bSetting,
-                                              XFA_Attribute eAttribute) {
-  if (bSetting) {
-    ThrowInvalidPropertyException();
-    return;
-  }
-
-  WideString wsName = GetCData(XFA_Attribute::Name);
-  CXFA_Node* pInstanceMgr = nullptr;
-  for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetPrevSibling(); pNode;
-       pNode = pNode->GetPrevSibling()) {
-    if (pNode->GetElementType() == XFA_Element::InstanceManager) {
-      WideString wsInstMgrName =
-          pNode->JSObject()->GetCData(XFA_Attribute::Name);
-      if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' &&
-          wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) {
-        pInstanceMgr = pNode;
-      }
-      break;
-    }
-  }
-  if (!pInstanceMgr) {
-    pValue->SetNull();
-    return;
-  }
-
-  pValue->Assign(
-      GetDocument()->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
-}
-
 void CJX_Object::ScriptSubmitFormatMode(CFXJSE_Value* pValue,
                                         bool bSetting,
                                         XFA_Attribute eAttribute) {}
 
-void CJX_Object::ScriptFormChecksumS(CFXJSE_Value* pValue,
-                                     bool bSetting,
-                                     XFA_Attribute eAttribute) {
-  if (bSetting) {
-    SetAttribute(XFA_Attribute::Checksum, pValue->ToWideString().AsStringView(),
-                 false);
-    return;
-  }
-
-  Optional<WideString> checksum = TryAttribute(XFA_Attribute::Checksum, false);
-  pValue->SetString(checksum ? checksum->ToUTF8().AsStringView() : "");
-}
-
-void CJX_Object::ScriptExclGroupErrorText(CFXJSE_Value* pValue,
-                                          bool bSetting,
-                                          XFA_Attribute eAttribute) {
-  if (bSetting)
-    ThrowInvalidPropertyException();
-}
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index 48a1361..557e6a3 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -175,16 +175,12 @@
   JSE_PROP(ScriptSomBorderWidth);
   JSE_PROP(ScriptSomValidationMessage);
   JSE_PROP(ScriptSomMandatoryMessage);
-  JSE_PROP(ScriptFieldLength);
   JSE_PROP(ScriptSomDefaultValue);
   JSE_PROP(ScriptSomDefaultValue_Read);
   JSE_PROP(ScriptSomDataNode);
   JSE_PROP(ScriptSomMandatory);
   JSE_PROP(ScriptSomInstanceIndex);
-  JSE_PROP(ScriptSubformInstanceManager);
   JSE_PROP(ScriptSubmitFormatMode);
-  JSE_PROP(ScriptFormChecksumS);
-  JSE_PROP(ScriptExclGroupErrorText);
 
   void ScriptSomMessage(CFXJSE_Value* pValue,
                         bool bSetting,
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp
index ffe078f..4a5d00d 100644
--- a/fxjs/xfa/cjx_subform.cpp
+++ b/fxjs/xfa/cjx_subform.cpp
@@ -10,6 +10,7 @@
 
 #include "fxjs/cfx_v8.h"
 #include "fxjs/js_resources.h"
+#include "fxjs/xfa/cfxjse_engine.h"
 #include "fxjs/xfa/cfxjse_value.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
@@ -103,6 +104,37 @@
   ScriptSomInstanceIndex(pValue, bSetting, eAttribute);
 }
 
+void CJX_Subform::instanceManager(CFXJSE_Value* pValue,
+                                  bool bSetting,
+                                  XFA_Attribute eAttribute) {
+  if (bSetting) {
+    ThrowInvalidPropertyException();
+    return;
+  }
+
+  WideString wsName = GetCData(XFA_Attribute::Name);
+  CXFA_Node* pInstanceMgr = nullptr;
+  for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetPrevSibling(); pNode;
+       pNode = pNode->GetPrevSibling()) {
+    if (pNode->GetElementType() == XFA_Element::InstanceManager) {
+      WideString wsInstMgrName =
+          pNode->JSObject()->GetCData(XFA_Attribute::Name);
+      if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' &&
+          wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) {
+        pInstanceMgr = pNode;
+      }
+      break;
+    }
+  }
+  if (!pInstanceMgr) {
+    pValue->SetNull();
+    return;
+  }
+
+  pValue->Assign(
+      GetDocument()->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
+}
+
 void CJX_Subform::layout(CFXJSE_Value* pValue,
                          bool bSetting,
                          XFA_Attribute eAttribute) {
diff --git a/fxjs/xfa/cjx_subform.h b/fxjs/xfa/cjx_subform.h
index 9422e82..c921aa8 100644
--- a/fxjs/xfa/cjx_subform.h
+++ b/fxjs/xfa/cjx_subform.h
@@ -26,6 +26,7 @@
   JSE_METHOD(execValidate);
 
   JSE_PROP(instanceIndex);
+  JSE_PROP(instanceManager);
   JSE_PROP(layout);
   JSE_PROP(locale);
   JSE_PROP(validationMessage);
diff --git a/xfa/fxfa/parser/element_attributes.inc b/xfa/fxfa/parser/element_attributes.inc
index 2cce37b..4ae7468 100644
--- a/xfa/fxfa/parser/element_attributes.inc
+++ b/xfa/fxfa/parser/element_attributes.inc
@@ -179,7 +179,7 @@
 ELEM_ATTR____(Field, FormatMessage, CJX_Field::formatMessage)
 ELEM_ATTR____(Field, RawValue, CJX_Field::rawValue)
 ELEM_ATTR____(Field, DefaultValue, CJX_Field::defaultValue)
-ELEM_ATTR____(Field, Length, CJX_Object::ScriptFieldLength)
+ELEM_ATTR____(Field, Length, CJX_Field::length)
 ELEM_ATTR____(Field, ColSpan, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Field, Locale, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Field, AnchorType, CJX_Object::ScriptAttributeString)
@@ -208,7 +208,7 @@
 ELEM_ATTR____(ExclGroup, X, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(ExclGroup, Y, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(ExclGroup, HAlign, CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(ExclGroup, ErrorText, CJX_Object::ScriptExclGroupErrorText)
+ELEM_ATTR____(ExclGroup, ErrorText, CJX_ExclGroup::errorText)
 ELEM_ATTR____(ExclGroup, DataNode, CJX_Object::ScriptSomDataNode)
 ELEM_ATTR____(ExclGroup, Access, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(ExclGroup, FillColor, CJX_ExclGroup::fillColor)
@@ -238,9 +238,9 @@
 ELEM_ATTR____(DateTimeEdit, HScrollPolicy, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Image, ContentType, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Image, TransferEncoding, CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(Image, DefaultValue, CJX_Image::defaultValue)
+ELEM_ATTR____(Image, DefaultValue, CJX_Object::ScriptSomDefaultValue_Read)
 ELEM_ATTR____(Image, Aspect, CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(Image, Value, CJX_Image::value)
+ELEM_ATTR____(Image, Value, CJX_Object::ScriptSomDefaultValue_Read)
 ELEM_ATTR____(Image, Href, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(SharpxHTML, Value, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(TimeStamp, Type, CJX_Object::ScriptAttributeString)
@@ -270,7 +270,7 @@
 ELEM_ATTR____(Subform, Layout, CJX_Subform::layout)
 ELEM_ATTR____(Subform, Relevant, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Subform, MergeMode, CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(Subform, InstanceManager, CJX_Object::ScriptSubformInstanceManager)
+ELEM_ATTR____(Subform, InstanceManager, CJX_Subform::instanceManager)
 ELEM_ATTR____(Subform, ColSpan, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Subform, Locale, CJX_Subform::locale)
 ELEM_ATTR____(Subform, AnchorType, CJX_Object::ScriptAttributeString)
@@ -442,7 +442,7 @@
 ELEM_ATTR____(Font, Weight, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Font, UnderlinePeriod, CJX_Object::ScriptAttributeString)
 ELEM_ATTR____(Font, Overline, CJX_Object::ScriptAttributeString)
-ELEM_ATTR____(Form, Checksum, CJX_Object::ScriptFormChecksumS)
+ELEM_ATTR____(Form, Checksum, CJX_Form::checksumS)
 ELEM_ATTR____(Float, DefaultValue, CJX_Float::defaultValue)
 ELEM_ATTR____(Float, Value, CJX_Float::value)
 ELEM_ATTR____(Value, Relevant, CJX_Object::ScriptAttributeString)
diff --git a/xfa/fxfa/parser/xfa_basic_data.cpp b/xfa/fxfa/parser/xfa_basic_data.cpp
index 5976d73..ed8bd71 100644
--- a/xfa/fxfa/parser/xfa_basic_data.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data.cpp
@@ -26,9 +26,9 @@
 #include "fxjs/xfa/cjx_extras.h"
 #include "fxjs/xfa/cjx_field.h"
 #include "fxjs/xfa/cjx_float.h"
+#include "fxjs/xfa/cjx_form.h"
 #include "fxjs/xfa/cjx_handler.h"
 #include "fxjs/xfa/cjx_hostpseudomodel.h"
-#include "fxjs/xfa/cjx_image.h"
 #include "fxjs/xfa/cjx_instancemanager.h"
 #include "fxjs/xfa/cjx_integer.h"
 #include "fxjs/xfa/cjx_layoutpseudomodel.h"