summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-25 16:59:38 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-25 16:59:38 +0000
commit1f7db295b1deeecb562d6213b3ea17b9168405eb (patch)
tree9e8ab0575b9acd207e8bcf8a7273aa2a4d0948bb
parent84d3394d88c42b798eedc938e6295ad1bf28ac66 (diff)
downloadpdfium-1f7db295b1deeecb562d6213b3ea17b9168405eb.tar.xz
Move CXFA_ThisProxy helper to CXFA_Object.
Because the other helpers are declared here. Rename VariablesThis to ThisProxy in a few places; VariablesThis is a slightly different concept (see GetVariablesThis()). Then introduce helper for CXFA_List subclass as well. Remove unused const version of some helpers. Change-Id: Ia328d8cd170a8b97015e98c1c770fa8a44810455 Reviewed-on: https://pdfium-review.googlesource.com/38670 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--fxjs/cfxjse_engine.cpp12
-rw-r--r--fxjs/xfa/cjx_list.cpp2
-rw-r--r--fxjs/xfa/cjx_node.cpp8
-rw-r--r--fxjs/xfa/cjx_node.h3
-rw-r--r--fxjs/xfa/cjx_treelist.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_object.cpp21
-rw-r--r--xfa/fxfa/parser/cxfa_object.h25
-rw-r--r--xfa/fxfa/parser/cxfa_thisproxy.cpp8
-rw-r--r--xfa/fxfa/parser/cxfa_thisproxy.h2
9 files changed, 41 insertions, 42 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index e297ed16e2..cc584a3fa3 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -67,9 +67,7 @@ const char kFormCalcRuntime[] = "pfm_rt";
CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue) {
CFXJSE_HostObject* pHostObject = pValue->ToHostObject();
- if (!pHostObject)
- return nullptr;
- return CXFA_ThisProxy::FromCXFAObject(pHostObject->AsCXFAObject());
+ return pHostObject ? ToThisProxy(pHostObject->AsCXFAObject()) : nullptr;
}
} // namespace
@@ -181,7 +179,7 @@ void CFXJSE_Engine::GlobalPropertySetter(CFXJSE_Value* pObject,
CXFA_Document* pDoc = lpOrginalNode->GetDocument();
CFXJSE_Engine* lpScriptContext = pDoc->GetScriptContext();
CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject());
- if (lpOrginalNode->IsVariablesThis())
+ if (lpOrginalNode->IsThisProxy())
pRefNode = ToNode(lpScriptContext->GetVariablesThis(lpOrginalNode));
WideString wsPropName = WideString::FromUTF8(szPropName);
@@ -193,7 +191,7 @@ void CFXJSE_Engine::GlobalPropertySetter(CFXJSE_Value* pObject,
true)) {
return;
}
- if (lpOrginalNode->IsVariablesThis()) {
+ if (lpOrginalNode->IsThisProxy()) {
if (pValue && pValue->IsUndefined()) {
pObject->SetObjectOwnProperty(szPropName, pValue);
return;
@@ -234,7 +232,7 @@ void CFXJSE_Engine::GlobalPropertyGetter(CFXJSE_Value* pObject,
}
CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject());
- if (pOriginalObject->IsVariablesThis())
+ if (pOriginalObject->IsThisProxy())
pRefNode = ToNode(lpScriptContext->GetVariablesThis(pOriginalObject));
if (lpScriptContext->QueryNodeByFlag(
@@ -473,7 +471,7 @@ CFXJSE_Context* CFXJSE_Engine::CreateVariablesContext(CXFA_Node* pScriptNode,
CXFA_Object* CFXJSE_Engine::GetVariablesThis(CXFA_Object* pObject,
bool bScriptNode) {
- CXFA_ThisProxy* pProxy = CXFA_ThisProxy::FromCXFAObject(pObject);
+ CXFA_ThisProxy* pProxy = ToThisProxy(pObject);
if (!pProxy)
return pObject;
diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp
index fcac45f58c..e56515d0b1 100644
--- a/fxjs/xfa/cjx_list.cpp
+++ b/fxjs/xfa/cjx_list.cpp
@@ -28,7 +28,7 @@ CJX_List::CJX_List(CXFA_List* list) : CJX_Object(list) {
CJX_List::~CJX_List() {}
CXFA_List* CJX_List::GetXFAList() {
- return static_cast<CXFA_List*>(GetXFAObject());
+ return ToList(GetXFAObject());
}
CJS_Return CJX_List::append(CFX_V8* runtime,
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index 856fea5267..efef5af87b 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -103,12 +103,8 @@ CJX_Node::CJX_Node(CXFA_Node* node) : CJX_Tree(node) {
CJX_Node::~CJX_Node() = default;
-CXFA_Node* CJX_Node::GetXFANode() {
- return static_cast<CXFA_Node*>(GetXFAObject());
-}
-
-const CXFA_Node* CJX_Node::GetXFANode() const {
- return static_cast<const CXFA_Node*>(GetXFAObject());
+CXFA_Node* CJX_Node::GetXFANode() const {
+ return ToNode(GetXFAObject());
}
CJS_Return CJX_Node::applyXSL(CFX_V8* runtime,
diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h
index 8d266424ab..af6800b5e5 100644
--- a/fxjs/xfa/cjx_node.h
+++ b/fxjs/xfa/cjx_node.h
@@ -38,8 +38,7 @@ class CJX_Node : public CJX_Tree {
JSE_PROP(ns);
JSE_PROP(oneOfChild);
- CXFA_Node* GetXFANode();
- const CXFA_Node* GetXFANode() const;
+ CXFA_Node* GetXFANode() const;
protected:
int32_t execSingleEventByName(const WideStringView& wsEventName,
diff --git a/fxjs/xfa/cjx_treelist.cpp b/fxjs/xfa/cjx_treelist.cpp
index b79b9e16b4..53c3ec1b54 100644
--- a/fxjs/xfa/cjx_treelist.cpp
+++ b/fxjs/xfa/cjx_treelist.cpp
@@ -25,7 +25,7 @@ CJX_TreeList::CJX_TreeList(CXFA_TreeList* list) : CJX_List(list) {
CJX_TreeList::~CJX_TreeList() {}
CXFA_TreeList* CJX_TreeList::GetXFATreeList() {
- return static_cast<CXFA_TreeList*>(GetXFAObject());
+ return ToTreeList(GetXFAObject());
}
CJS_Return CJX_TreeList::namedItem(
diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp
index 920e33860e..6daf3aa7b4 100644
--- a/xfa/fxfa/parser/cxfa_object.cpp
+++ b/xfa/fxfa/parser/cxfa_object.cpp
@@ -15,6 +15,7 @@
#include "xfa/fxfa/cxfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
+#include "xfa/fxfa/parser/cxfa_thisproxy.h"
#include "xfa/fxfa/parser/cxfa_treelist.h"
CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
@@ -43,6 +44,10 @@ WideString CXFA_Object::GetSOMExpression() {
return pScriptContext->GetSomExpression(ToNode(this));
}
+CXFA_List* CXFA_Object::AsList() {
+ return IsList() ? static_cast<CXFA_List*>(this) : nullptr;
+}
+
CXFA_Node* CXFA_Object::AsNode() {
return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr;
}
@@ -51,18 +56,22 @@ CXFA_TreeList* CXFA_Object::AsTreeList() {
return IsTreeList() ? static_cast<CXFA_TreeList*>(this) : nullptr;
}
-const CXFA_Node* CXFA_Object::AsNode() const {
- return IsNode() ? static_cast<const CXFA_Node*>(this) : nullptr;
+CXFA_ThisProxy* CXFA_Object::AsThisProxy() {
+ return IsThisProxy() ? static_cast<CXFA_ThisProxy*>(this) : nullptr;
}
-const CXFA_TreeList* CXFA_Object::AsTreeList() const {
- return IsTreeList() ? static_cast<const CXFA_TreeList*>(this) : nullptr;
+CXFA_List* ToList(CXFA_Object* pObj) {
+ return pObj ? pObj->AsList() : nullptr;
}
CXFA_Node* ToNode(CXFA_Object* pObj) {
return pObj ? pObj->AsNode() : nullptr;
}
-const CXFA_Node* ToNode(const CXFA_Object* pObj) {
- return pObj ? pObj->AsNode() : nullptr;
+CXFA_TreeList* ToTreeList(CXFA_Object* pObj) {
+ return pObj ? pObj->AsTreeList() : nullptr;
+}
+
+CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj) {
+ return pObj ? pObj->AsThisProxy() : nullptr;
}
diff --git a/xfa/fxfa/parser/cxfa_object.h b/xfa/fxfa/parser/cxfa_object.h
index 023516a05e..173bf23f25 100644
--- a/xfa/fxfa/parser/cxfa_object.h
+++ b/xfa/fxfa/parser/cxfa_object.h
@@ -24,12 +24,14 @@ enum class XFA_ObjectType {
TreeList,
ContainerNode,
ContentNode,
- VariablesThis
+ ThisProxy,
};
class CJX_Object;
class CXFA_Document;
+class CXFA_List;
class CXFA_Node;
+class CXFA_ThisProxy;
class CXFA_TreeList;
class CXFA_Object : public CFXJSE_HostObject {
@@ -42,6 +44,10 @@ class CXFA_Object : public CFXJSE_HostObject {
CXFA_Document* GetDocument() const { return m_pDocument.Get(); }
XFA_ObjectType GetObjectType() const { return m_objectType; }
+ bool IsList() const {
+ return m_objectType == XFA_ObjectType::List ||
+ m_objectType == XFA_ObjectType::TreeList;
+ }
bool IsNode() const {
return m_objectType == XFA_ObjectType::Node ||
m_objectType == XFA_ObjectType::NodeC ||
@@ -50,7 +56,7 @@ class CXFA_Object : public CFXJSE_HostObject {
m_objectType == XFA_ObjectType::TextNode ||
m_objectType == XFA_ObjectType::ContainerNode ||
m_objectType == XFA_ObjectType::ContentNode ||
- m_objectType == XFA_ObjectType::VariablesThis;
+ m_objectType == XFA_ObjectType::ThisProxy;
}
bool IsTreeList() const { return m_objectType == XFA_ObjectType::TreeList; }
bool IsContentNode() const {
@@ -61,15 +67,12 @@ class CXFA_Object : public CFXJSE_HostObject {
}
bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; }
bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; }
- bool IsVariablesThis() const {
- return m_objectType == XFA_ObjectType::VariablesThis;
- }
+ bool IsThisProxy() const { return m_objectType == XFA_ObjectType::ThisProxy; }
+ CXFA_List* AsList();
CXFA_Node* AsNode();
CXFA_TreeList* AsTreeList();
-
- const CXFA_Node* AsNode() const;
- const CXFA_TreeList* AsTreeList() const;
+ CXFA_ThisProxy* AsThisProxy();
CJX_Object* JSObject() { return m_pJSObject.get(); }
const CJX_Object* JSObject() const { return m_pJSObject.get(); }
@@ -99,11 +102,13 @@ class CXFA_Object : public CFXJSE_HostObject {
const XFA_Element m_elementType;
const uint32_t m_elementNameHash;
const WideStringView m_elementName;
-
std::unique_ptr<CJX_Object> m_pJSObject;
};
+// Helper functions that permit nullptr arguments.
+CXFA_List* ToList(CXFA_Object* pObj);
CXFA_Node* ToNode(CXFA_Object* pObj);
-const CXFA_Node* ToNode(const CXFA_Object* pObj);
+CXFA_TreeList* ToTreeList(CXFA_Object* pObj);
+CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj);
#endif // XFA_FXFA_PARSER_CXFA_OBJECT_H_
diff --git a/xfa/fxfa/parser/cxfa_thisproxy.cpp b/xfa/fxfa/parser/cxfa_thisproxy.cpp
index a3593e99b5..60a90b0931 100644
--- a/xfa/fxfa/parser/cxfa_thisproxy.cpp
+++ b/xfa/fxfa/parser/cxfa_thisproxy.cpp
@@ -10,15 +10,9 @@
#include "third_party/base/ptr_util.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-// static
-CXFA_ThisProxy* CXFA_ThisProxy::FromCXFAObject(CXFA_Object* that) {
- return that && that->IsVariablesThis() ? static_cast<CXFA_ThisProxy*>(that)
- : nullptr;
-}
-
CXFA_ThisProxy::CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode)
: CXFA_Object(pThisNode->GetDocument(),
- XFA_ObjectType::VariablesThis,
+ XFA_ObjectType::ThisProxy,
XFA_Element::Unknown,
WideStringView(),
pdfium::MakeUnique<CJX_Object>(this)),
diff --git a/xfa/fxfa/parser/cxfa_thisproxy.h b/xfa/fxfa/parser/cxfa_thisproxy.h
index e86a6b5534..197a97da67 100644
--- a/xfa/fxfa/parser/cxfa_thisproxy.h
+++ b/xfa/fxfa/parser/cxfa_thisproxy.h
@@ -13,8 +13,6 @@
class CXFA_ThisProxy : public CXFA_Object {
public:
- static CXFA_ThisProxy* FromCXFAObject(CXFA_Object* that);
-
CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode);
~CXFA_ThisProxy() override;