diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-13 01:20:24 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-13 01:20:24 +0000 |
commit | 94ed4456bfe64ea045be24c66966d814b73fa7ac (patch) | |
tree | 37c2f025b678ce47ef925904d5615c33cd3c656c | |
parent | 5548984944785d80daa03d98e92698309a3bc604 (diff) | |
download | pdfium-94ed4456bfe64ea045be24c66966d814b73fa7ac.tar.xz |
Move remaining Script_ methods to CJX_Object
The CJX_Node isn't the root of the CJX hierarchy. This causes issues
now that CJX_Object has child objects which don't inherit from CJX_Node.
This CL moves Script_* from CJX_Node to CJX_Object.
Change-Id: I9f063c9d796896ba34be802a8ef8f108911ed56c
Reviewed-on: https://pdfium-review.googlesource.com/20972
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 509 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.h | 117 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.cpp | 488 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.h | 114 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_basic_data_element_script.cpp | 72 |
5 files changed, 641 insertions, 659 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 9d416ea4d1..cceaa208fc 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -6,26 +6,15 @@ #include "fxjs/xfa/cjx_node.h" -#include <map> -#include <vector> - -#include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_codepage.h" -#include "core/fxcrt/fx_extension.h" -#include "core/fxcrt/xml/cfx_xmlelement.h" -#include "core/fxcrt/xml/cfx_xmlnode.h" -#include "core/fxcrt/xml/cfx_xmltext.h" #include "fxjs/cfxjse_engine.h" #include "fxjs/js_resources.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffnotify.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/parser/cxfa_arraynodelist.h" -#include "xfa/fxfa/parser/cxfa_attachnodelist.h" -#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" -#include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -119,90 +108,6 @@ const CXFA_Node* CJX_Node::GetXFANode() const { return static_cast<const CXFA_Node*>(GetXFAObject()); } -int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) { - CXFA_OccurData occurData(GetXFANode()->GetOccurNode()); - if (iDesired < occurData.GetMin()) { - ThrowTooManyOccurancesException(L"min"); - return 1; - } - - int32_t iMax = occurData.GetMax(); - if (iMax >= 0 && iDesired > iMax) { - ThrowTooManyOccurancesException(L"max"); - return 2; - } - - int32_t iCount = GetXFANode()->GetCount(); - if (iDesired == iCount) - return 0; - - if (iDesired < iCount) { - WideString wsInstManagerName = GetCData(XFA_Attribute::Name); - WideString wsInstanceName = WideString( - wsInstManagerName.IsEmpty() - ? wsInstManagerName - : wsInstManagerName.Right(wsInstManagerName.GetLength() - 1)); - uint32_t dInstanceNameHash = - FX_HashCode_GetW(wsInstanceName.AsStringView(), false); - CXFA_Node* pPrevSibling = - iDesired == 0 ? GetXFANode() : GetXFANode()->GetItem(iDesired - 1); - while (iCount > iDesired) { - CXFA_Node* pRemoveInstance = - pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); - if (pRemoveInstance->GetElementType() != XFA_Element::Subform && - pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { - continue; - } - if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { - NOTREACHED(); - break; - } - if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { - GetXFANode()->RemoveItem(pRemoveInstance, true); - iCount--; - } - } - } else { - while (iCount < iDesired) { - CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(true); - GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false); - iCount++; - CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return 0; - - pNotify->RunNodeInitialize(pNewInstance); - } - } - - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (pLayoutPro) { - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); - } - return 0; -} - -int32_t CJX_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { - int32_t iCount = GetXFANode()->GetCount(); - if (iFrom > iCount || iTo > iCount - 1) { - ThrowIndexOutOfBoundsException(); - return 1; - } - if (iFrom < 0 || iTo < 0 || iFrom == iTo) - return 0; - - CXFA_Node* pMoveInstance = GetXFANode()->GetItem(iFrom); - GetXFANode()->RemoveItem(pMoveInstance, false); - GetXFANode()->InsertItem(pMoveInstance, iTo, iCount - 1, true); - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (pLayoutPro) { - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); - } - return 0; -} - CJS_Return CJX_Node::applyXSL(CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { if (params.size() != 1) @@ -478,402 +383,6 @@ CJS_Return CJX_Node::setElement( return CJS_Return(true); } -void CJX_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetString( - TryNamespace().value_or(WideString()).UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( - GetXFANode()->GetModelNode())); -} - -void CJX_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - pValue->SetBoolean(GetXFANode()->IsContainerNode()); -} - -void CJX_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - if (GetXFANode()->GetElementType() == XFA_Element::Subform) { - pValue->SetBoolean(false); - return; - } - pValue->SetBoolean(GetContent(false).IsEmpty()); -} - -void CJX_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - std::vector<CXFA_Node*> properties = GetXFANode()->GetNodeList( - XFA_NODEFILTER_OneOfProperty, XFA_Element::Unknown); - if (!properties.empty()) { - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( - properties.front())); - } -} - -void CJX_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Delta_Target(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Field_Length(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) { - pValue->SetInteger(0); - return; - } - pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); -} - -void CJX_Node::Script_Field_EditValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); - return; - } - pValue->SetString( - pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); - return; - } - pValue->SetString(pWidgetData->GetValue(XFA_VALUEPICTURE_Display) - .UTF8Encode() - .AsStringView()); -} - -void CJX_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetNull(); -} - -void CJX_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (!bSetting) { - pValue->SetInteger(pWidgetData->GetSelectedItem(0)); - return; - } - - int32_t iIndex = pValue->ToInteger(); - if (iIndex == -1) { - pWidgetData->ClearAllSelections(); - return; - } - - pWidgetData->SetItemState(iIndex, true, true, true, true); -} - -void CJX_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) - ThrowInvalidPropertyException(); -} - -void CJX_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - if (bSetting) { - pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringView(), - true, true, true); - return; - } - - WideString wsValue = GetContent(true); - XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); - if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { - pValue->SetNull(); - return; - } - pValue->SetString(wsValue.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - - WideString wsName = GetCData(XFA_Attribute::Name); - CXFA_Node* pInstanceMgr = nullptr; - for (CXFA_Node* pNode = GetXFANode()->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); - if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' && - wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) { - pInstanceMgr = pNode; - } - break; - } - } - if (!pInstanceMgr) { - pValue->SetNull(); - return; - } - - pValue->Assign( - GetDocument()->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); -} - -void CJX_Node::Script_Subform_Locale(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - SetCData(XFA_Attribute::Locale, pValue->ToWideString(), true, true); - return; - } - - WideString wsLocaleName; - GetXFANode()->GetLocaleName(wsLocaleName); - pValue->SetString(wsLocaleName.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax()); -} - -void CJX_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetInteger(CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMin()); -} - -void CJX_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - pValue->SetInteger(GetXFANode()->GetCount()); - return; - } - InstanceManager_SetInstances(pValue->ToInteger()); -} - -void CJX_Node::Script_Occur_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_OccurData occurData(GetXFANode()); - if (!bSetting) { - pValue->SetInteger(occurData.GetMax()); - return; - } - occurData.SetMax(pValue->ToInteger()); -} - -void CJX_Node::Script_Occur_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_OccurData occurData(GetXFANode()); - if (!bSetting) { - pValue->SetInteger(occurData.GetMin()); - return; - } - occurData.SetMin(pValue->ToInteger()); -} - -void CJX_Node::Script_Form_Checksum(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - SetAttribute(XFA_Attribute::Checksum, pValue->ToWideString().AsStringView(), - false); - return; - } - - pdfium::Optional<WideString> checksum = - TryAttribute(XFA_Attribute::Checksum, false); - pValue->SetString(checksum ? checksum->UTF8Encode().AsStringView() : ""); -} - -void CJX_Node::Script_Packet_Content(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (bSetting) { - if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); - pXMLElement->SetTextData(pValue->ToWideString()); - } - return; - } - - WideString wsTextData; - if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); - wsTextData = pXMLElement->GetTextData(); - } - - pValue->SetString(wsTextData.UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_Source_Db(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Xfa_This(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) - return; - - CXFA_Object* pThis = GetDocument()->GetScriptContext()->GetThisObject(); - ASSERT(pThis); - pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap(pThis)); -} - -void CJX_Node::Script_Handler_Version(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Extras_Type(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -void CJX_Node::Script_Script_Stateless(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - if (bSetting) { - ThrowInvalidPropertyException(); - return; - } - pValue->SetString(FX_UTF8Encode(WideStringView(L"0", 1)).AsStringView()); -} - -void CJX_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) {} - -pdfium::Optional<WideString> CJX_Node::TryNamespace() { - if (GetXFANode()->IsModelNode() || - GetXFANode()->GetElementType() == XFA_Element::Packet) { - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) - return {}; - - return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; - } - - if (GetXFANode()->GetPacketType() != XFA_PacketType::Datasets) - return GetXFANode()->GetModelNode()->JSNode()->TryNamespace(); - - CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); - if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) - return {}; - - if (GetXFANode()->GetElementType() == XFA_Element::DataValue && - GetEnum(XFA_Attribute::Contains) == XFA_AttributeEnum::MetaData) { - WideString wsNamespace; - bool ret = XFA_FDEExtension_ResolveNamespaceQualifier( - static_cast<CFX_XMLElement*>(pXMLNode), - GetCData(XFA_Attribute::QualifiedName), &wsNamespace); - if (!ret) - return {}; - return {wsNamespace}; - } - return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; -} - int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, XFA_Element eType) { CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); @@ -947,15 +456,3 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, } return XFA_EVENTERROR_NotExist; } - -void CJX_Node::ThrowMissingPropertyException(const WideString& obj, - const WideString& prop) const { - ThrowException(L"'%ls' doesn't have property '%ls'.", obj.c_str(), - prop.c_str()); -} - -void CJX_Node::ThrowTooManyOccurancesException(const WideString& obj) const { - ThrowException( - L"The element [%ls] has violated its allowable number of occurrences.", - obj.c_str()); -} diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h index f2ff49217e..9d16d852bf 100644 --- a/fxjs/xfa/cjx_node.h +++ b/fxjs/xfa/cjx_node.h @@ -34,15 +34,6 @@ class CJX_Node : public CJX_Tree { void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; } size_t GetCalcRecursionCount() const { return calc_recursion_count_; } - pdfium::Optional<WideString> TryNamespace(); - - void ThrowMissingPropertyException(const WideString& obj, - const WideString& prop) const; - void ThrowTooManyOccurancesException(const WideString& obj) const; - - int32_t InstanceManager_SetInstances(int32_t iDesired); - int32_t InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom); - JS_METHOD(applyXSL, CJX_Node); JS_METHOD(assignNode, CJX_Node); JS_METHOD(clone, CJX_Node); @@ -55,114 +46,6 @@ class CJX_Node : public CJX_Tree { JS_METHOD(setAttribute, CJX_Node); JS_METHOD(setElement, CJX_Node); - void Script_NodeClass_Ns(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_NodeClass_Model(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_NodeClass_IsContainer(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_NodeClass_IsNull(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_ModelClass_Context(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_ModelClass_AliasNode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Delta_CurrentValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Delta_SavedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Delta_Target(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Field_Length(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Field_EditValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Field_FormattedValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Field_ParentSubform(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Field_SelectedIndex(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_ExclGroup_Transient(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - - void Script_Subform_InstanceManager(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Subform_Locale(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_InstanceManager_Count(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_InstanceManager_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_InstanceManager_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - - void Script_Occur_Max(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Occur_Min(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - - void Script_Form_Checksum(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - - void Script_Packet_Content(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - - void Script_Source_Db(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Xfa_This(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Handler_Version(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_SubmitFormat_Mode(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Extras_Type(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Encrypt_Format(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Script_Stateless(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - protected: int32_t execSingleEventByName(const WideStringView& wsEventName, XFA_Element eType); diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 2c6588824f..04d053ce38 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -18,9 +18,11 @@ #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_object.h" +#include "xfa/fxfa/parser/cxfa_occurdata.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { @@ -148,6 +150,12 @@ CJS_Return CJX_Object::RunMethod( params); } +void CJX_Object::ThrowTooManyOccurancesException(const WideString& obj) const { + ThrowException( + L"The element [%ls] has violated its allowable number of occurrences.", + obj.c_str()); +} + void CJX_Object::ThrowInvalidPropertyException() const { ThrowException(L"Invalid property set operation."); } @@ -1688,3 +1696,483 @@ int32_t CJX_Object::Subform_and_SubformSet_InstanceIndex() { } return index; } + +void CJX_Object::Script_NodeClass_Ns(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetString( + TryNamespace().value_or(WideString()).UTF8Encode().AsStringView()); +} + +void CJX_Object::Script_NodeClass_Model(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + + pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( + ToNode(GetXFAObject())->GetModelNode())); +} + +void CJX_Object::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + + pValue->SetBoolean(GetXFAObject()->IsContainerNode()); +} + +void CJX_Object::Script_NodeClass_IsNull(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::Subform) { + pValue->SetBoolean(false); + return; + } + pValue->SetBoolean(GetContent(false).IsEmpty()); +} + +void CJX_Object::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + + std::vector<CXFA_Node*> properties = + ToNode(GetXFAObject()) + ->GetNodeList(XFA_NODEFILTER_OneOfProperty, XFA_Element::Unknown); + if (!properties.empty()) { + pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap( + properties.front())); + } +} + +void CJX_Object::Script_ModelClass_Context(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Delta_CurrentValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Delta_SavedValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Delta_Target(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Field_Length(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + if (!widget_data_) { + pValue->SetInteger(0); + return; + } + pValue->SetInteger(widget_data_->CountChoiceListItems(true)); +} + +void CJX_Object::Script_Field_EditValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + if (bSetting) { + widget_data_->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); + return; + } + pValue->SetString(widget_data_->GetValue(XFA_VALUEPICTURE_Edit) + .UTF8Encode() + .AsStringView()); +} + +void CJX_Object::Script_Field_FormattedValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + if (bSetting) { + widget_data_->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); + return; + } + pValue->SetString(widget_data_->GetValue(XFA_VALUEPICTURE_Display) + .UTF8Encode() + .AsStringView()); +} + +void CJX_Object::Script_Field_ParentSubform(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetNull(); +} + +void CJX_Object::Script_Field_SelectedIndex(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + if (!bSetting) { + pValue->SetInteger(widget_data_->GetSelectedItem(0)); + return; + } + + int32_t iIndex = pValue->ToInteger(); + if (iIndex == -1) { + widget_data_->ClearAllSelections(); + return; + } + + widget_data_->SetItemState(iIndex, true, true, true, true); +} + +void CJX_Object::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) + ThrowInvalidPropertyException(); +} + +void CJX_Object::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + if (bSetting) { + widget_data_->SetSelectedMemberByValue( + pValue->ToWideString().AsStringView(), true, true, true); + return; + } + + WideString wsValue = GetContent(true); + XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); + if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { + pValue->SetNull(); + return; + } + pValue->SetString(wsValue.UTF8Encode().AsStringView()); +} + +void CJX_Object::Script_ExclGroup_Transient(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Subform_InstanceManager(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + + WideString wsName = GetCData(XFA_Attribute::Name); + CXFA_Node* pInstanceMgr = nullptr; + for (CXFA_Node* pNode = + 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); + if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' && + wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) { + pInstanceMgr = pNode; + } + break; + } + } + if (!pInstanceMgr) { + pValue->SetNull(); + return; + } + + pValue->Assign( + GetDocument()->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); +} + +void CJX_Object::Script_Subform_Locale(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + SetCData(XFA_Attribute::Locale, pValue->ToWideString(), true, true); + return; + } + + WideString wsLocaleName; + ToNode(GetXFAObject())->GetLocaleName(wsLocaleName); + pValue->SetString(wsLocaleName.UTF8Encode().AsStringView()); +} + +void CJX_Object::Script_InstanceManager_Max(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetInteger( + CXFA_OccurData(ToNode(GetXFAObject())->GetOccurNode()).GetMax()); +} + +void CJX_Object::Script_InstanceManager_Min(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetInteger( + CXFA_OccurData(ToNode(GetXFAObject())->GetOccurNode()).GetMin()); +} + +void CJX_Object::Script_InstanceManager_Count(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + pValue->SetInteger(ToNode(GetXFAObject())->GetCount()); + return; + } + InstanceManager_SetInstances(pValue->ToInteger()); +} + +void CJX_Object::Script_Occur_Max(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + CXFA_OccurData occurData(ToNode(GetXFAObject())); + if (!bSetting) { + pValue->SetInteger(occurData.GetMax()); + return; + } + occurData.SetMax(pValue->ToInteger()); +} + +void CJX_Object::Script_Occur_Min(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + CXFA_OccurData occurData(ToNode(GetXFAObject())); + if (!bSetting) { + pValue->SetInteger(occurData.GetMin()); + return; + } + occurData.SetMin(pValue->ToInteger()); +} + +void CJX_Object::Script_Form_Checksum(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + SetAttribute(XFA_Attribute::Checksum, pValue->ToWideString().AsStringView(), + false); + return; + } + + pdfium::Optional<WideString> checksum = + TryAttribute(XFA_Attribute::Checksum, false); + pValue->SetString(checksum ? checksum->UTF8Encode().AsStringView() : ""); +} + +void CJX_Object::Script_Packet_Content(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode(); + if (bSetting) { + if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); + pXMLElement->SetTextData(pValue->ToWideString()); + } + return; + } + + WideString wsTextData; + if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); + wsTextData = pXMLElement->GetTextData(); + } + + pValue->SetString(wsTextData.UTF8Encode().AsStringView()); +} + +void CJX_Object::Script_Source_Db(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Xfa_This(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) + return; + + CXFA_Object* pThis = GetDocument()->GetScriptContext()->GetThisObject(); + ASSERT(pThis); + pValue->Assign(GetDocument()->GetScriptContext()->GetJSValueFromMap(pThis)); +} + +void CJX_Object::Script_Handler_Version(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Extras_Type(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +void CJX_Object::Script_Script_Stateless(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetString(FX_UTF8Encode(WideStringView(L"0", 1)).AsStringView()); +} + +void CJX_Object::Script_Encrypt_Format(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) {} + +pdfium::Optional<WideString> CJX_Object::TryNamespace() { + if (ToNode(GetXFAObject())->IsModelNode() || + ToNode(GetXFAObject())->GetElementType() == XFA_Element::Packet) { + CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode(); + if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) + return {}; + + return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; + } + + if (ToNode(GetXFAObject())->GetPacketType() != XFA_PacketType::Datasets) + return ToNode(GetXFAObject())->GetModelNode()->JSNode()->TryNamespace(); + + CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode(); + if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) + return {}; + + if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::DataValue && + GetEnum(XFA_Attribute::Contains) == XFA_AttributeEnum::MetaData) { + WideString wsNamespace; + bool ret = XFA_FDEExtension_ResolveNamespaceQualifier( + static_cast<CFX_XMLElement*>(pXMLNode), + GetCData(XFA_Attribute::QualifiedName), &wsNamespace); + if (!ret) + return {}; + return {wsNamespace}; + } + return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()}; +} + +int32_t CJX_Object::InstanceManager_SetInstances(int32_t iDesired) { + CXFA_OccurData occurData(ToNode(GetXFAObject())->GetOccurNode()); + if (iDesired < occurData.GetMin()) { + ThrowTooManyOccurancesException(L"min"); + return 1; + } + + int32_t iMax = occurData.GetMax(); + if (iMax >= 0 && iDesired > iMax) { + ThrowTooManyOccurancesException(L"max"); + return 2; + } + + int32_t iCount = ToNode(GetXFAObject())->GetCount(); + if (iDesired == iCount) + return 0; + + if (iDesired < iCount) { + WideString wsInstManagerName = GetCData(XFA_Attribute::Name); + WideString wsInstanceName = WideString( + wsInstManagerName.IsEmpty() + ? wsInstManagerName + : wsInstManagerName.Right(wsInstManagerName.GetLength() - 1)); + uint32_t dInstanceNameHash = + FX_HashCode_GetW(wsInstanceName.AsStringView(), false); + CXFA_Node* pPrevSibling = + iDesired == 0 ? ToNode(GetXFAObject()) + : ToNode(GetXFAObject())->GetItem(iDesired - 1); + while (iCount > iDesired) { + CXFA_Node* pRemoveInstance = + pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); + if (pRemoveInstance->GetElementType() != XFA_Element::Subform && + pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { + continue; + } + if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { + NOTREACHED(); + break; + } + if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { + ToNode(GetXFAObject())->RemoveItem(pRemoveInstance, true); + iCount--; + } + } + } else { + while (iCount < iDesired) { + CXFA_Node* pNewInstance = ToNode(GetXFAObject())->CreateInstance(true); + ToNode(GetXFAObject())->InsertItem(pNewInstance, iCount, iCount, false); + iCount++; + CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); + if (!pNotify) + return 0; + + pNotify->RunNodeInitialize(pNewInstance); + } + } + + CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); + if (pLayoutPro) { + pLayoutPro->AddChangedContainer( + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + } + return 0; +} + +int32_t CJX_Object::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { + int32_t iCount = ToNode(GetXFAObject())->GetCount(); + if (iFrom > iCount || iTo > iCount - 1) { + ThrowIndexOutOfBoundsException(); + return 1; + } + if (iFrom < 0 || iTo < 0 || iFrom == iTo) + return 0; + + CXFA_Node* pMoveInstance = ToNode(GetXFAObject())->GetItem(iFrom); + ToNode(GetXFAObject())->RemoveItem(pMoveInstance, false); + ToNode(GetXFAObject())->InsertItem(pMoveInstance, iTo, iCount - 1, true); + CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); + if (pLayoutPro) { + pLayoutPro->AddChangedContainer( + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + } + return 0; +} diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index 10146f4ef9..cb1fef62da 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -141,6 +141,116 @@ class CJX_Object { bool bSetting, XFA_Attribute eAttribute); + void Script_NodeClass_Ns(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_NodeClass_Model(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_NodeClass_IsContainer(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_NodeClass_IsNull(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_ModelClass_Context(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_ModelClass_AliasNode(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Delta_CurrentValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Delta_SavedValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Delta_Target(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_Length(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_EditValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_FormattedValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_ParentSubform(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Field_SelectedIndex(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_ExclGroup_Transient(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + void Script_Subform_InstanceManager(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Subform_Locale(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_InstanceManager_Count(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_InstanceManager_Max(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_InstanceManager_Min(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + void Script_Occur_Max(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Occur_Min(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + void Script_Form_Checksum(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + void Script_Packet_Content(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + void Script_Source_Db(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Xfa_This(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Handler_Version(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_SubmitFormat_Mode(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Extras_Type(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Encrypt_Format(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Script_Stateless(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + + pdfium::Optional<WideString> TryNamespace(); + pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault); bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify); int32_t GetInteger(XFA_Attribute eAttr); @@ -176,10 +286,14 @@ class CJX_Object { CXFA_CalcData* GetCalcData() const { return calc_data_.get(); } std::unique_ptr<CXFA_CalcData> ReleaseCalcData(); + int32_t InstanceManager_SetInstances(int32_t iDesired); + int32_t InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom); + void ThrowInvalidPropertyException() const; void ThrowArgumentMismatchException() const; void ThrowIndexOutOfBoundsException() const; void ThrowParamCountMismatchException(const WideString& method) const; + void ThrowTooManyOccurancesException(const WideString& obj) const; protected: void DefineMethods(const CJX_MethodSpec method_specs[], size_t count); diff --git a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp index 3e22316daf..a56ba19d7a 100644 --- a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp +++ b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp @@ -11,7 +11,6 @@ #include "fxjs/xfa/cjx_hostpseudomodel.h" #include "fxjs/xfa/cjx_layoutpseudomodel.h" #include "fxjs/xfa/cjx_logpseudomodel.h" -#include "fxjs/xfa/cjx_node.h" #include "fxjs/xfa/cjx_object.h" #include "fxjs/xfa/cjx_signaturepseudomodel.h" #include "fxjs/xfa/cjx_tree.h" @@ -420,7 +419,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { {0xf6b47749, L"lock", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_BOOL, XFA_Attribute::Lock, XFA_ScriptType::Basic}, - {0x2d574d58, L"this", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Xfa_This, + {0x2d574d58, L"this", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Xfa_This, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0x4fdc3454, L"timeStamp", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -777,13 +776,13 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_BOOL, XFA_Attribute::Lock, XFA_ScriptType::Basic}, {0x6c0d9600, L"currentValue", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Delta_CurrentValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Delta_CurrentValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x942643f0, L"savedValue", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Delta_SavedValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Delta_SavedValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xc8da4da7, L"target", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Delta_Target, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Delta_Target, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbe52dfbf, L"desc", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1047,7 +1046,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_FillColor, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x54c399e3, L"formattedValue", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_FormattedValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_FormattedValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x570ce835, L"presence", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1059,7 +1058,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_FontColor, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x6826c408, L"parentSubform", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_ParentSubform, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_ParentSubform, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x79b67434, L"mandatoryMessage", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_MandatoryMessage, @@ -1095,7 +1094,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_DefaultValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xa60dd202, L"length", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_Length, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_Length, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xac06e2b0, L"colSpan", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1116,10 +1115,10 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_ValidationMessage, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xdcecd663, L"editValue", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_EditValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_EditValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xe07e5061, L"selectedIndex", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Field_SelectedIndex, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Field_SelectedIndex, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xf65e34be, L"borderWidth", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_BorderWidth, @@ -1293,7 +1292,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Use, XFA_ScriptType::Basic}, {0xf23332f, L"errorText", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ExclGroup_ErrorText, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ExclGroup_ErrorText, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x1abbd7e0, L"dataNode", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_DataNode, @@ -1332,7 +1331,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Layout, XFA_ScriptType::Basic}, {0x846599f8, L"transient", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ExclGroup_Transient, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ExclGroup_Transient, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x85fd6faf, L"mandatory", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_Mandatory, @@ -1341,10 +1340,10 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Relevant, XFA_ScriptType::Basic}, {0xa03cf627, L"rawValue", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ExclGroup_DefaultAndRawValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ExclGroup_DefaultAndRawValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xa52682bd, L"{default}", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ExclGroup_DefaultAndRawValue, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ExclGroup_DefaultAndRawValue, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xac06e2b0, L"colSpan", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1565,7 +1564,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::MergeMode, XFA_ScriptType::Basic}, {0x9f3e9510, L"instanceManager", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Subform_InstanceManager, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Subform_InstanceManager, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0xac06e2b0, L"colSpan", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1574,7 +1573,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Usehref, XFA_ScriptType::Basic}, {0xbc8fa350, L"locale", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Subform_Locale, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Subform_Locale, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xc2bd40fd, L"anchorType", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1616,7 +1615,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Type, XFA_ScriptType::Basic}, {0x5a50e9e6, L"version", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Handler_Version, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Handler_Version, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbc254332, L"usehref", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -1701,7 +1700,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Lock, XFA_ScriptType::Basic}, {0x7d9fd7c5, L"mode", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_SubmitFormat_Mode, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_SubmitFormat_Mode, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbe52dfbf, L"desc", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -2076,7 +2075,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::RunAt, XFA_ScriptType::Basic}, {0xa021b738, L"stateless", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Script_Stateless, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Script_Stateless, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xa52682bd, L"{default}", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_DefaultValue, @@ -2328,13 +2327,13 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Usehref, XFA_ScriptType::Basic}, {0xb3543a6, L"max", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_InstanceManager_Max, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_InstanceManager_Max, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xb356ca4, L"min", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_InstanceManager_Min, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_InstanceManager_Min, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x6f544d49, L"count", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_InstanceManager_Count, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_InstanceManager_Count, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x25363, L"to", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -2586,7 +2585,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Use, XFA_ScriptType::Basic}, {0x28dee6e9, L"format", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Encrypt_Format, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Encrypt_Format, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbc254332, L"usehref", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -2786,7 +2785,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Overline, XFA_ScriptType::Basic}, {0xaf754613, L"checksum", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Form_Checksum, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Form_Checksum, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbe52dfbf, L"desc", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -2929,7 +2928,8 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { {0xc0811ed, L"use", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Use, XFA_ScriptType::Basic}, - {0x2f16a382, L"type", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Extras_Type, + {0x2f16a382, L"type", + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Extras_Type, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xbc254332, L"usehref", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -3001,7 +3001,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_BOOL, XFA_Attribute::Lock, XFA_ScriptType::Basic}, {0x97be91b, L"content", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Packet_Content, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Packet_Content, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xc0811ed, L"use", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -3161,7 +3161,7 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { XFA_Attribute::Hand, XFA_ScriptType::Basic}, {0xa60dd202, L"length", (XFA_ATTRIBUTE_CALLBACK)&CJX_List::length, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, - {0x20146, L"db", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Source_Db, + {0x20146, L"db", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Source_Db, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xc0811ed, L"use", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -3169,9 +3169,9 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { {0xbc254332, L"usehref", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Usehref, XFA_ScriptType::Basic}, - {0xb3543a6, L"max", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Occur_Max, + {0xb3543a6, L"max", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Occur_Max, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, - {0xb356ca4, L"min", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_Occur_Min, + {0xb356ca4, L"min", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Occur_Min, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xc0811ed, L"use", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, @@ -3265,25 +3265,25 @@ const XFA_SCRIPTATTRIBUTEINFO g_SomAttributeData[] = { {0x21aed, L"id", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Attribute_String, XFA_Attribute::Id, XFA_ScriptType::Basic}, - {0x234a1, L"ns", (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_NodeClass_Ns, + {0x234a1, L"ns", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_NodeClass_Ns, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0x50d1a9d1, L"model", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_NodeClass_Model, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_NodeClass_Model, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0xacb4823f, L"isContainer", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_NodeClass_IsContainer, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_NodeClass_IsContainer, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xe372ae97, L"isNull", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_NodeClass_IsNull, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_NodeClass_IsNull, XFA_Attribute::Unknown, XFA_ScriptType::Basic}, {0xfe612a5b, L"oneOfChild", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_NodeClass_OneOfChild, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_NodeClass_OneOfChild, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0x97c1c65, L"context", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ModelClass_Context, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ModelClass_Context, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0x58be2870, L"aliasNode", - (XFA_ATTRIBUTE_CALLBACK)&CJX_Node::Script_ModelClass_AliasNode, + (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_ModelClass_AliasNode, XFA_Attribute::Unknown, XFA_ScriptType::Object}, {0xa52682bd, L"{default}", (XFA_ATTRIBUTE_CALLBACK)&CJX_Object::Script_Som_DefaultValue, |