diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-13 18:29:02 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-13 18:29:02 +0000 |
commit | 2614250d4f11ed02033a7da095a1694ece12ab78 (patch) | |
tree | cc41c5770c17ea47537856991fa44cd1e2acfeb8 /fxjs/xfa | |
parent | 14768f3264a4cff8ca0096a27e41f1861b2c422b (diff) | |
download | pdfium-2614250d4f11ed02033a7da095a1694ece12ab78.tar.xz |
Methods are on CJX_Object not CJX_Node now
This CL converts all of the JSNode() to JSObject() calls as all of the
original CJX_Node methods have been moved to CJX_Object. This fixes
potential bad casts from things like CJX_Content which do not inhert
from CJX_Node.
Bug: pdfium:793372
Change-Id: I6c7f63a78f3d47bb6bad74faed3fd8c535bf095e
Reviewed-on: https://pdfium-review.googlesource.com/21090
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/xfa')
-rw-r--r-- | fxjs/xfa/cjx_layoutpseudomodel.cpp | 2 | ||||
-rw-r--r-- | fxjs/xfa/cjx_model.cpp | 4 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 9 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.h | 14 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.cpp | 71 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.h | 11 |
6 files changed, 55 insertions, 56 deletions
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index 4165a36e57..e3e0fea5f9 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp @@ -163,7 +163,7 @@ CJS_Return CJX_LayoutPseudoModel::NumberedPageCount(CJS_V8* runtime, continue; CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); - if (pMasterPage->JSNode()->GetInteger(XFA_Attribute::Numbered)) + if (pMasterPage->JSObject()->GetInteger(XFA_Attribute::Numbered)) iPageCount++; } } else { diff --git a/fxjs/xfa/cjx_model.cpp b/fxjs/xfa/cjx_model.cpp index 7ab90e29ba..4ac6280c44 100644 --- a/fxjs/xfa/cjx_model.cpp +++ b/fxjs/xfa/cjx_model.cpp @@ -55,8 +55,8 @@ CJS_Return CJX_Model::createNode( if (!pNewNode->HasAttribute(XFA_Attribute::Name)) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - pNewNode->JSNode()->SetAttribute(XFA_Attribute::Name, name.AsStringView(), - true); + pNewNode->JSObject()->SetAttribute(XFA_Attribute::Name, name.AsStringView(), + true); if (pNewNode->GetPacketType() == XFA_PacketType::Datasets) pNewNode->CreateXMLMappingNode(); } diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index cceaa208fc..b2743f0176 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -6,6 +6,9 @@ #include "fxjs/xfa/cjx_node.h" +#include <memory> +#include <vector> + #include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_codepage.h" #include "fxjs/cfxjse_engine.h" @@ -186,7 +189,7 @@ CJS_Return CJX_Node::isPropertySpecified( bool bHas = !!GetProperty(iIndex, eType, true); if (!bHas && bParent && GetXFANode()->GetParent()) { // Also check on the parent. - auto* jsnode = GetXFANode()->GetParent()->JSNode(); + auto* jsnode = GetXFANode()->GetParent()->JSObject(); bHas = jsnode->HasAttribute(attr) || !!jsnode->GetProperty(iIndex, eType, true); } @@ -227,8 +230,8 @@ CJS_Return CJX_Node::loadXML(CJS_V8* runtime, CXFA_Node* pFakeRoot = GetXFANode()->Clone(false); WideString wsContentType = GetCData(XFA_Attribute::ContentType); if (!wsContentType.IsEmpty()) { - pFakeRoot->JSNode()->SetCData(XFA_Attribute::ContentType, - WideString(wsContentType), false, false); + pFakeRoot->JSObject()->SetCData(XFA_Attribute::ContentType, + WideString(wsContentType), false, false); } std::unique_ptr<CFX_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode()); diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h index 9d16d852bf..f54239aa67 100644 --- a/fxjs/xfa/cjx_node.h +++ b/fxjs/xfa/cjx_node.h @@ -7,18 +7,12 @@ #ifndef FXJS_XFA_CJX_NODE_H_ #define FXJS_XFA_CJX_NODE_H_ -#include <memory> -#include <vector> - -#include "core/fxcrt/unowned_ptr.h" #include "fxjs/CJX_Define.h" #include "fxjs/xfa/cjx_object.h" #include "fxjs/xfa/cjx_tree.h" #include "xfa/fxfa/fxfa_basic.h" -class CXFA_LayoutItem; class CXFA_Node; -class CXFA_WidgetData; class CJX_Node : public CJX_Tree { public: @@ -28,12 +22,6 @@ class CJX_Node : public CJX_Tree { CXFA_Node* GetXFANode(); const CXFA_Node* GetXFANode() const; - void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; } - CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); } - - void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; } - size_t GetCalcRecursionCount() const { return calc_recursion_count_; } - JS_METHOD(applyXSL, CJX_Node); JS_METHOD(assignNode, CJX_Node); JS_METHOD(clone, CJX_Node); @@ -51,8 +39,6 @@ class CJX_Node : public CJX_Tree { XFA_Element eType); private: - UnownedPtr<CXFA_LayoutItem> layout_item_; - size_t calc_recursion_count_ = 0; static const CJX_MethodSpec MethodSpecs[]; }; diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 04d053ce38..fc708584d7 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -602,10 +602,10 @@ bool CJX_Object::SetContent(const WideString& wsContent, CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); ASSERT(pChildValue); - pChildValue->JSNode()->SetCData(XFA_Attribute::ContentType, L"text/xml", - false, false); - pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify, - bScriptModify, false); + pChildValue->JSObject()->SetCData(XFA_Attribute::ContentType, + L"text/xml", false, false); + pChildValue->JSObject()->SetContent(wsContent, wsContent, bNotify, + bScriptModify, false); CXFA_Node* pBind = ToNode(GetXFAObject())->GetBindData(); if (bSyncData && pBind) { std::vector<WideString> wsSaveTextArray; @@ -645,8 +645,8 @@ bool CJX_Object::SetContent(const WideString& wsContent, while (iAddNodes-- > 0) { pValueNodes = pBind->CreateSamePacketNode(XFA_Element::DataValue); - pValueNodes->JSNode()->SetCData(XFA_Attribute::Name, L"value", - false, false); + pValueNodes->JSObject()->SetCData(XFA_Attribute::Name, L"value", + false, false); pValueNodes->CreateXMLMappingNode(); pBind->InsertChild(pValueNodes, nullptr); } @@ -663,15 +663,15 @@ bool CJX_Object::SetContent(const WideString& wsContent, pBind->GetNodeItem(XFA_NODEITEM_FirstChild); pValueNode; pValueNode = pValueNode->GetNodeItem( XFA_NODEITEM_NextSibling)) { - pValueNode->JSNode()->SetAttributeValue( + pValueNode->JSObject()->SetAttributeValue( wsSaveTextArray[i], wsSaveTextArray[i], false, false); i++; } } for (const auto& pArrayNode : *(pBind->GetBindItems())) { if (pArrayNode.Get() != ToNode(GetXFAObject())) { - pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify, - bScriptModify, false); + pArrayNode->JSObject()->SetContent(wsContent, wsContent, bNotify, + bScriptModify, false); } } } @@ -686,17 +686,17 @@ bool CJX_Object::SetContent(const WideString& wsContent, CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); ASSERT(pChildValue); - pChildValue->JSNode()->SetContent(wsContent, wsContent, bNotify, - bScriptModify, false); + pChildValue->JSObject()->SetContent(wsContent, wsContent, bNotify, + bScriptModify, false); } pBindNode = ToNode(GetXFAObject())->GetBindData(); if (pBindNode && bSyncData) { - pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify, - bScriptModify, false); + pBindNode->JSObject()->SetContent(wsContent, wsXMLValue, bNotify, + bScriptModify, false); for (const auto& pArrayNode : *(pBindNode->GetBindItems())) { if (pArrayNode.Get() != ToNode(GetXFAObject())) { - pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify, - true, false); + pArrayNode->JSObject()->SetContent(wsContent, wsContent, bNotify, + true, false); } } } @@ -727,7 +727,7 @@ bool CJX_Object::SetContent(const WideString& wsContent, : XFA_Element::Sharptext); ToNode(GetXFAObject())->InsertChild(pContentRawDataNode, nullptr); } - return pContentRawDataNode->JSNode()->SetContent( + return pContentRawDataNode->JSObject()->SetContent( wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); } case XFA_ObjectType::NodeC: @@ -748,8 +748,8 @@ bool CJX_Object::SetContent(const WideString& wsContent, if (pParent && pParent->IsContainerNode()) { pBindNode = pParent->GetBindData(); if (pBindNode) { - pBindNode->JSNode()->SetContent(wsContent, wsXMLValue, bNotify, - bScriptModify, false); + pBindNode->JSObject()->SetContent(wsContent, wsXMLValue, bNotify, + bScriptModify, false); } } } @@ -768,8 +768,8 @@ bool CJX_Object::SetContent(const WideString& wsContent, SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); if (pBindNode && bSyncData) { for (const auto& pArrayNode : *(pBindNode->GetBindItems())) { - pArrayNode->JSNode()->SetContent(wsContent, wsContent, bNotify, - bScriptModify, false); + pArrayNode->JSObject()->SetContent(wsContent, wsContent, bNotify, + bScriptModify, false); } } return true; @@ -794,11 +794,11 @@ pdfium::Optional<WideString> CJX_Object::TryContent(bool bScriptModify, CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); if (pChildValue && XFA_FieldIsMultiListBox(ToNode(GetXFAObject()))) { - pChildValue->JSNode()->SetAttribute(XFA_Attribute::ContentType, - L"text/xml", false); + pChildValue->JSObject()->SetAttribute(XFA_Attribute::ContentType, + L"text/xml", false); } if (pChildValue) - return pChildValue->JSNode()->TryContent(bScriptModify, bProto); + return pChildValue->JSObject()->TryContent(bScriptModify, bProto); return {}; } break; @@ -821,7 +821,7 @@ pdfium::Optional<WideString> CJX_Object::TryContent(bool bScriptModify, ToNode(GetXFAObject())->CreateSamePacketNode(element); ToNode(GetXFAObject())->InsertChild(pContentRawDataNode, nullptr); } - return pContentRawDataNode->JSNode()->TryContent(bScriptModify, true); + return pContentRawDataNode->JSObject()->TryContent(bScriptModify, true); } case XFA_ObjectType::NodeC: case XFA_ObjectType::NodeV: @@ -913,7 +913,7 @@ void CJX_Object::SetMapModuleValue(void* pKey, void* pValue) { bool CJX_Object::GetMapModuleValue(void* pKey, void*& pValue) { for (CXFA_Node* pNode = ToNode(GetXFAObject()); pNode; pNode = pNode->GetTemplateNode()) { - XFA_MAPMODULEDATA* pModule = pNode->JSNode()->GetMapModuleData(); + XFA_MAPMODULEDATA* pModule = pNode->JSObject()->GetMapModuleData(); if (pModule) { auto it = pModule->m_ValueMap.find(pKey); if (it != pModule->m_ValueMap.end()) { @@ -973,7 +973,7 @@ bool CJX_Object::GetMapModuleBuffer(void* pKey, XFA_MAPDATABLOCK* pBuffer = nullptr; for (const CXFA_Node* pNode = ToNode(GetXFAObject()); pNode; pNode = pNode->GetTemplateNode()) { - XFA_MAPMODULEDATA* pModule = pNode->JSNode()->GetMapModuleData(); + XFA_MAPMODULEDATA* pModule = pNode->JSObject()->GetMapModuleData(); if (pModule) { auto it = pModule->m_BufferMap.find(pKey); if (it != pModule->m_BufferMap.end()) { @@ -1040,7 +1040,7 @@ void CJX_Object::RemoveMapModuleKey(void* pKey) { void CJX_Object::MergeAllData(CXFA_Object* pDstModule) { XFA_MAPMODULEDATA* pDstModuleData = - ToNode(pDstModule)->JSNode()->CreateMapModuleData(); + ToNode(pDstModule)->JSObject()->CreateMapModuleData(); XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); if (!pSrcModuleData) return; @@ -1092,18 +1092,18 @@ void CJX_Object::MoveBufferMapData(CXFA_Object* pDstModule) { bNeedMove = false; if (bNeedMove) - ToNode(pDstModule)->JSNode()->SetCalcData(ReleaseCalcData()); + ToNode(pDstModule)->JSObject()->SetCalcData(ReleaseCalcData()); if (!pDstModule->IsNodeV()) return; - WideString wsValue = ToNode(pDstModule)->JSNode()->GetContent(false); + WideString wsValue = ToNode(pDstModule)->JSObject()->GetContent(false); WideString wsFormatValue(wsValue); CXFA_WidgetData* pWidgetData = ToNode(pDstModule)->GetContainerWidgetData(); if (pWidgetData) wsFormatValue = pWidgetData->GetFormatDataValue(wsValue); ToNode(pDstModule) - ->JSNode() + ->JSObject() ->SetContent(wsValue, wsFormatValue, true, true, true); } @@ -1122,7 +1122,7 @@ void CJX_Object::MoveBufferMapData(CXFA_Object* pSrcModule, pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling); pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling); } - ToNode(pSrcModule)->JSNode()->MoveBufferMapData(pDstModule); + ToNode(pSrcModule)->JSObject()->MoveBufferMapData(pDstModule); } void CJX_Object::OnChanging(XFA_Attribute eAttr, bool bNotify) { @@ -1558,7 +1558,7 @@ void CJX_Object::Script_Som_InstanceIndex(CFXJSE_Value* pValue, if (!pManagerNode) return; - pManagerNode->JSNode()->InstanceManager_MoveInstance(iTo, iFrom); + pManagerNode->JSObject()->InstanceManager_MoveInstance(iTo, iFrom); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); if (!pNotify) return; @@ -1619,7 +1619,7 @@ void CJX_Object::Script_Field_DefaultValue(CFXJSE_Value* pValue, XFA_NODEITEM_FirstChild); if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { if (pUIChild->GetElementType() == XFA_Element::NumericEdit && - (pNode->JSNode()->GetInteger(XFA_Attribute::FracDigits) == -1)) { + (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) { pValue->SetString(content.UTF8Encode().AsStringView()); } else { CFX_Decimal decimal(content.AsStringView()); @@ -1902,7 +1902,8 @@ void CJX_Object::Script_Subform_InstanceManager(CFXJSE_Value* pValue, ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { if (pNode->GetElementType() == XFA_Element::InstanceManager) { - WideString wsInstMgrName = pNode->JSNode()->GetCData(XFA_Attribute::Name); + WideString wsInstMgrName = + pNode->JSObject()->GetCData(XFA_Attribute::Name); if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' && wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) { pInstanceMgr = pNode; @@ -2073,7 +2074,7 @@ pdfium::Optional<WideString> CJX_Object::TryNamespace() { } if (ToNode(GetXFAObject())->GetPacketType() != XFA_PacketType::Datasets) - return ToNode(GetXFAObject())->GetModelNode()->JSNode()->TryNamespace(); + return ToNode(GetXFAObject())->GetModelNode()->JSObject()->TryNamespace(); CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode(); if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index cb1fef62da..b704037e4f 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -23,6 +23,7 @@ class CFXJSE_Value; class CJS_V8; class CXFA_CalcData; class CXFA_Document; +class CXFA_LayoutItem; class CXFA_Object; struct XFA_MAPMODULEDATA; @@ -58,6 +59,12 @@ class CJX_Object { } CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); } + void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; } + size_t GetCalcRecursionCount() const { return calc_recursion_count_; } + + void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; } + CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); } + bool HasMethod(const WideString& func) const; CJS_Return RunMethod(const WideString& func, const std::vector<v8::Local<v8::Value>>& params); @@ -353,11 +360,13 @@ class CJX_Object { void RemoveMapModuleKey(void* pKey); void MoveBufferMapData(CXFA_Object* pDstModule); - std::unique_ptr<CXFA_WidgetData> widget_data_; UnownedPtr<CXFA_Object> object_; + UnownedPtr<CXFA_LayoutItem> layout_item_; + std::unique_ptr<CXFA_WidgetData> widget_data_; std::unique_ptr<XFA_MAPMODULEDATA> map_module_data_; std::unique_ptr<CXFA_CalcData> calc_data_; std::map<ByteString, CJX_MethodCall> method_specs_; + size_t calc_recursion_count_ = 0; }; #endif // FXJS_XFA_CJX_OBJECT_H_ |