diff options
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 16 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.h | 6 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.cpp | 6 | ||||
-rw-r--r-- | fxjs/cjx_hostpseudomodel.cpp | 2 | ||||
-rw-r--r-- | testing/xfa_js_embedder_test.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fffield.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptdata.cpp | 18 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptdata.h | 18 |
9 files changed, 38 insertions, 44 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index e5d6c0a0fe..c2dba2f311 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -130,7 +130,7 @@ CFXJSE_Engine::CFXJSE_Engine(CXFA_Document* pDocument, v8::Isolate* pIsolate) pDocument->GetRoot())), m_pIsolate(pIsolate), m_pJsClass(nullptr), - m_eScriptType(XFA_ScriptDataType::Unknown), + m_eScriptType(CXFA_ScriptData::Type::Unknown), m_pScriptNodeArray(nullptr), m_ResolveProcessor(pdfium::MakeUnique<CFXJSE_ResolveProcessor>()), m_pThisObject(nullptr), @@ -150,14 +150,14 @@ CFXJSE_Engine::~CFXJSE_Engine() { delete ToThisProxy(pair.second->GetGlobalObject().get(), nullptr); } -bool CFXJSE_Engine::RunScript(XFA_ScriptDataType eScriptType, +bool CFXJSE_Engine::RunScript(CXFA_ScriptData::Type eScriptType, const WideStringView& wsScript, CFXJSE_Value* hRetValue, CXFA_Object* pThisObject) { ByteString btScript; - AutoRestorer<XFA_ScriptDataType> typeRestorer(&m_eScriptType); + AutoRestorer<CXFA_ScriptData::Type> typeRestorer(&m_eScriptType); m_eScriptType = eScriptType; - if (eScriptType == XFA_ScriptDataType::Formcalc) { + if (eScriptType == CXFA_ScriptData::Type::Formcalc) { if (!m_FM2JSContext) { m_FM2JSContext = pdfium::MakeUnique<CFXJSE_FormCalcContext>( m_pIsolate, m_JsContext.get(), m_pDocument.Get()); @@ -243,7 +243,7 @@ void CFXJSE_Engine::GlobalPropertyGetter(CFXJSE_Value* pObject, CFXJSE_Engine* lpScriptContext = pDoc->GetScriptContext(); CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); WideString wsPropName = WideString::FromUTF8(szPropName); - if (lpScriptContext->GetType() == XFA_ScriptDataType::Formcalc) { + if (lpScriptContext->GetType() == CXFA_ScriptData::Type::Formcalc) { if (szPropName == kFormCalcRuntime) { lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); return; @@ -319,7 +319,7 @@ void CFXJSE_Engine::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, return; if (pObject == lpScriptContext->GetThisObject() || - (lpScriptContext->GetType() == XFA_ScriptDataType::Javascript && + (lpScriptContext->GetType() == CXFA_ScriptData::Type::Javascript && !lpScriptContext->IsStrictScopeInJavaScript())) { dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; bRet = lpScriptContext->QueryNodeByFlag(ToNode(pObject), @@ -454,7 +454,7 @@ bool CFXJSE_Engine::IsStrictScopeInJavaScript() { return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); } -XFA_ScriptDataType CFXJSE_Engine::GetType() { +CXFA_ScriptData::Type CFXJSE_Engine::GetType() { return m_eScriptType; } @@ -574,7 +574,7 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, if (wsExpression.IsEmpty()) return 0; - if (m_eScriptType != XFA_ScriptDataType::Formcalc || + if (m_eScriptType != CXFA_ScriptData::Type::Formcalc || (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { m_upObjectArray.clear(); } diff --git a/fxjs/cfxjse_engine.h b/fxjs/cfxjse_engine.h index b049eecf56..ae9156f1c4 100644 --- a/fxjs/cfxjse_engine.h +++ b/fxjs/cfxjse_engine.h @@ -28,7 +28,7 @@ class CFXJSE_Engine { void SetEventParam(CXFA_EventParam param) { m_eventParam = param; } CXFA_EventParam* GetEventParam() { return &m_eventParam; } - bool RunScript(XFA_ScriptDataType eScriptType, + bool RunScript(CXFA_ScriptData::Type eScriptType, const WideStringView& wsScript, CFXJSE_Value* pRetValue, CXFA_Object* pThisObject); @@ -89,7 +89,7 @@ class CFXJSE_Engine { bool RunVariablesScript(CXFA_Node* pScriptNode); CXFA_Object* GetVariablesThis(CXFA_Object* pObject, bool bScriptNode = false); bool IsStrictScopeInJavaScript(); - XFA_ScriptDataType GetType(); + CXFA_ScriptData::Type GetType(); std::vector<CXFA_Node*>* GetUpObjectArray() { return &m_upObjectArray; } CXFA_Document* GetDocument() const { return m_pDocument.Get(); } @@ -104,7 +104,7 @@ class CFXJSE_Engine { std::unique_ptr<CFXJSE_Context> m_JsContext; v8::Isolate* m_pIsolate; CFXJSE_Class* m_pJsClass; - XFA_ScriptDataType m_eScriptType; + CXFA_ScriptData::Type m_eScriptType; std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Value>> m_mapObjectToValue; std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Context>> m_mapVariableToContext; diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp index ef7ddc10fb..3a6bc91d50 100644 --- a/fxjs/cfxjse_resolveprocessor.cpp +++ b/fxjs/cfxjse_resolveprocessor.cpp @@ -661,11 +661,11 @@ void CFXJSE_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, CFXJSE_ResolveNodeData& rnd) { ASSERT(iFoundCount == pdfium::CollectionSize<int32_t>(rnd.m_Objects)); WideString wsExpression; - XFA_ScriptDataType eLangType = XFA_ScriptDataType::Unknown; + CXFA_ScriptData::Type eLangType = CXFA_ScriptData::Type::Unknown; if (wsCondition.Left(2) == L".[" && wsCondition.Last() == L']') { - eLangType = XFA_ScriptDataType::Formcalc; + eLangType = CXFA_ScriptData::Type::Formcalc; } else if (wsCondition.Left(2) == L".(" && wsCondition.Last() == L')') { - eLangType = XFA_ScriptDataType::Javascript; + eLangType = CXFA_ScriptData::Type::Javascript; } else { return; } diff --git a/fxjs/cjx_hostpseudomodel.cpp b/fxjs/cjx_hostpseudomodel.cpp index 35ab2f88c9..0e26a19048 100644 --- a/fxjs/cjx_hostpseudomodel.cpp +++ b/fxjs/cjx_hostpseudomodel.cpp @@ -528,7 +528,7 @@ bool CJX_HostPseudoModel::ValidateArgsForMsg(CFXJSE_Arguments* pArguments, bool bIsJsType = false; if (GetDocument()->GetScriptContext()->GetType() == - XFA_ScriptDataType::Javascript) { + CXFA_ScriptData::Type::Javascript) { bIsJsType = true; } diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp index 68a0c109d4..966264d735 100644 --- a/testing/xfa_js_embedder_test.cpp +++ b/testing/xfa_js_embedder_test.cpp @@ -74,7 +74,7 @@ bool XFAJSEmbedderTest::ExecuteSilenceFailure(const ByteStringView& input) { bool XFAJSEmbedderTest::ExecuteHelper(const ByteStringView& input) { value_ = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate()); - return script_context_->RunScript(XFA_ScriptDataType::Formcalc, + return script_context_->RunScript(CXFA_ScriptData::Type::Formcalc, WideString::FromUTF8(input).AsStringView(), value_.get(), GetXFADocument()->GetRoot()); } diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index 3b9b7c67c8..ca3d2bb047 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -689,10 +689,7 @@ int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { CXFA_ScriptData scriptData = calcData.GetScriptData(); if (!scriptData.HasValidNode()) return 1; - - WideString wsExpression; - scriptData.GetExpression(wsExpression); - if (wsExpression.IsEmpty()) + if (scriptData.GetExpression().IsEmpty()) return 1; } diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 816e2a2204..fcc1e69762 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -599,19 +599,18 @@ std::pair<int32_t, bool> CXFA_WidgetAcc::ExecuteBoolScript( if (scriptData.GetRunAt() == XFA_ATTRIBUTEENUM_Server) return {XFA_EVENTERROR_Disabled, false}; - WideString wsExpression; - scriptData.GetExpression(wsExpression); + WideString wsExpression = scriptData.GetExpression(); if (wsExpression.IsEmpty()) return {XFA_EVENTERROR_NotExist, false}; - XFA_ScriptDataType eScriptType = scriptData.GetContentType(); - if (eScriptType == XFA_ScriptDataType::Unknown) + CXFA_ScriptData::Type eScriptType = scriptData.GetContentType(); + if (eScriptType == CXFA_ScriptData::Type::Unknown) return {XFA_EVENTERROR_Success, false}; CXFA_FFDoc* pDoc = GetDoc(); CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext(); pContext->SetEventParam(*pEventParam); - pContext->SetRunAtType((XFA_ATTRIBUTEENUM)scriptData.GetRunAt()); + pContext->SetRunAtType(scriptData.GetRunAt()); std::vector<CXFA_Node*> refNodes; if (pEventParam->m_eType == XFA_EVENT_InitCalculate || diff --git a/xfa/fxfa/parser/cxfa_scriptdata.cpp b/xfa/fxfa/parser/cxfa_scriptdata.cpp index 39d9a4b8c9..40a22b672d 100644 --- a/xfa/fxfa/parser/cxfa_scriptdata.cpp +++ b/xfa/fxfa/parser/cxfa_scriptdata.cpp @@ -10,22 +10,20 @@ CXFA_ScriptData::CXFA_ScriptData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -XFA_ScriptDataType CXFA_ScriptData::GetContentType() { +CXFA_ScriptData::Type CXFA_ScriptData::GetContentType() const { pdfium::Optional<WideString> cData = m_pNode->JSNode()->TryCData(XFA_Attribute::ContentType, false); - if (!cData) - return XFA_ScriptDataType::Formcalc; + if (!cData || *cData == L"application/x-formcalc") + return Type::Formcalc; if (*cData == L"application/x-javascript") - return XFA_ScriptDataType::Javascript; - if (*cData == L"application/x-formcalc") - return XFA_ScriptDataType::Formcalc; - return XFA_ScriptDataType::Unknown; + return Type::Javascript; + return Type::Unknown; } -int32_t CXFA_ScriptData::GetRunAt() { +XFA_ATTRIBUTEENUM CXFA_ScriptData::GetRunAt() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::RunAt); } -void CXFA_ScriptData::GetExpression(WideString& wsExpression) { - wsExpression = m_pNode->JSNode()->GetContent(false); +WideString CXFA_ScriptData::GetExpression() const { + return m_pNode->JSNode()->GetContent(false); } diff --git a/xfa/fxfa/parser/cxfa_scriptdata.h b/xfa/fxfa/parser/cxfa_scriptdata.h index 6e85d79ed2..2129928fb7 100644 --- a/xfa/fxfa/parser/cxfa_scriptdata.h +++ b/xfa/fxfa/parser/cxfa_scriptdata.h @@ -12,21 +12,21 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/parser/cxfa_datadata.h" -enum class XFA_ScriptDataType { - Formcalc = 0, - Javascript, - Unknown, -}; - class CXFA_Node; class CXFA_ScriptData : public CXFA_DataData { public: + enum class Type { + Formcalc = 0, + Javascript, + Unknown, + }; + explicit CXFA_ScriptData(CXFA_Node* pNode); - XFA_ScriptDataType GetContentType(); - int32_t GetRunAt(); - void GetExpression(WideString& wsExpression); + Type GetContentType() const; + XFA_ATTRIBUTEENUM GetRunAt() const; + WideString GetExpression() const; }; #endif // XFA_FXFA_PARSER_CXFA_SCRIPTDATA_H_ |