diff options
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 19 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.h | 8 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_lexer.h | 20 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_program.cpp | 14 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_program.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_scriptcontext.cpp | 2 |
8 files changed, 37 insertions, 38 deletions
diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 716e378ed7..d0a111fa0d 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -2778,7 +2778,7 @@ void CXFA_FM2JSContext::Eval(CFXJSE_Value* pThis, } CFX_WideTextBuf wsJavaScriptBuf; - if (CXFA_FM2JSContext::Translate( + if (!CXFA_FM2JSContext::Translate( CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), &wsJavaScriptBuf)) { pContext->ThrowCompilerErrorException(); @@ -5433,8 +5433,8 @@ void CXFA_FM2JSContext::eval_translation(CFXJSE_Value* pThis, CFX_WideString scriptString = CFX_WideString::FromUTF8(argString.AsStringC()); CFX_WideTextBuf wsJavaScriptBuf; - if (CXFA_FM2JSContext::Translate(scriptString.AsStringC(), - &wsJavaScriptBuf)) { + if (!CXFA_FM2JSContext::Translate(scriptString.AsStringC(), + &wsJavaScriptBuf)) { pContext->ThrowCompilerErrorException(); return; } @@ -6112,18 +6112,15 @@ CFX_ByteString CXFA_FM2JSContext::ValueToUTF8String(CFXJSE_Value* arg) { } // static. -int32_t CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, - CFX_WideTextBuf* wsJavascript) { +bool CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, + CFX_WideTextBuf* wsJavascript) { if (wsFormcalc.IsEmpty()) { wsJavascript->Clear(); - return 0; + return true; } - CXFA_FMProgram program(wsFormcalc); - int32_t status = program.ParseProgram(); - if (status) - return status; - return program.TranslateProgram(*wsJavascript); + CXFA_FMProgram program(wsFormcalc); + return program.ParseProgram() && program.TranslateProgram(*wsJavascript); } CXFA_FM2JSContext::CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.h b/xfa/fxfa/fm2js/xfa_fm2jscontext.h index bde185d28c..6508852ba2 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.h +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.h @@ -427,8 +427,8 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { CFXJSE_Value* src, bool* ret); - static int32_t Translate(const CFX_WideStringC& wsFormcalc, - CFX_WideTextBuf* wsJavascript); + static bool Translate(const CFX_WideStringC& wsFormcalc, + CFX_WideTextBuf* wsJavascript); void GlobalPropertyGetter(CFXJSE_Value* pValue); diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index a7ba901c89..ad3a92abc3 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -833,7 +833,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { uint32_t line = m_pToken->m_uLinenum; - const wchar_t* pStartPos = m_lexer->SavePos(); + const wchar_t* pStartPos = m_lexer->GetPos(); NextToken(); Check(TOKlparen); std::unique_ptr<CXFA_FMSimpleExpression> pExpression; @@ -851,7 +851,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { m_pToken->m_type = TOKidentifier; m_pToken->m_wstring = L"if"; m_lexer->SetToken(std::move(pNewToken)); - m_lexer->RestorePos(pStartPos); + m_lexer->SetPos(pStartPos); return ParseExpExpression(); } Check(TOKthen); diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h index 23b01b877c..8cf6b955ed 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.h +++ b/xfa/fxfa/fm2js/xfa_fmparse.h @@ -19,9 +19,12 @@ class CXFA_FMParse { ~CXFA_FMParse(); void NextToken(); + std::vector<std::unique_ptr<CXFA_FMExpression>> ParseTopExpression(); + + private: void Check(XFA_FM_TOKEN op); void Error(uint32_t lineNum, const wchar_t* msg, ...); - std::vector<std::unique_ptr<CXFA_FMExpression>> ParseTopExpression(); + bool HasError() const; std::unique_ptr<CXFA_FMExpression> ParseFunction(); std::unique_ptr<CXFA_FMExpression> ParseExpression(); std::unique_ptr<CXFA_FMExpression> ParseVarExpression(); @@ -47,9 +50,6 @@ class CXFA_FMParse { std::unique_ptr<CXFA_FMSimpleExpression> e); std::unique_ptr<CXFA_FMSimpleExpression> ParseIndexExpression(); - private: - bool HasError() const; - std::unique_ptr<CXFA_FMLexer> m_lexer; CXFA_FMToken* m_pToken; CXFA_FMErrorInfo* const m_pErrorInfo; diff --git a/xfa/fxfa/fm2js/xfa_lexer.h b/xfa/fxfa/fm2js/xfa_lexer.h index 0db9de58a9..7de76d7a62 100644 --- a/xfa/fxfa/fm2js/xfa_lexer.h +++ b/xfa/fxfa/fm2js/xfa_lexer.h @@ -108,21 +108,23 @@ class CXFA_FMLexer { ~CXFA_FMLexer(); CXFA_FMToken* NextToken(); - const wchar_t* Number(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* String(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* Identifiers(CXFA_FMToken* t, const wchar_t* p); - const wchar_t* Comment(const wchar_t* p); - XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p); + bool HasError() const; + void SetCurrentLine(uint32_t line) { m_uCurrentLine = line; } void SetToken(std::unique_ptr<CXFA_FMToken> pToken) { m_pToken = std::move(pToken); } - const wchar_t* SavePos() { return m_ptr; } - void RestorePos(const wchar_t* pPos) { m_ptr = pPos; } - void Error(const wchar_t* msg, ...); - bool HasError() const; + + const wchar_t* GetPos() { return m_ptr; } + void SetPos(const wchar_t* pPos) { m_ptr = pPos; } private: + const wchar_t* Number(CXFA_FMToken* t, const wchar_t* p); + const wchar_t* String(CXFA_FMToken* t, const wchar_t* p); + const wchar_t* Identifiers(CXFA_FMToken* t, const wchar_t* p); + const wchar_t* Comment(const wchar_t* p); + XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p); + void Error(const wchar_t* msg, ...); std::unique_ptr<CXFA_FMToken> Scan(); const wchar_t* m_ptr; diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp index 6afe332629..8e5aa5ec3b 100644 --- a/xfa/fxfa/fm2js/xfa_program.cpp +++ b/xfa/fxfa/fm2js/xfa_program.cpp @@ -16,25 +16,25 @@ CXFA_FMProgram::CXFA_FMProgram(const CFX_WideStringC& wsFormcalc) CXFA_FMProgram::~CXFA_FMProgram() {} -int32_t CXFA_FMProgram::ParseProgram() { +bool CXFA_FMProgram::ParseProgram() { m_parse.NextToken(); if (!m_pErrorInfo.message.IsEmpty()) - return -1; + return false; std::vector<std::unique_ptr<CXFA_FMExpression>> expressions = m_parse.ParseTopExpression(); if (!m_pErrorInfo.message.IsEmpty()) - return -1; + return false; std::vector<CFX_WideStringC> arguments; m_globalFunction = pdfium::MakeUnique<CXFA_FMFunctionDefinition>( 1, true, L"", std::move(arguments), std::move(expressions)); - return 0; + return true; } -int32_t CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) { +bool CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) { if (!m_globalFunction->ToJavaScript(wsJavaScript)) - return -1; + return false; wsJavaScript.AppendChar(0); - return 0; + return true; } diff --git a/xfa/fxfa/fm2js/xfa_program.h b/xfa/fxfa/fm2js/xfa_program.h index a00a5037da..641c72f4a2 100644 --- a/xfa/fxfa/fm2js/xfa_program.h +++ b/xfa/fxfa/fm2js/xfa_program.h @@ -17,8 +17,8 @@ class CXFA_FMProgram { explicit CXFA_FMProgram(const CFX_WideStringC& wsFormcalc); ~CXFA_FMProgram(); - int32_t ParseProgram(); - int32_t TranslateProgram(CFX_WideTextBuf& wsJavaScript); + bool ParseProgram(); + bool TranslateProgram(CFX_WideTextBuf& wsJavaScript); private: CXFA_FMErrorInfo m_pErrorInfo; diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp index a3aed388be..cf6cb14fb9 100644 --- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp +++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -153,7 +153,7 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, m_pIsolate, m_JsContext.get(), m_pDocument); } CFX_WideTextBuf wsJavaScript; - if (CXFA_FM2JSContext::Translate(wsScript, &wsJavaScript)) { + if (!CXFA_FM2JSContext::Translate(wsScript, &wsJavaScript)) { hRetValue->SetUndefined(); return false; } |