| 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 CXFA_FM2JSContext::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 CXFA_FM2JSContext::Translate(scriptString.AsStringC(), wsJavaScriptBuf, |
| 6421 wsError); |
| 6421 if (wsError.IsEmpty()) { | 6422 if (wsError.IsEmpty()) { |
| 6422 CFX_WideString javaScript = wsJavaScriptBuf.MakeString(); | 6423 CFX_WideString javaScript = wsJavaScriptBuf.MakeString(); |
| 6423 FXJSE_Value_SetUTF8String( | 6424 FXJSE_Value_SetUTF8String( |
| 6424 args.GetReturnValue(), | 6425 args.GetReturnValue(), |
| 6425 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()) | 6426 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()) |
| 6426 .AsStringC()); | 6427 .AsStringC()); |
| 6427 } else { | 6428 } else { |
| 6428 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR); | 6429 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR); |
| 6429 } | 6430 } |
| 6430 } | 6431 } |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7115 if (FXJSE_Value_IsNull(arg) || FXJSE_Value_IsUndefined(arg)) { | 7116 if (FXJSE_Value_IsNull(arg) || FXJSE_Value_IsUndefined(arg)) { |
| 7116 szOutputString = ""; | 7117 szOutputString = ""; |
| 7117 } else if (FXJSE_Value_IsBoolean(arg)) { | 7118 } else if (FXJSE_Value_IsBoolean(arg)) { |
| 7118 szOutputString = FXJSE_Value_ToBoolean(arg) ? "1" : "0"; | 7119 szOutputString = FXJSE_Value_ToBoolean(arg) ? "1" : "0"; |
| 7119 } else { | 7120 } else { |
| 7120 szOutputString = ""; | 7121 szOutputString = ""; |
| 7121 FXJSE_Value_ToUTF8String(arg, szOutputString); | 7122 FXJSE_Value_ToUTF8String(arg, szOutputString); |
| 7122 } | 7123 } |
| 7123 } | 7124 } |
| 7124 | 7125 |
| 7126 // static. |
| 7127 int32_t CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, |
| 7128 CFX_WideTextBuf& wsJavascript, |
| 7129 CFX_WideString& wsError) { |
| 7130 if (wsFormcalc.IsEmpty()) { |
| 7131 wsJavascript.Clear(); |
| 7132 wsError.clear(); |
| 7133 return 0; |
| 7134 } |
| 7135 int32_t status = 0; |
| 7136 CXFA_FMProgram program; |
| 7137 status = program.Init(wsFormcalc); |
| 7138 if (status) { |
| 7139 wsError = program.GetError().message; |
| 7140 return status; |
| 7141 } |
| 7142 status = program.ParseProgram(); |
| 7143 if (status) { |
| 7144 wsError = program.GetError().message; |
| 7145 return status; |
| 7146 } |
| 7147 program.TranslateProgram(wsJavascript); |
| 7148 return 0; |
| 7149 } |
| 7150 |
| 7125 CXFA_FM2JSContext::CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, | 7151 CXFA_FM2JSContext::CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, |
| 7126 CFXJSE_Context* pScriptContext, | 7152 CFXJSE_Context* pScriptContext, |
| 7127 CXFA_Document* pDoc) | 7153 CXFA_Document* pDoc) |
| 7128 : m_pIsolate(pScriptIsolate), | 7154 : m_pIsolate(pScriptIsolate), |
| 7129 m_pFMClass(FXJSE_DefineClass(pScriptContext, &formcalc_fm2js_descriptor)), | 7155 m_pFMClass(FXJSE_DefineClass(pScriptContext, &formcalc_fm2js_descriptor)), |
| 7130 m_pValue(new CFXJSE_Value(pScriptIsolate)), | 7156 m_pValue(new CFXJSE_Value(pScriptIsolate)), |
| 7131 m_pDocument(pDoc) { | 7157 m_pDocument(pDoc) { |
| 7132 FXJSE_Value_SetNull(m_pValue.get()); | 7158 FXJSE_Value_SetNull(m_pValue.get()); |
| 7133 FXJSE_Value_SetObject(m_pValue.get(), this, m_pFMClass); | 7159 FXJSE_Value_SetObject(m_pValue.get(), this, m_pFMClass); |
| 7134 } | 7160 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 7145 CFX_WideString wsFormat; | 7171 CFX_WideString wsFormat; |
| 7146 pAppProvider->LoadString(iStringID, wsFormat); | 7172 pAppProvider->LoadString(iStringID, wsFormat); |
| 7147 CFX_WideString wsMessage; | 7173 CFX_WideString wsMessage; |
| 7148 va_list arg_ptr; | 7174 va_list arg_ptr; |
| 7149 va_start(arg_ptr, iStringID); | 7175 va_start(arg_ptr, iStringID); |
| 7150 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7176 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
| 7151 va_end(arg_ptr); | 7177 va_end(arg_ptr); |
| 7152 FXJSE_ThrowMessage( | 7178 FXJSE_ThrowMessage( |
| 7153 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7179 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
| 7154 } | 7180 } |
| OLD | NEW |