OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" | 7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" |
8 | 8 |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
11 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
12 #include "xfa/fgas/localization/fgas_locale.h" | 12 #include "xfa/fgas/localization/fgas_locale.h" |
13 #include "xfa/fxfa/app/xfa_ffnotify.h" | 13 #include "xfa/fxfa/app/xfa_ffnotify.h" |
14 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 14 #include "xfa/fxfa/fm2js/xfa_program.h" |
15 #include "xfa/fxfa/parser/xfa_document.h" | 15 #include "xfa/fxfa/parser/xfa_document.h" |
16 #include "xfa/fxfa/parser/xfa_localevalue.h" | 16 #include "xfa/fxfa/parser/xfa_localevalue.h" |
17 #include "xfa/fxfa/parser/xfa_parser.h" | 17 #include "xfa/fxfa/parser/xfa_parser.h" |
18 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 18 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
19 #include "xfa/fxfa/parser/xfa_script_imp.h" | 19 #include "xfa/fxfa/parser/xfa_script_imp.h" |
20 #include "xfa/fxjse/cfxjse_arguments.h" | 20 #include "xfa/fxjse/cfxjse_arguments.h" |
21 #include "xfa/fxjse/value.h" | 21 #include "xfa/fxjse/value.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
(...skipping 3372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3397 if (args.GetLength() == 1) { | 3397 if (args.GetLength() == 1) { |
3398 std::unique_ptr<CFXJSE_Value> scriptValue = GetSimpleValue(pThis, args, 0); | 3398 std::unique_ptr<CFXJSE_Value> scriptValue = GetSimpleValue(pThis, args, 0); |
3399 CFX_ByteString utf8ScriptString; | 3399 CFX_ByteString utf8ScriptString; |
3400 ValueToUTF8String(scriptValue.get(), utf8ScriptString); | 3400 ValueToUTF8String(scriptValue.get(), utf8ScriptString); |
3401 if (utf8ScriptString.IsEmpty()) { | 3401 if (utf8ScriptString.IsEmpty()) { |
3402 FXJSE_Value_SetNull(args.GetReturnValue()); | 3402 FXJSE_Value_SetNull(args.GetReturnValue()); |
3403 } else { | 3403 } else { |
3404 CFX_WideTextBuf wsJavaScriptBuf; | 3404 CFX_WideTextBuf wsJavaScriptBuf; |
3405 CFX_WideString javaScript; | 3405 CFX_WideString javaScript; |
3406 CFX_WideString wsError; | 3406 CFX_WideString wsError; |
3407 XFA_FM2JS_Translate( | 3407 pContext->Translate( |
3408 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), | 3408 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), |
3409 wsJavaScriptBuf, wsError); | 3409 wsJavaScriptBuf, wsError); |
3410 CFXJSE_Context* pContext = | 3410 CFXJSE_Context* pContext = |
3411 FXJSE_Context_Create(pIsolate, nullptr, nullptr); | 3411 FXJSE_Context_Create(pIsolate, nullptr, nullptr); |
3412 std::unique_ptr<CFXJSE_Value> returnValue(new CFXJSE_Value(pIsolate)); | 3412 std::unique_ptr<CFXJSE_Value> returnValue(new CFXJSE_Value(pIsolate)); |
3413 javaScript = wsJavaScriptBuf.AsStringC(); | 3413 javaScript = wsJavaScriptBuf.AsStringC(); |
3414 FXJSE_ExecuteScript( | 3414 FXJSE_ExecuteScript( |
3415 pContext, | 3415 pContext, |
3416 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), | 3416 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), |
3417 returnValue.get()); | 3417 returnValue.get()); |
(...skipping 2992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6410 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); | 6410 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); |
6411 CFX_ByteString argString; | 6411 CFX_ByteString argString; |
6412 ValueToUTF8String(argOne.get(), argString); | 6412 ValueToUTF8String(argOne.get(), argString); |
6413 if (argString.IsEmpty()) { | 6413 if (argString.IsEmpty()) { |
6414 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); | 6414 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); |
6415 } else { | 6415 } else { |
6416 CFX_WideString scriptString = | 6416 CFX_WideString scriptString = |
6417 CFX_WideString::FromUTF8(argString.AsStringC()); | 6417 CFX_WideString::FromUTF8(argString.AsStringC()); |
6418 CFX_WideTextBuf wsJavaScriptBuf; | 6418 CFX_WideTextBuf wsJavaScriptBuf; |
6419 CFX_WideString wsError; | 6419 CFX_WideString wsError; |
6420 XFA_FM2JS_Translate(scriptString.AsStringC(), wsJavaScriptBuf, wsError); | 6420 pContext->Translate(scriptString.AsStringC(), wsJavaScriptBuf, wsError); |
6421 if (wsError.IsEmpty()) { | 6421 if (wsError.IsEmpty()) { |
6422 CFX_WideString javaScript = wsJavaScriptBuf.MakeString(); | 6422 CFX_WideString javaScript = wsJavaScriptBuf.MakeString(); |
6423 FXJSE_Value_SetUTF8String( | 6423 FXJSE_Value_SetUTF8String( |
6424 args.GetReturnValue(), | 6424 args.GetReturnValue(), |
6425 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()) | 6425 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()) |
6426 .AsStringC()); | 6426 .AsStringC()); |
6427 } else { | 6427 } else { |
6428 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR); | 6428 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR); |
6429 } | 6429 } |
6430 } | 6430 } |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7132 FXJSE_Value_SetNull(m_pValue.get()); | 7132 FXJSE_Value_SetNull(m_pValue.get()); |
7133 FXJSE_Value_SetObject(m_pValue.get(), this, m_pFMClass); | 7133 FXJSE_Value_SetObject(m_pValue.get(), this, m_pFMClass); |
7134 } | 7134 } |
7135 | 7135 |
7136 CXFA_FM2JSContext::~CXFA_FM2JSContext() {} | 7136 CXFA_FM2JSContext::~CXFA_FM2JSContext() {} |
7137 | 7137 |
7138 void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { | 7138 void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { |
7139 FXJSE_Value_Set(pValue, m_pValue.get()); | 7139 FXJSE_Value_Set(pValue, m_pValue.get()); |
7140 } | 7140 } |
7141 | 7141 |
| 7142 int32_t CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, |
| 7143 CFX_WideTextBuf& wsJavascript, |
| 7144 CFX_WideString& wsError) const { |
| 7145 if (wsFormcalc.IsEmpty()) { |
| 7146 wsJavascript.Clear(); |
| 7147 wsError.clear(); |
| 7148 return 0; |
| 7149 } |
| 7150 int32_t status = 0; |
| 7151 CXFA_FMProgram program; |
| 7152 status = program.Init(wsFormcalc); |
| 7153 if (status) { |
| 7154 wsError = program.GetError().message; |
| 7155 return status; |
| 7156 } |
| 7157 status = program.ParseProgram(); |
| 7158 if (status) { |
| 7159 wsError = program.GetError().message; |
| 7160 return status; |
| 7161 } |
| 7162 program.TranslateProgram(wsJavascript); |
| 7163 return 0; |
| 7164 } |
| 7165 |
7142 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { | 7166 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { |
7143 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); | 7167 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
7144 ASSERT(pAppProvider); | 7168 ASSERT(pAppProvider); |
7145 CFX_WideString wsFormat; | 7169 CFX_WideString wsFormat; |
7146 pAppProvider->LoadString(iStringID, wsFormat); | 7170 pAppProvider->LoadString(iStringID, wsFormat); |
7147 CFX_WideString wsMessage; | 7171 CFX_WideString wsMessage; |
7148 va_list arg_ptr; | 7172 va_list arg_ptr; |
7149 va_start(arg_ptr, iStringID); | 7173 va_start(arg_ptr, iStringID); |
7150 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7174 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
7151 va_end(arg_ptr); | 7175 va_end(arg_ptr); |
7152 FXJSE_ThrowMessage( | 7176 FXJSE_ThrowMessage( |
7153 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7177 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
7154 } | 7178 } |
OLD | NEW |