summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-06-02 17:45:25 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-02 17:45:25 -0700
commit8f3074bef53ed941daef3f32981b1449db7bcc26 (patch)
tree3d2aaca633cf24117bf2b3bfde236ec4047927d3 /xfa/fxfa/parser
parentdb444d2063df6c574882d9263e885c4fe1134133 (diff)
downloadpdfium-8f3074bef53ed941daef3f32981b1449db7bcc26.tar.xz
Remove FXJSE_Value_ToObject and call methods directly
This Cl removes the global FXJSE_Value_ToObject method and adds individual methods on CXFA_Value to do the needed conversions. Review-Url: https://codereview.chromium.org/2026993003
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_valuearray.cpp22
-rw-r--r--xfa/fxfa/parser/cxfa_valuearray.h23
-rw-r--r--xfa/fxfa/parser/xfa_script.h21
-rw-r--r--xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp14
-rw-r--r--xfa/fxfa/parser/xfa_script_imp.cpp37
-rw-r--r--xfa/fxfa/parser/xfa_script_imp.h2
6 files changed, 77 insertions, 42 deletions
diff --git a/xfa/fxfa/parser/cxfa_valuearray.cpp b/xfa/fxfa/parser/cxfa_valuearray.cpp
new file mode 100644
index 0000000000..face1b4cb4
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_valuearray.cpp
@@ -0,0 +1,22 @@
+// 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 "xfa/fxfa/parser/cxfa_valuearray.h"
+
+#include "xfa/fxfa/parser/xfa_script_imp.h"
+
+CXFA_ValueArray::CXFA_ValueArray(v8::Isolate* pIsolate)
+ : m_pIsolate(pIsolate) {}
+
+CXFA_ValueArray::~CXFA_ValueArray() {
+ for (int32_t i = 0; i < GetSize(); i++)
+ delete GetAt(i);
+}
+
+void CXFA_ValueArray::GetAttributeObject(CXFA_ObjArray& objArray) {
+ for (int32_t i = 0; i < GetSize(); i++)
+ objArray.Add(CXFA_ScriptContext::ToObject(GetAt(i), nullptr));
+}
diff --git a/xfa/fxfa/parser/cxfa_valuearray.h b/xfa/fxfa/parser/cxfa_valuearray.h
new file mode 100644
index 0000000000..b2825fa53a
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_valuearray.h
@@ -0,0 +1,23 @@
+// 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 XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_
+#define XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_
+
+#include "xfa/fxfa/include/fxfa.h"
+#include "xfa/fxjse/value.h"
+
+class CXFA_ValueArray : public CFX_ArrayTemplate<CFXJSE_Value*> {
+ public:
+ explicit CXFA_ValueArray(v8::Isolate* pIsolate);
+ ~CXFA_ValueArray();
+
+ void GetAttributeObject(CXFA_ObjArray& objArray);
+
+ v8::Isolate* const m_pIsolate;
+};
+
+#endif // XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_
diff --git a/xfa/fxfa/parser/xfa_script.h b/xfa/fxfa/parser/xfa_script.h
index da348f7a36..e81a7b9754 100644
--- a/xfa/fxfa/parser/xfa_script.h
+++ b/xfa/fxfa/parser/xfa_script.h
@@ -8,6 +8,7 @@
#define XFA_FXFA_PARSER_XFA_SCRIPT_H_
#include "xfa/fxfa/include/fxfa.h"
+#include "xfa/fxfa/parser/cxfa_valuearray.h"
#include "xfa/fxjse/value.h"
#define XFA_RESOLVENODE_Children 0x0001
@@ -36,26 +37,6 @@ enum XFA_RESOVENODE_RSTYPE {
XFA_RESOVENODE_RSTYPE_ExistNodes,
};
-class CXFA_ValueArray : public CFX_ArrayTemplate<CFXJSE_Value*> {
- public:
- CXFA_ValueArray(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
-
- ~CXFA_ValueArray() {
- for (int32_t i = 0; i < GetSize(); i++) {
- delete GetAt(i);
- }
- }
-
- void GetAttributeObject(CXFA_ObjArray& objArray) {
- for (int32_t i = 0; i < GetSize(); i++) {
- objArray.Add(
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(GetAt(i), nullptr)));
- }
- }
-
- v8::Isolate* m_pIsolate;
-};
-
struct XFA_RESOLVENODE_RS {
XFA_RESOLVENODE_RS()
: dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(NULL) {}
diff --git a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp
index 3b5f681a0f..3adabe6a6e 100644
--- a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp
+++ b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp
@@ -19,6 +19,14 @@
#include "xfa/fxfa/parser/xfa_utils.h"
#include "xfa/fxjse/cfxjse_arguments.h"
+namespace {
+
+CXFA_Node* ToNode(CFXJSE_Value* pValue, CFXJSE_Class* pClass) {
+ return static_cast<CXFA_Node*>(pValue->ToHostObject(pClass));
+}
+
+} // namespace
+
CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument)
: CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_HostPseudoModel) {
m_uScriptHash = XFA_HASHCODE_Host;
@@ -309,8 +317,7 @@ void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList(
if (iLength >= 1) {
std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0));
if (FXJSE_Value_IsObject(pValue.get())) {
- pNode =
- static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue.get(), nullptr));
+ pNode = ToNode(pValue.get(), nullptr);
} else if (FXJSE_Value_IsUTF8String(pValue.get())) {
CFX_ByteString bsString;
FXJSE_Value_ToUTF8String(pValue.get(), bsString);
@@ -507,8 +514,7 @@ void CScript_HostPseudoModel::Script_HostPseudoModel_SetFocus(
if (iLength >= 1) {
std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0));
if (FXJSE_Value_IsObject(pValue.get())) {
- pNode =
- static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue.get(), nullptr));
+ pNode = ToNode(pValue.get(), nullptr);
} else if (FXJSE_Value_IsUTF8String(pValue.get())) {
CFX_ByteString bsString;
FXJSE_Value_ToUTF8String(pValue.get(), bsString);
diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp
index 528758f6f8..55034a6399 100644
--- a/xfa/fxfa/parser/xfa_script_imp.cpp
+++ b/xfa/fxfa/parser/xfa_script_imp.cpp
@@ -66,8 +66,18 @@ const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = {
const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime";
+CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) {
+ return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass));
+}
+
} // namespace
+// static.
+CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue,
+ CFXJSE_Class* pClass) {
+ return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass));
+}
+
CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument)
: m_pDocument(pDocument),
m_pJsContext(nullptr),
@@ -147,8 +157,7 @@ FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType,
void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject,
const CFX_ByteStringC& szPropName,
CFXJSE_Value* pValue) {
- CXFA_Object* lpOrginalNode =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pObject, nullptr));
+ CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr);
CXFA_Document* pDoc = lpOrginalNode->GetDocument();
CXFA_ScriptContext* lpScriptContext =
(CXFA_ScriptContext*)pDoc->GetScriptContext();
@@ -204,8 +213,7 @@ FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode,
void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject,
const CFX_ByteStringC& szPropName,
CFXJSE_Value* pValue) {
- CXFA_Object* pOriginalObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pObject, nullptr));
+ CXFA_Object* pOriginalObject = ToObject(pObject, nullptr);
CXFA_Document* pDoc = pOriginalObject->GetDocument();
CXFA_ScriptContext* lpScriptContext =
(CXFA_ScriptContext*)pDoc->GetScriptContext();
@@ -259,8 +267,7 @@ void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject,
void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue,
const CFX_ByteStringC& szPropName,
CFXJSE_Value* pReturnValue) {
- CXFA_Object* pOriginalObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pOriginalValue, nullptr));
+ CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr);
if (!pOriginalObject) {
FXJSE_Value_SetUndefined(pReturnValue);
return;
@@ -305,8 +312,7 @@ void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue,
void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue,
const CFX_ByteStringC& szPropName,
CFXJSE_Value* pReturnValue) {
- CXFA_Object* pOriginalObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pOriginalValue, nullptr));
+ CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr);
if (!pOriginalObject)
return;
@@ -357,8 +363,7 @@ int32_t CXFA_ScriptContext::NormalPropTypeGetter(
CFXJSE_Value* pOriginalValue,
const CFX_ByteStringC& szPropName,
FX_BOOL bQueryIn) {
- CXFA_Object* pObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pOriginalValue, nullptr));
+ CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
if (!pObject)
return FXJSE_ClassPropType_None;
@@ -380,8 +385,7 @@ int32_t CXFA_ScriptContext::GlobalPropTypeGetter(
CFXJSE_Value* pOriginalValue,
const CFX_ByteStringC& szPropName,
FX_BOOL bQueryIn) {
- CXFA_Object* pObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pOriginalValue, nullptr));
+ CXFA_Object* pObject = ToObject(pOriginalValue, nullptr);
if (!pObject)
return FXJSE_ClassPropType_None;
@@ -398,8 +402,7 @@ int32_t CXFA_ScriptContext::GlobalPropTypeGetter(
void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis,
const CFX_ByteStringC& szFuncName,
CFXJSE_Arguments& args) {
- CXFA_Object* pObject =
- static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pThis, nullptr));
+ CXFA_Object* pObject = ToObject(pThis, nullptr);
if (!pObject)
return;
@@ -530,8 +533,7 @@ void CXFA_ScriptContext::ReleaseVariablesMap() {
m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext);
std::unique_ptr<CFXJSE_Value> pObject(
FXJSE_Context_GetGlobalObject(pVariableContext));
- delete static_cast<CXFA_ThisProxy*>(
- FXJSE_Value_ToObject(pObject.get(), nullptr));
+ delete ToThisProxy(pObject.get(), nullptr);
FXJSE_Context_Release(pVariableContext);
}
m_mapVariableToContext.RemoveAll();
@@ -653,8 +655,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
(rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))(
pValue.get(), FALSE,
(XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute);
- rndFind.m_Nodes.SetAt(0, static_cast<CXFA_Object*>(FXJSE_Value_ToObject(
- pValue.get(), nullptr)));
+ rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr));
}
int32_t iSize = m_upObjectArray.GetSize();
if (iSize) {
diff --git a/xfa/fxfa/parser/xfa_script_imp.h b/xfa/fxfa/parser/xfa_script_imp.h
index 91f5f0ab80..86d3f3703a 100644
--- a/xfa/fxfa/parser/xfa_script_imp.h
+++ b/xfa/fxfa/parser/xfa_script_imp.h
@@ -93,6 +93,8 @@ class CXFA_ScriptContext {
CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; }
CXFA_Document* GetDocument() const { return m_pDocument; }
+ static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass);
+
private:
void DefineJsContext();
CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode,