Remove class CPDF_DocJSActions.

It's just a nametree, and used only in one place, so put small
amout of code inline where it is used.  Avoid re-creation
of the nametree on each iteration in the process.

-- rename one method.

Change-Id: Id2266af431df6d9aadc76cdc791f4368552a25a3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65730
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/BUILD.gn b/core/fpdfdoc/BUILD.gn
index 3aa748e..f25ace9 100644
--- a/core/fpdfdoc/BUILD.gn
+++ b/core/fpdfdoc/BUILD.gn
@@ -31,8 +31,6 @@
     "cpdf_defaultappearance.h",
     "cpdf_dest.cpp",
     "cpdf_dest.h",
-    "cpdf_docjsactions.cpp",
-    "cpdf_docjsactions.h",
     "cpdf_filespec.cpp",
     "cpdf_filespec.h",
     "cpdf_formcontrol.cpp",
diff --git a/core/fpdfdoc/cpdf_docjsactions.cpp b/core/fpdfdoc/cpdf_docjsactions.cpp
deleted file mode 100644
index 2e6560b..0000000
--- a/core/fpdfdoc/cpdf_docjsactions.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2016 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 "core/fpdfdoc/cpdf_docjsactions.h"
-
-#include "core/fpdfapi/parser/cpdf_dictionary.h"
-#include "core/fpdfdoc/cpdf_nametree.h"
-
-CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {
-  ASSERT(m_pDocument);
-}
-
-CPDF_DocJSActions::~CPDF_DocJSActions() = default;
-
-int CPDF_DocJSActions::CountJSActions() const {
-  CPDF_NameTree name_tree(m_pDocument.Get(), "JavaScript");
-  return name_tree.GetCount();
-}
-
-CPDF_Action CPDF_DocJSActions::GetJSActionAndName(int index,
-                                                  WideString* csName) const {
-  CPDF_NameTree name_tree(m_pDocument.Get(), "JavaScript");
-  return CPDF_Action(ToDictionary(name_tree.LookupValueAndName(index, csName)));
-}
diff --git a/core/fpdfdoc/cpdf_docjsactions.h b/core/fpdfdoc/cpdf_docjsactions.h
deleted file mode 100644
index cad28e9..0000000
--- a/core/fpdfdoc/cpdf_docjsactions.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2016 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 CORE_FPDFDOC_CPDF_DOCJSACTIONS_H_
-#define CORE_FPDFDOC_CPDF_DOCJSACTIONS_H_
-
-#include "core/fpdfdoc/cpdf_action.h"
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/unowned_ptr.h"
-
-class CPDF_Document;
-
-class CPDF_DocJSActions {
- public:
-  explicit CPDF_DocJSActions(CPDF_Document* pDoc);
-  ~CPDF_DocJSActions();
-
-  int CountJSActions() const;
-  CPDF_Action GetJSActionAndName(int index, WideString* csName) const;
-  CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
-
- private:
-  UnownedPtr<CPDF_Document> const m_pDocument;
-};
-
-#endif  // CORE_FPDFDOC_CPDF_DOCJSACTIONS_H_
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 5f3b7e1..021ec60 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -12,7 +12,7 @@
 
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
-#include "core/fpdfdoc/cpdf_docjsactions.h"
+#include "core/fpdfdoc/cpdf_nametree.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "fpdfsdk/cpdfsdk_actionhandler.h"
 #include "fpdfsdk/cpdfsdk_annothandlermgr.h"
@@ -591,13 +591,13 @@
   return it != m_PageMap.end() ? it->second.get() : nullptr;
 }
 
-void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
-  CPDF_DocJSActions docJS(m_pCPDFDoc.Get());
-  int iCount = docJS.CountJSActions();
+void CPDFSDK_FormFillEnvironment::ProcJavascriptAction() {
+  CPDF_NameTree docJS(m_pCPDFDoc.Get(), "JavaScript");
+  int iCount = docJS.GetCount();
   for (int i = 0; i < iCount; i++) {
-    WideString csJSName;
-    CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName);
-    GetActionHandler()->DoAction_JavaScript(jsAction, csJSName, this);
+    WideString name;
+    CPDF_Action action(ToDictionary(docJS.LookupValueAndName(i, &name)));
+    GetActionHandler()->DoAction_JavaScript(action, name, this);
   }
 }
 
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index 99f98e7..ea67394 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -82,7 +82,7 @@
   void SetChangeMark() { m_bChangeMask = true; }
   void ClearChangeMark() { m_bChangeMask = false; }
 
-  void ProcJavascriptFun();
+  void ProcJavascriptAction();
   bool ProcOpenAction();
   void Invalidate(IPDF_Page* page, const FX_RECT& rect);
 
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 5f64337..a3f3022 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -651,7 +651,7 @@
   CPDFSDK_FormFillEnvironment* pFormFillEnv =
       CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle);
   if (pFormFillEnv && pFormFillEnv->IsJSPlatformPresent())
-    pFormFillEnv->ProcJavascriptFun();
+    pFormFillEnv->ProcJavascriptAction();
 }
 
 FPDF_EXPORT void FPDF_CALLCONV