From 3cdcfeb04b5c496199d8c88ebd2402c3db4413ab Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 3 Jan 2017 15:45:10 -0500 Subject: Create individual exception methods. This CL removes the LoadString method from CPDFXFA_Context and, instead, creates individual exception methods for each of the loaded strings and calls as needed. BUG=pdfium:549 Change-Id: I1d975f01f13f45a885946a9952f24b13387dc3e4 Reviewed-on: https://pdfium-review.googlesource.com/2135 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fxfa/parser/cscript_hostpseudomodel.cpp | 69 +- xfa/fxfa/parser/cscript_hostpseudomodel.h | 10 +- xfa/fxfa/parser/cscript_layoutpseudomodel.cpp | 18 +- xfa/fxfa/parser/cscript_layoutpseudomodel.h | 3 + xfa/fxfa/parser/cscript_signaturepseudomodel.cpp | 8 +- xfa/fxfa/parser/cxfa_node.cpp | 1157 +++++++++++----------- xfa/fxfa/parser/cxfa_nodelist.cpp | 111 ++- xfa/fxfa/parser/cxfa_object.cpp | 27 +- xfa/fxfa/parser/xfa_object.h | 13 +- 9 files changed, 719 insertions(+), 697 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index b4559669b7..97f16f01e7 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -34,13 +34,6 @@ CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument) CScript_HostPseudoModel::~CScript_HostPseudoModel() {} -void CScript_HostPseudoModel::LoadString(CFXJSE_Value* pValue, - CXFA_FFNotify* pNotify, - uint32_t dwFlag) { - pValue->SetString( - FX_UTF8Encode(pNotify->GetAppProvider()->LoadString(dwFlag)).AsStringC()); -} - void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { @@ -48,7 +41,7 @@ void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, if (!pNotify) return; if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } pValue->SetString("Exchange"); @@ -89,11 +82,10 @@ void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_LANGUAGE); + ThrowSetLanguageException(); return; } pValue->SetString( @@ -109,7 +101,7 @@ void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, } CXFA_FFDoc* hDoc = pNotify->GetHDOC(); if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_NUMPAGES); + ThrowSetNumPagesException(); return; } pValue->SetInteger(pNotify->GetDocEnvironment()->CountPages(hDoc)); @@ -119,11 +111,10 @@ void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_PLATFORM); + ThrowSetPlatformException(); return; } pValue->SetString( @@ -176,7 +167,7 @@ void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue, if (!pNotify) return; if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_VARIATION); + ThrowSetVariationException(); return; } pValue->SetString("Full"); @@ -190,7 +181,7 @@ void CScript_HostPseudoModel::Version(CFXJSE_Value* pValue, return; } if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_VERSION); + ThrowSetVersionException(); return; } pValue->SetString("11"); @@ -204,7 +195,7 @@ void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, return; } if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } pValue->SetString( @@ -217,7 +208,7 @@ void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"gotoURL"); + ThrowParamCountMismatchException(L"gotoURL"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -238,7 +229,7 @@ void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); + ThrowParamCountMismatchException(L"openList"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -285,7 +276,7 @@ void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"response"); + ThrowParamCountMismatchException(L"response"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -349,7 +340,7 @@ static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData"); + ThrowParamCountMismatchException(L"resetData"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -400,7 +391,7 @@ void CScript_HostPseudoModel::Beep(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"beep"); + ThrowParamCountMismatchException(L"beep"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -419,7 +410,7 @@ void CScript_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setFocus"); + ThrowParamCountMismatchException(L"setFocus"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -472,7 +463,7 @@ void CScript_HostPseudoModel::MessageBox(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"messageBox"); + ThrowParamCountMismatchException(L"messageBox"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -524,7 +515,7 @@ bool CScript_HostPseudoModel::ValidateArgsForMsg(CFXJSE_Arguments* pArguments, } std::unique_ptr pValueArg(pArguments->GetValue(iArgIndex)); if (!pValueArg->IsString() && bIsJsType) { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); + ThrowArgumentMismatchException(); return false; } if (pValueArg->IsNull()) { @@ -545,7 +536,7 @@ void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { } int32_t iLength = pArguments->GetLength(); if (iLength != 8) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"print"); + ThrowParamCountMismatchException(L"print"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -611,7 +602,7 @@ void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); + ThrowParamCountMismatchException(L"importData"); return; } // Not implemented. @@ -620,7 +611,7 @@ void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); + ThrowParamCountMismatchException(L"exportData"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); @@ -685,3 +676,23 @@ void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { if (pValue) pValue->SetString(FX_UTF8Encode(wsDataTime).AsStringC()); } + +void CScript_HostPseudoModel::ThrowSetLanguageException() const { + ThrowException(L"Unable to set language value."); +} + +void CScript_HostPseudoModel::ThrowSetNumPagesException() const { + ThrowException(L"Unable to set numPages value."); +} + +void CScript_HostPseudoModel::ThrowSetPlatformException() const { + ThrowException(L"Unable to set platform value."); +} + +void CScript_HostPseudoModel::ThrowSetVariationException() const { + ThrowException(L"Unable to set variation value."); +} + +void CScript_HostPseudoModel::ThrowSetVersionException() const { + ThrowException(L"Unable to set version value."); +} diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.h b/xfa/fxfa/parser/cscript_hostpseudomodel.h index 76c910b801..7d24a1d2b4 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.h +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.h @@ -51,12 +51,16 @@ class CScript_HostPseudoModel : public CXFA_Object { void CurrentDateTime(CFXJSE_Arguments* pArguments); protected: - void LoadString(CFXJSE_Value* pValue, - CXFA_FFNotify* pNotify, - uint32_t dwFlag); bool ValidateArgsForMsg(CFXJSE_Arguments* pArguments, int32_t iArgIndex, CFX_WideString& wsValue); + + private: + void ThrowSetLanguageException() const; + void ThrowSetNumPagesException() const; + void ThrowSetPlatformException() const; + void ThrowSetVariationException() const; + void ThrowSetVersionException() const; }; #endif // XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index a9c63666b3..a1d1ca5785 100644 --- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -39,7 +39,7 @@ void CScript_LayoutPseudoModel::Ready(CFXJSE_Value* pValue, return; } if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_READY); + ThrowSetReadyException(); return; } int32_t iStatus = pNotify->GetLayoutStatus(); @@ -65,7 +65,7 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, methodName = L"y"; break; } - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); + ThrowParamCountMismatchException(methodName); return; } CXFA_Node* pNode = nullptr; @@ -177,7 +177,7 @@ void CScript_LayoutPseudoModel::PageCount(CFXJSE_Arguments* pArguments) { void CScript_LayoutPseudoModel::PageSpan(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan"); + ThrowParamCountMismatchException(L"pageSpan"); return; } CXFA_Node* pNode = nullptr; @@ -343,7 +343,7 @@ void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 3) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent"); + ThrowParamCountMismatchException(L"pageContent"); return; } int32_t iIndex = 0; @@ -411,7 +411,7 @@ void CScript_LayoutPseudoModel::AbsPageSpan(CFXJSE_Arguments* pArguments) { void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) { if (pArguments->GetLength() != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"absPageInBatch"); + ThrowParamCountMismatchException(L"absPageInBatch"); return; } @@ -422,7 +422,7 @@ void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) { void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) { if (pArguments->GetLength() != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sheetInBatch"); + ThrowParamCountMismatchException(L"sheetInBatch"); return; } @@ -456,7 +456,7 @@ void CScript_LayoutPseudoModel::PageImp(CFXJSE_Arguments* pArguments, } else { methodName = L"page"; } - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); + ThrowParamCountMismatchException(methodName); return; } CXFA_Node* pNode = nullptr; @@ -481,3 +481,7 @@ void CScript_LayoutPseudoModel::PageImp(CFXJSE_Arguments* pArguments, if (pValue) pValue->SetInteger(bAbsPage ? iPage : iPage + 1); } + +void CScript_LayoutPseudoModel::ThrowSetReadyException() const { + ThrowException(L"Unable to set ready value."); +} diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.h b/xfa/fxfa/parser/cscript_layoutpseudomodel.h index ad64417bf3..55a00db14a 100644 --- a/xfa/fxfa/parser/cscript_layoutpseudomodel.h +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.h @@ -55,6 +55,9 @@ class CScript_LayoutPseudoModel : public CXFA_Object { bool bOnPageArea, CXFA_NodeArray& retArray); void PageImp(CFXJSE_Arguments* pArguments, bool bAbsPage); + + private: + void ThrowSetReadyException() const; }; #endif // XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp index 391f3be381..e5874a61cc 100644 --- a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -26,7 +26,7 @@ CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); + ThrowParamCountMismatchException(L"verify"); return; } @@ -38,7 +38,7 @@ void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 3 || iLength > 7) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); + ThrowParamCountMismatchException(L"sign"); return; } @@ -49,7 +49,7 @@ void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { if (pArguments->GetLength() != 0) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); + ThrowParamCountMismatchException(L"enumerate"); return; } return; @@ -58,7 +58,7 @@ void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { void CScript_SignaturePseudoModel::Clear(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); + ThrowParamCountMismatchException(L"clear"); return; } diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index cabf87fa7f..1bde816d3d 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -994,7 +994,7 @@ void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode"); + ThrowParamCountMismatchException(L"resolveNode"); return; } CFX_WideString wsExpression = @@ -1037,7 +1037,7 @@ void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes"); + ThrowParamCountMismatchException(L"resolveNodes"); return; } CFX_WideString wsExpression = @@ -1090,14 +1090,15 @@ void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; - CFX_WideString wsName; - GetAttribute(XFA_ATTRIBUTE_Name, wsName); - CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); - Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); + ThrowInvalidPropertyException(); + return; } + + uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; + CFX_WideString wsName; + GetAttribute(XFA_ATTRIBUTE_Name, wsName); + CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); + Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); } void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, @@ -1120,65 +1121,67 @@ void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; - CFX_WideString wsExpression = - FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]"); - Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); + ThrowInvalidPropertyException(); + return; } + + uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; + CFX_WideString wsExpression = + FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]"); + Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); } void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); + return; + } + CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); + if (pParent) { + pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); } else { - CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); - if (pParent) { - pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); - } else { - pValue->SetNull(); - } + pValue->SetNull(); } } void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (bSetting) - ThrowException(XFA_IDS_INVAlID_PROP_SET); - else - pValue->SetInteger(GetNodeSameNameIndex()); + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetInteger(GetNodeSameNameIndex()); } void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (bSetting) - ThrowException(XFA_IDS_INVAlID_PROP_SET); - else - pValue->SetInteger(GetNodeSameClassIndex()); + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetInteger(GetNodeSameClassIndex()); } void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - CFX_WideString wsSOMExpression; - GetSOMExpression(wsSOMExpression); - pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); + ThrowInvalidPropertyException(); + return; } + CFX_WideString wsSOMExpression; + GetSOMExpression(wsSOMExpression); + pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); } void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL"); + ThrowParamCountMismatchException(L"applyXSL"); return; } CFX_WideString wsExpression = @@ -1191,7 +1194,7 @@ void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 3) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode"); + ThrowParamCountMismatchException(L"assignNode"); return; } CFX_WideString wsExpression; @@ -1215,7 +1218,7 @@ void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone"); + ThrowParamCountMismatchException(L"clone"); return; } bool bClone = !!pArguments->GetInt32(0); @@ -1227,7 +1230,7 @@ void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); + ThrowParamCountMismatchException(L"getAttribute"); return; } CFX_WideString wsExpression = @@ -1242,7 +1245,7 @@ void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement"); + ThrowParamCountMismatchException(L"getElement"); return; } CFX_WideString wsExpression; @@ -1261,7 +1264,7 @@ void CXFA_Node::Script_NodeClass_IsPropertySpecified( CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 3) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified"); + ThrowParamCountMismatchException(L"isPropertySpecified"); return; } CFX_WideString wsExpression; @@ -1297,7 +1300,7 @@ void CXFA_Node::Script_NodeClass_IsPropertySpecified( void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 3) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); + ThrowParamCountMismatchException(L"loadXML"); return; } CFX_WideString wsExpression; @@ -1417,13 +1420,13 @@ void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); + ThrowParamCountMismatchException(L"saveXML"); return; } bool bPrettyMode = false; if (iLength == 1) { if (pArguments->GetUTF8String(0) != "pretty") { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); + ThrowArgumentMismatchException(); return; } bPrettyMode = true; @@ -1471,7 +1474,7 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); + ThrowParamCountMismatchException(L"setAttribute"); return; } CFX_WideString wsAttributeValue = @@ -1484,7 +1487,7 @@ void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1 && iLength != 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement"); + ThrowParamCountMismatchException(L"setElement"); return; } CXFA_Node* pNode = nullptr; @@ -1502,61 +1505,64 @@ void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - CFX_WideString wsNameSpace; - TryNamespace(wsNameSpace); - pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); + ThrowInvalidPropertyException(); + return; } + + CFX_WideString wsNameSpace; + TryNamespace(wsNameSpace); + pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); } void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); + ThrowInvalidPropertyException(); + return; } + pValue->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); } void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (bSetting) - ThrowException(XFA_IDS_INVAlID_PROP_SET); - else - pValue->SetBoolean(IsContainerNode()); + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetBoolean(IsContainerNode()); } void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - if (GetElementType() == XFA_Element::Subform) { - pValue->SetBoolean(false); - return; - } - CFX_WideString strValue; - pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); + ThrowInvalidPropertyException(); + return; + } + if (GetElementType() == XFA_Element::Subform) { + pValue->SetBoolean(false); + return; } + CFX_WideString strValue; + pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); } void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - CXFA_NodeArray properts; - int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); - if (iSize > 0) { - pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); - } + ThrowInvalidPropertyException(); + return; + } + + CXFA_NodeArray properts; + int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); + if (iSize > 0) { + pValue->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); } } @@ -1577,7 +1583,7 @@ void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS"); + ThrowParamCountMismatchException(L"isCompatibleNS"); return; } CFX_WideString wsNameSpace; @@ -1613,11 +1619,11 @@ void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - pValue->SetInteger(GetInteger(eAttribute)); - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + if (bSetting) { + ThrowInvalidPropertyException(); + return; } + pValue->SetInteger(GetInteger(eAttribute)); } void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, @@ -1633,11 +1639,11 @@ void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + if (bSetting) { + ThrowInvalidPropertyException(); + return; } + pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); } void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( @@ -1863,31 +1869,29 @@ void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - CFX_WideString wsValue; - GetAttribute(eAttribute, wsValue); - pValue->SetString( - FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + if (bSetting) { + ThrowInvalidPropertyException(); + return; } + + CFX_WideString wsValue; + GetAttribute(eAttribute, wsValue); + pValue->SetString( + FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); } void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if ((argc == 0) || (argc == 1)) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute"); + if (argc != 0 && argc != 1) { + ThrowParamCountMismatchException(L"execute"); + return; } + pArguments->GetReturnValue()->SetBoolean(false); } void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"restore"); } void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, @@ -1965,15 +1969,16 @@ void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) { - pValue->SetInteger(0); - return; - } - pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); + ThrowInvalidPropertyException(); + return; + } + + CXFA_WidgetData* pWidgetData = GetWidgetData(); + if (!pWidgetData) { + pValue->SetInteger(0); + return; } + pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); } void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, @@ -2046,16 +2051,17 @@ void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } + CFX_WideString content = GetScriptContent(true); if (content.IsEmpty()) { pValue->SetNull(); - } else { - pValue->SetString( - FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); + return; } + pValue->SetString( + FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); } void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, @@ -2171,17 +2177,18 @@ void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - CXFA_Node* pDataNode = GetBindData(); - if (pDataNode) { - pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); - } else { - pValue->SetNull(); - } - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + if (bSetting) { + ThrowInvalidPropertyException(); + return; } + + CXFA_Node* pDataNode = GetBindData(); + if (!pDataNode) { + pValue->SetNull(); + return; + } + + pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); } void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, @@ -2376,10 +2383,10 @@ void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } else { - pValue->SetNull(); + ThrowInvalidPropertyException(); + return; } + pValue->SetNull(); } void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, @@ -2410,38 +2417,39 @@ void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { } void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString eventString = pArguments->GetUTF8String(0); - int32_t iRet = execSingleEventByName( - CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), - XFA_Element::Field); - if (eventString == "validate") { - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"execEvent"); + return; } + + CFX_ByteString eventString = pArguments->GetUTF8String(0); + int32_t iRet = execSingleEventByName( + CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), + XFA_Element::Field); + if (eventString != "validate") + return; + + pArguments->GetReturnValue()->SetBoolean( + (iRet == XFA_EVENTERROR_Error) ? false : true); } void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execInitialize"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); } void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem"); + ThrowParamCountMismatchException(L"deleteItem"); return; } CXFA_WidgetData* pWidgetData = GetWidgetData(); @@ -2458,7 +2466,7 @@ void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem"); + ThrowParamCountMismatchException(L"getSaveItem"); return; } int32_t iIndex = pArguments->GetInt32(0); @@ -2484,7 +2492,7 @@ void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem"); + ThrowParamCountMismatchException(L"boundItem"); return; } CXFA_WidgetData* pWidgetData = GetWidgetData(); @@ -2503,7 +2511,7 @@ void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState"); + ThrowParamCountMismatchException(L"getItemState"); return; } CXFA_WidgetData* pWidgetData = GetWidgetData(); @@ -2518,16 +2526,16 @@ void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { } void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execCalculate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); } void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} @@ -2535,7 +2543,7 @@ void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem"); + ThrowParamCountMismatchException(L"getDisplayItem"); return; } int32_t iIndex = pArguments->GetInt32(0); @@ -2561,7 +2569,7 @@ void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState"); + ThrowParamCountMismatchException(L"setItemState"); return; } CXFA_WidgetData* pWidgetData = GetWidgetData(); @@ -2580,7 +2588,7 @@ void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem"); + ThrowParamCountMismatchException(L"addItem"); return; } CXFA_WidgetData* pWidgetData = GetWidgetData(); @@ -2601,29 +2609,28 @@ void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { } void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - int32_t iRet = - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execValidate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + pArguments->GetReturnValue()->SetBoolean(false); + return; + } + + int32_t iRet = + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); + pArguments->GetReturnValue()->SetBoolean( + (iRet == XFA_EVENTERROR_Error) ? false : true); } void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - } + if (bSetting) + ThrowInvalidPropertyException(); } void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, @@ -2652,21 +2659,21 @@ void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, XFA_ATTRIBUTE eAttribute) {} void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString eventString = pArguments->GetUTF8String(0); - execSingleEventByName( - CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), - XFA_Element::ExclGroup); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"execEvent"); + return; } + + CFX_ByteString eventString = pArguments->GetUTF8String(0); + execSingleEventByName( + CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), + XFA_Element::ExclGroup); } void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); if (argc < 0 || argc > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember"); + ThrowParamCountMismatchException(L"selectedMember"); return; } @@ -2694,45 +2701,46 @@ void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { } void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execInitialize"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); } void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execCalculate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); } void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execValidate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + pArguments->GetReturnValue()->SetBoolean(false); + return; + } + + int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); + pArguments->GetReturnValue()->SetBoolean( + (iRet == XFA_EVENTERROR_Error) ? false : true); } void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, @@ -2774,29 +2782,31 @@ void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); - CXFA_Node* pInstanceMgr = nullptr; - for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { - if (pNode->GetElementType() == XFA_Element::InstanceManager) { - CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); - if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && - wsInstMgrName.Mid(1) == wsName) { - pInstanceMgr = pNode; - } - break; + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + + CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); + CXFA_Node* pInstanceMgr = nullptr; + for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { + if (pNode->GetElementType() == XFA_Element::InstanceManager) { + CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); + if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && + wsInstMgrName.Mid(1) == wsName) { + pInstanceMgr = pNode; } + break; } - if (pInstanceMgr) { - pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); - } else { - pValue->SetNull(); - } - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); } + if (!pInstanceMgr) { + pValue->SetNull(); + return; + } + + pValue->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); } void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, @@ -2814,65 +2824,63 @@ void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, } void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString eventString = pArguments->GetUTF8String(0); - execSingleEventByName( - CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), - XFA_Element::Subform); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"execEvent"); + return; } + + CFX_ByteString eventString = pArguments->GetUTF8String(0); + execSingleEventByName( + CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), + XFA_Element::Subform); } void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execInitialize"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); } void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execCalculate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); } void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execValidate"); + return; + } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + pArguments->GetReturnValue()->SetBoolean(false); + return; } + + int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); + pArguments->GetReturnValue()->SetBoolean( + (iRet == XFA_EVENTERROR_Error) ? false : true); } void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"getInvalidObjects"); } int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { @@ -2890,136 +2898,136 @@ int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { } void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - pArguments->GetReturnValue()->SetBoolean(true); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"formNodes"); + return; } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - m_pDocument->DoDataRemerge(true); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"remerge"); + return; } + m_pDocument->DoDataRemerge(true); } void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - pArguments->GetReturnValue()->SetBoolean(true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execInitialize"); + return; + } + + CXFA_WidgetData* pWidgetData = GetWidgetData(); + if (!pWidgetData) { + pArguments->GetReturnValue()->SetBoolean(false); + return; } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if ((argc > 0) && (argc < 4)) { - CFX_WideString strTagName; - CFX_WideString strName; - CFX_WideString strNameSpace; - CFX_ByteString bsTagName = pArguments->GetUTF8String(0); - strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); - if (argc > 1) { - CFX_ByteString bsName = pArguments->GetUTF8String(1); - strName = CFX_WideString::FromUTF8(bsName.AsStringC()); - if (argc == 3) { - CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); - strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); - } - } - XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); - CXFA_Node* pNewNode = CreateSamePacketNode(eType); - if (!pNewNode) { - pArguments->GetReturnValue()->SetNull(); - } else { - if (!strName.IsEmpty()) { - if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, - XFA_XDPPACKET_UNKNOWN)) { - pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); - if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { - pNewNode->CreateXMLMappingNode(); - } - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); - } else { - ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), - L"name"); - } - } else { - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); - } + if (argc <= 0 || argc >= 4) { + ThrowParamCountMismatchException(L"createNode"); + return; + } + + CFX_WideString strName; + CFX_WideString strNameSpace; + CFX_ByteString bsTagName = pArguments->GetUTF8String(0); + CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); + if (argc > 1) { + CFX_ByteString bsName = pArguments->GetUTF8String(1); + strName = CFX_WideString::FromUTF8(bsName.AsStringC()); + if (argc == 3) { + CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); + strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode"); } + + XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); + CXFA_Node* pNewNode = CreateSamePacketNode(eType); + if (!pNewNode) { + pArguments->GetReturnValue()->SetNull(); + return; + } + + if (strName.IsEmpty()) { + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); + return; + } + + if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, + XFA_XDPPACKET_UNKNOWN)) { + ThrowMissingPropertyException(strTagName, L"name"); + return; + } + + pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); + if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) + pNewNode->CreateXMLMappingNode(); + + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); } void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() == 1) { - pArguments->GetReturnValue()->SetBoolean(true); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"recalculate"); + return; } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - pArguments->GetReturnValue()->SetBoolean(true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execCalculate"); + return; + } + + CXFA_WidgetData* pWidgetData = GetWidgetData(); + if (!pWidgetData) { + pArguments->GetReturnValue()->SetBoolean(false); + return; } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - pArguments->GetReturnValue()->SetBoolean(true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execValidate"); + return; } + CXFA_WidgetData* pWidgetData = GetWidgetData(); + if (!pWidgetData) { + pArguments->GetReturnValue()->SetBoolean(false); + return; + } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - pArguments->GetReturnValue()->SetBoolean(true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"evaluate"); + return; + } + + CXFA_WidgetData* pWidgetData = GetWidgetData(); + if (!pWidgetData) { + pArguments->GetReturnValue()->SetBoolean(false); + return; } + pArguments->GetReturnValue()->SetBoolean(true); } void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } CXFA_Occur nodeOccur(GetOccurNode()); @@ -3030,7 +3038,7 @@ void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } CXFA_Occur nodeOccur(GetOccurNode()); @@ -3050,8 +3058,7 @@ void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, void CXFA_Node::Script_InstanceManager_MoveInstance( CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 2) { + if (pArguments->GetLength() != 2) { pArguments->GetReturnValue()->SetUndefined(); return; } @@ -3075,21 +3082,20 @@ void CXFA_Node::Script_InstanceManager_MoveInstance( void CXFA_Node::Script_InstanceManager_RemoveInstance( CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 1) { + if (pArguments->GetLength() != 1) { pArguments->GetReturnValue()->SetUndefined(); return; } int32_t iIndex = pArguments->GetInt32(0); int32_t iCount = GetCount(this); if (iIndex < 0 || iIndex >= iCount) { - ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); + ThrowIndexOutOfBoundsException(); return; } CXFA_Occur nodeOccur(GetOccurNode()); int32_t iMin = nodeOccur.GetMin(); if (iCount - 1 < iMin) { - ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); + ThrowTooManyOccurancesException(L"min"); return; } CXFA_Node* pRemoveInstance = GetItem(this, iIndex); @@ -3114,8 +3120,7 @@ void CXFA_Node::Script_InstanceManager_RemoveInstance( void CXFA_Node::Script_InstanceManager_SetInstances( CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 1) { + if (pArguments->GetLength() != 1) { pArguments->GetReturnValue()->SetUndefined(); return; } @@ -3126,8 +3131,8 @@ void CXFA_Node::Script_InstanceManager_SetInstances( void CXFA_Node::Script_InstanceManager_AddInstance( CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if ((argc != 0) && (argc != 1)) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance"); + if (argc != 0 && argc != 1) { + ThrowParamCountMismatchException(L"addInstance"); return; } bool fFlags = true; @@ -3138,7 +3143,7 @@ void CXFA_Node::Script_InstanceManager_AddInstance( CXFA_Occur nodeOccur(GetOccurNode()); int32_t iMax = nodeOccur.GetMax(); if (iMax >= 0 && iCount >= iMax) { - ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); + ThrowTooManyOccurancesException(L"max"); return; } CXFA_Node* pNewInstance = CreateInstance(this, fFlags); @@ -3161,8 +3166,8 @@ void CXFA_Node::Script_InstanceManager_AddInstance( void CXFA_Node::Script_InstanceManager_InsertInstance( CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if ((argc != 1) && (argc != 2)) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance"); + if (argc != 1 && argc != 2) { + ThrowParamCountMismatchException(L"insertInstance"); return; } int32_t iIndex = pArguments->GetInt32(0); @@ -3173,12 +3178,12 @@ void CXFA_Node::Script_InstanceManager_InsertInstance( CXFA_Occur nodeOccur(GetOccurNode()); int32_t iCount = GetCount(this); if (iIndex < 0 || iIndex > iCount) { - ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); + ThrowIndexOutOfBoundsException(); return; } int32_t iMax = nodeOccur.GetMax(); if (iMax >= 0 && iCount >= iMax) { - ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); + ThrowTooManyOccurancesException(L"max"); return; } CXFA_Node* pNewInstance = CreateInstance(this, bBind); @@ -3203,11 +3208,11 @@ int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { int32_t iMax = nodeOccur.GetMax(); int32_t iMin = nodeOccur.GetMin(); if (iDesired < iMin) { - ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); + ThrowTooManyOccurancesException(L"min"); return 1; } if ((iMax >= 0) && (iDesired > iMax)) { - ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); + ThrowTooManyOccurancesException(L"max"); return 2; } int32_t iCount = GetCount(this); @@ -3262,7 +3267,7 @@ int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { int32_t iCount = GetCount(this); if (iFrom > iCount || iTo > iCount - 1) { - ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); + ThrowIndexOutOfBoundsException(); return 1; } if (iFrom < 0 || iTo < 0 || iFrom == iTo) { @@ -3305,51 +3310,52 @@ void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if ((argc == 0) || (argc == 1)) { - pArguments->GetReturnValue()->SetString(""); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata"); + if (argc != 0 && argc != 1) { + ThrowParamCountMismatchException(L"metadata"); + return; } + pArguments->GetReturnValue()->SetString(""); } void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CXFA_Node* pDataNode = static_cast(pArguments->GetObject(0)); - if (pDataNode) { - CXFA_NodeArray formItems; - CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); - pFormNodes->SetArrayNodeList(formItems); - pArguments->GetReturnValue()->SetObject( - pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); - } else { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"formNodes"); + return; + } + + CXFA_Node* pDataNode = static_cast(pArguments->GetObject(0)); + if (!pDataNode) { + ThrowArgumentMismatchException(); + return; } + + CXFA_NodeArray formItems; + CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); + pFormNodes->SetArrayNodeList(formItems); + pArguments->GetReturnValue()->SetObject( + pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); } void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - m_pDocument->DoDataRemerge(true); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"remerge"); + return; } + + m_pDocument->DoDataRemerge(true); } void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execInitialize"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); } void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { @@ -3359,51 +3365,50 @@ void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { pEventParam->m_eType == XFA_EVENT_InitCalculate) { return; } - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - const bool bScriptFlags = pArguments->GetInt32(0) != 0; - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bScriptFlags) { - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); - } else { - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"recalculate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + if (pArguments->GetInt32(0) != 0) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); } void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execCalculate"); + return; } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) + return; + + pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); } void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - pArguments->GetReturnValue()->SetBoolean(false); - } else { - int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); + if (pArguments->GetLength() != 0) { + ThrowParamCountMismatchException(L"execValidate"); + return; + } + + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + pArguments->GetReturnValue()->SetBoolean(false); + return; } + + int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); + pArguments->GetReturnValue()->SetBoolean( + (iRet == XFA_EVENTERROR_Error) ? false : true); } void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, @@ -3411,66 +3416,67 @@ void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, XFA_ATTRIBUTE eAttribute) { if (bSetting) { SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); - } else { - CFX_WideString wsChecksum; - GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); - pValue->SetString( - FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); + return; } + + CFX_WideString wsChecksum; + GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); + pValue->SetString( + FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); } void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); - CFX_WideString wsAttributeValue; - CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); - if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { - static_cast(pXMLNode)->GetString( - CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), - wsAttributeValue); - } - pArguments->GetReturnValue()->SetString( - FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) - .AsStringC()); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"getAttribute"); + return; + } + + CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); + CFX_WideString wsAttributeValue; + CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); + if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { + static_cast(pXMLNode)->GetString( + CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), + wsAttributeValue); } + pArguments->GetReturnValue()->SetString( + FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) + .AsStringC()); } void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 2) { - CFX_ByteString bsValue = pArguments->GetUTF8String(0); - CFX_ByteString bsName = pArguments->GetUTF8String(1); - CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); - if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { - static_cast(pXMLNode)->SetString( - CFX_WideString::FromUTF8(bsName.AsStringC()), - CFX_WideString::FromUTF8(bsValue.AsStringC())); - } - pArguments->GetReturnValue()->SetNull(); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); + if (pArguments->GetLength() != 2) { + ThrowParamCountMismatchException(L"setAttribute"); + return; + } + + CFX_ByteString bsValue = pArguments->GetUTF8String(0); + CFX_ByteString bsName = pArguments->GetUTF8String(1); + CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); + if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { + static_cast(pXMLNode)->SetString( + CFX_WideString::FromUTF8(bsName.AsStringC()), + CFX_WideString::FromUTF8(bsValue.AsStringC())); } + pArguments->GetReturnValue()->SetNull(); } void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString bsName = pArguments->GetUTF8String(0); - CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); - CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); - if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFDE_XMLElement* pXMLElement = static_cast(pXMLNode); - if (pXMLElement->HasAttribute(wsName.c_str())) { - pXMLElement->RemoveAttribute(wsName.c_str()); - } + if (pArguments->GetLength() != 1) { + ThrowParamCountMismatchException(L"removeAttribute"); + return; + } + + CFX_ByteString bsName = pArguments->GetUTF8String(0); + CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); + CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); + if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { + CFDE_XMLElement* pXMLElement = static_cast(pXMLNode); + if (pXMLElement->HasAttribute(wsName.c_str())) { + pXMLElement->RemoveAttribute(wsName.c_str()); } - pArguments->GetReturnValue()->SetNull(); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute"); } + pArguments->GetReturnValue()->SetNull(); } void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, @@ -3495,139 +3501,88 @@ void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, } void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"next"); } void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"cancelBatch"); } void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"first"); } void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"updateBatch"); } void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"previous"); } void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"isBOF"); } void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"isEOF"); } void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"cancel"); } void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"update"); } void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"open"); } void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"delete"); } void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"addNew"); } void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"requery"); } void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"resync"); } void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"close"); } void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"last"); } void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc == 0) { - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged"); - } + if (pArguments->GetLength() != 0) + ThrowParamCountMismatchException(L"hasDataChanged"); } void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, @@ -3660,7 +3615,7 @@ void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC()); @@ -5194,3 +5149,17 @@ void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, } pSrcModule->MoveBufferMapData(pDstModule, pKey); } + +void CXFA_Node::ThrowMissingPropertyException( + const CFX_WideString& obj, + const CFX_WideString& prop) const { + ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), + prop.c_str()); +} + +void CXFA_Node::ThrowTooManyOccurancesException( + const CFX_WideString& obj) const { + ThrowException( + L"The element [%s] has violated its allowable number of occurrences.", + obj.c_str()); +} diff --git a/xfa/fxfa/parser/cxfa_nodelist.cpp b/xfa/fxfa/parser/cxfa_nodelist.cpp index cb09833d24..97c531f33b 100644 --- a/xfa/fxfa/parser/cxfa_nodelist.cpp +++ b/xfa/fxfa/parser/cxfa_nodelist.cpp @@ -36,85 +36,90 @@ CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CXFA_Node* pNode = static_cast(pArguments->GetObject(0)); - if (pNode) { - Append(pNode); - } else { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"append"); + if (argc != 1) { + ThrowParamCountMismatchException(L"append"); + return; } + + CXFA_Node* pNode = static_cast(pArguments->GetObject(0)); + if (!pNode) { + ThrowArgumentMismatchException(); + return; + } + Append(pNode); } void CXFA_NodeList::Script_ListClass_Insert(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if (argc == 2) { - CXFA_Node* pNewNode = static_cast(pArguments->GetObject(0)); - CXFA_Node* pBeforeNode = static_cast(pArguments->GetObject(1)); - if (pNewNode) { - Insert(pNewNode, pBeforeNode); - } else { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insert"); + if (argc != 2) { + ThrowParamCountMismatchException(L"insert"); + return; } + + CXFA_Node* pNewNode = static_cast(pArguments->GetObject(0)); + CXFA_Node* pBeforeNode = static_cast(pArguments->GetObject(1)); + if (!pNewNode) { + ThrowArgumentMismatchException(); + return; + } + Insert(pNewNode, pBeforeNode); } void CXFA_NodeList::Script_ListClass_Remove(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CXFA_Node* pNode = static_cast(pArguments->GetObject(0)); - if (pNode) { - Remove(pNode); - } else { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remove"); + if (argc != 1) { + ThrowParamCountMismatchException(L"remove"); + return; + } + + CXFA_Node* pNode = static_cast(pArguments->GetObject(0)); + if (!pNode) { + ThrowArgumentMismatchException(); + return; } + Remove(pNode); } void CXFA_NodeList::Script_ListClass_Item(CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if (argc == 1) { - int32_t iIndex = pArguments->GetInt32(0); - if ((iIndex >= 0) && (iIndex + 1 <= GetLength())) { - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(Item(iIndex))); - } else { - ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); - } - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"item"); + if (argc != 1) { + ThrowParamCountMismatchException(L"item"); + return; + } + + int32_t iIndex = pArguments->GetInt32(0); + if (iIndex < 0 || iIndex >= GetLength()) { + ThrowIndexOutOfBoundsException(); + return; } + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(Item(iIndex))); } void CXFA_NodeList::Script_TreelistClass_NamedItem( CFXJSE_Arguments* pArguments) { int32_t argc = pArguments->GetLength(); - if (argc == 1) { - CFX_ByteString szName = pArguments->GetUTF8String(0); - CXFA_Node* pNode = - NamedItem(CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC()); - if (!pNode) { - return; - } - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); - } else { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"namedItem"); + if (argc != 1) { + ThrowParamCountMismatchException(L"namedItem"); + return; } + + CFX_ByteString szName = pArguments->GetUTF8String(0); + CXFA_Node* pNode = + NamedItem(CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC()); + if (!pNode) + return; + + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); } void CXFA_NodeList::Script_ListClass_Length(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { - if (!bSetting) { - pValue->SetInteger(GetLength()); - } else { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + if (bSetting) { + ThrowInvalidPropertyException(); + return; } + pValue->SetInteger(GetLength()); } diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index c8ed7138a8..45e34424aa 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp @@ -39,7 +39,7 @@ void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); + ThrowInvalidPropertyException(); return; } CFX_WideStringC className = GetClassName(); @@ -47,14 +47,29 @@ void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC()); } -void CXFA_Object::ThrowException(int32_t iStringID, ...) { - IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); - ASSERT(pAppProvider); +void CXFA_Object::ThrowInvalidPropertyException() const { + ThrowException(L"Invalid property set operation."); +} + +void CXFA_Object::ThrowIndexOutOfBoundsException() const { + ThrowException(L"Index value is out of bounds."); +} + +void CXFA_Object::ThrowParamCountMismatchException( + const CFX_WideString& method) const { + ThrowException(L"Incorrect number of parameters calling method '%s'.", + method.c_str()); +} + +void CXFA_Object::ThrowArgumentMismatchException() const { + ThrowException(L"Argument mismatch in property or function argument."); +} +void CXFA_Object::ThrowException(const FX_WCHAR* str, ...) const { CFX_WideString wsMessage; va_list arg_ptr; - va_start(arg_ptr, iStringID); - wsMessage.FormatV(pAppProvider->LoadString(iStringID).c_str(), arg_ptr); + va_start(arg_ptr, str); + wsMessage.FormatV(str, arg_ptr); va_end(arg_ptr); FXJSE_ThrowMessage( FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); diff --git a/xfa/fxfa/parser/xfa_object.h b/xfa/fxfa/parser/xfa_object.h index c3686ac076..93f4e0145d 100644 --- a/xfa/fxfa/parser/xfa_object.h +++ b/xfa/fxfa/parser/xfa_object.h @@ -90,9 +90,15 @@ class CXFA_Object : public CFXJSE_HostObject { void Script_ObjectClass_ClassName(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute); - void ThrowException(int32_t iStringID, ...); + + void ThrowInvalidPropertyException() const; + void ThrowArgumentMismatchException() const; + void ThrowIndexOutOfBoundsException() const; + void ThrowParamCountMismatchException(const CFX_WideString& method) const; protected: + void ThrowException(const FX_WCHAR* str, ...) const; + CXFA_Document* const m_pDocument; const XFA_ObjectType m_objectType; const XFA_Element m_elementType; @@ -676,6 +682,11 @@ class CXFA_Node : public CXFA_Object { uint32_t m_dwNameHash; CXFA_Node* m_pAuxNode; XFA_MAPMODULEDATA* m_pMapModuleData; + + private: + void ThrowMissingPropertyException(const CFX_WideString& obj, + const CFX_WideString& prop) const; + void ThrowTooManyOccurancesException(const CFX_WideString& obj) const; }; class CXFA_ThisProxy : public CXFA_Object { -- cgit v1.2.3