From 8eb2722e764fff0a39d0d1dc0c59473aa938b31f Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 14 Dec 2017 21:04:13 +0000 Subject: Add type information to CJX_Object::GetProperty This CL adds a type template to the CJX_Object::GetProperty method so we can have the correct types returned. Change-Id: Ieda8ec4bd31d26a1e71af30f08b48eb826f5993d Reviewed-on: https://pdfium-review.googlesource.com/21250 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fxjs/cfxjse_engine.cpp | 2 +- fxjs/cfxjse_resolveprocessor.cpp | 7 ++++--- fxjs/xfa/cjx_node.cpp | 8 ++++---- fxjs/xfa/cjx_object.cpp | 12 +++++++----- fxjs/xfa/cjx_object.h | 21 ++++++++++++++++++--- 5 files changed, 34 insertions(+), 16 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index a1c70a7d16..3def7f250f 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -352,7 +352,7 @@ void CFXJSE_Engine::NormalPropertySetter(CFXJSE_Value* pOriginalValue, CXFA_Node* pPropOrChild = nullptr; XFA_Element eType = CXFA_Node::NameToElement(wsPropName); if (eType != XFA_Element::Unknown) - pPropOrChild = pNode->JSObject()->GetProperty(0, eType, true); + pPropOrChild = pNode->JSObject()->GetProperty(0, eType, true); else pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringView()); diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp index 75c5eea6b5..beb0541a49 100644 --- a/fxjs/cfxjse_resolveprocessor.cpp +++ b/fxjs/cfxjse_resolveprocessor.cpp @@ -19,6 +19,7 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodehelper.h" #include "xfa/fxfa/parser/cxfa_object.h" +#include "xfa/fxfa/parser/cxfa_occur.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -345,13 +346,13 @@ bool CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { CXFA_Node* pInstanceManager = curNode->AsNode()->GetInstanceMgrOfSubform(); if (pInstanceManager) { - pProp = pInstanceManager->JSObject()->GetProperty(0, XFA_Element::Occur, - true); + pProp = pInstanceManager->JSObject()->GetProperty( + 0, XFA_Element::Occur, true); } } else { XFA_Element eType = CXFA_Node::NameToElement(wsName); if (eType != XFA_Element::Unknown) { - pProp = curNode->AsNode()->JSObject()->GetProperty( + pProp = curNode->AsNode()->JSObject()->GetProperty( 0, eType, eType != XFA_Element::PageSet); } } diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 1216177f02..e64f1fd5e7 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -163,8 +163,8 @@ CJS_Return CJX_Node::getElement( WideString expression = runtime->ToWideString(params[0]); int32_t iValue = params.size() >= 2 ? runtime->ToInt32(params[1]) : 0; - CXFA_Node* pNode = - GetProperty(iValue, CXFA_Node::NameToElement(expression), true); + CXFA_Node* pNode = GetProperty( + iValue, CXFA_Node::NameToElement(expression), true); CFXJSE_Value* value = GetDocument()->GetScriptContext()->GetJSValueFromMap(pNode); if (!value) @@ -186,12 +186,12 @@ CJS_Return CJX_Node::isPropertySpecified( bool bParent = params.size() < 2 || runtime->ToBoolean(params[1]); int32_t iIndex = params.size() == 3 ? runtime->ToInt32(params[2]) : 0; XFA_Element eType = CXFA_Node::NameToElement(expression); - bool bHas = !!GetProperty(iIndex, eType, true); + bool bHas = !!GetProperty(iIndex, eType, true); if (!bHas && bParent && GetXFANode()->GetParent()) { // Also check on the parent. auto* jsnode = GetXFANode()->GetParent()->JSObject(); bHas = jsnode->HasAttribute(attr) || - !!jsnode->GetProperty(iIndex, eType, true); + !!jsnode->GetProperty(iIndex, eType, true); } return CJS_Return(runtime->NewBoolean(bHas)); } diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index fcf77d434d..304b861dcf 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -619,7 +619,8 @@ bool CJX_Object::SetContent(const WideString& wsContent, switch (ToNode(GetXFAObject())->GetObjectType()) { case XFA_ObjectType::ContainerNode: { if (XFA_FieldIsMultiListBox(ToNode(GetXFAObject()))) { - CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true); + CXFA_Value* pValue = + GetProperty(0, XFA_Element::Value, true); if (!pValue) break; @@ -703,7 +704,8 @@ bool CJX_Object::SetContent(const WideString& wsContent, if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExclGroup) { pNode = ToNode(GetXFAObject()); } else { - CXFA_Node* pValue = GetProperty(0, XFA_Element::Value, true); + CXFA_Value* pValue = + GetProperty(0, XFA_Element::Value, true); if (!pValue) break; @@ -898,9 +900,9 @@ pdfium::Optional CJX_Object::TryNamespace() { return {static_cast(pXMLNode)->GetNamespaceURI()}; } -CXFA_Node* CJX_Object::GetProperty(int32_t index, - XFA_Element eProperty, - bool bCreateProperty) { +CXFA_Node* CJX_Object::GetPropertyInternal(int32_t index, + XFA_Element eProperty, + bool bCreateProperty) { if (index < 0 || index >= ToNode(GetXFAObject())->PropertyOccuranceCount(eProperty)) { return nullptr; diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index cf2ede7abf..f6ce3ccfb8 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -101,9 +101,10 @@ class CJX_Object { bool bSyncData); WideString GetContent(bool bScriptModify); - CXFA_Node* GetProperty(int32_t index, - XFA_Element eType, - bool bCreateProperty); + template + T* GetProperty(int32_t index, XFA_Element eType, bool bCreateProperty) { + return static_cast(GetPropertyInternal(index, eType, bCreateProperty)); + } void SetAttributeValue(const WideString& wsValue, const WideString& wsXMLValue, @@ -222,6 +223,20 @@ class CJX_Object { void ThrowException(const wchar_t* str, ...) const; private: + void Script_Boolean_DefaultValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Draw_DefaultValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_DefaultValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + CXFA_Node* GetPropertyInternal(int32_t index, + XFA_Element eType, + bool bCreateProperty); + void OnChanged(XFA_Attribute eAttr, bool bNotify, bool bScriptModify); void OnChanging(XFA_Attribute eAttr, bool bNotify); bool SetUserData(void* pKey, -- cgit v1.2.3