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 |
(...skipping 3221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3232 HValueToUTF8String(scriptValue, utf8ScriptString); | 3232 HValueToUTF8String(scriptValue, utf8ScriptString); |
3233 if (utf8ScriptString.IsEmpty()) { | 3233 if (utf8ScriptString.IsEmpty()) { |
3234 FXJSE_Value_SetNull(args.GetReturnValue()); | 3234 FXJSE_Value_SetNull(args.GetReturnValue()); |
3235 } else { | 3235 } else { |
3236 CFX_WideTextBuf wsJavaScriptBuf; | 3236 CFX_WideTextBuf wsJavaScriptBuf; |
3237 CFX_WideString javaScript; | 3237 CFX_WideString javaScript; |
3238 CFX_WideString wsError; | 3238 CFX_WideString wsError; |
3239 XFA_FM2JS_Translate( | 3239 XFA_FM2JS_Translate( |
3240 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), | 3240 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), |
3241 wsJavaScriptBuf, wsError); | 3241 wsJavaScriptBuf, wsError); |
3242 FXJSE_HCONTEXT hContext = FXJSE_Context_Create(pIsolate); | 3242 CFXJSE_Context* pContext = FXJSE_Context_Create(pIsolate); |
3243 FXJSE_HVALUE returnValue = FXJSE_Value_Create(pIsolate); | 3243 FXJSE_HVALUE returnValue = FXJSE_Value_Create(pIsolate); |
3244 javaScript = wsJavaScriptBuf.AsStringC(); | 3244 javaScript = wsJavaScriptBuf.AsStringC(); |
3245 FXJSE_ExecuteScript( | 3245 FXJSE_ExecuteScript( |
3246 hContext, | 3246 pContext, |
3247 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), | 3247 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), |
3248 returnValue); | 3248 returnValue); |
3249 FXJSE_Value_Set(args.GetReturnValue(), returnValue); | 3249 FXJSE_Value_Set(args.GetReturnValue(), returnValue); |
3250 FXJSE_Value_Release(returnValue); | 3250 FXJSE_Value_Release(returnValue); |
3251 FXJSE_Context_Release(hContext); | 3251 FXJSE_Context_Release(pContext); |
3252 } | 3252 } |
3253 FXJSE_Value_Release(scriptValue); | 3253 FXJSE_Value_Release(scriptValue); |
3254 } else { | 3254 } else { |
3255 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, | 3255 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, |
3256 L"Eval"); | 3256 L"Eval"); |
3257 } | 3257 } |
3258 } | 3258 } |
3259 void CXFA_FM2JSContext::Ref(FXJSE_HOBJECT hThis, | 3259 void CXFA_FM2JSContext::Ref(FXJSE_HOBJECT hThis, |
3260 const CFX_ByteStringC& szFuncName, | 3260 const CFX_ByteStringC& szFuncName, |
3261 CFXJSE_Arguments& args) { | 3261 CFXJSE_Arguments& args) { |
(...skipping 3906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7168 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS)); | 7168 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS)); |
7169 } | 7169 } |
7170 CXFA_FM2JSContext::~CXFA_FM2JSContext() { | 7170 CXFA_FM2JSContext::~CXFA_FM2JSContext() { |
7171 m_pDocument = NULL; | 7171 m_pDocument = NULL; |
7172 if (m_hValue) { | 7172 if (m_hValue) { |
7173 FXJSE_Value_Release(m_hValue); | 7173 FXJSE_Value_Release(m_hValue); |
7174 m_hValue = NULL; | 7174 m_hValue = NULL; |
7175 } | 7175 } |
7176 m_pIsolate = NULL; | 7176 m_pIsolate = NULL; |
7177 } | 7177 } |
7178 void CXFA_FM2JSContext::Initialize(v8::Isolate* hScriptRuntime, | 7178 void CXFA_FM2JSContext::Initialize(v8::Isolate* pScriptIsolate, |
7179 FXJSE_HCONTEXT hScriptContext, | 7179 CFXJSE_Context* pScriptContext, |
7180 CXFA_Document* pDoc) { | 7180 CXFA_Document* pDoc) { |
7181 m_pDocument = pDoc; | 7181 m_pDocument = pDoc; |
7182 m_pIsolate = hScriptRuntime; | 7182 m_pIsolate = pScriptIsolate; |
7183 m_fmClass.name = "XFA_FM2JS_FormCalcClass"; | 7183 m_fmClass.name = "XFA_FM2JS_FormCalcClass"; |
7184 m_fmClass.constructor = NULL; | 7184 m_fmClass.constructor = NULL; |
7185 m_fmClass.properties = NULL; | 7185 m_fmClass.properties = NULL; |
7186 m_fmClass.methods = formcalc_fm2js_functions; | 7186 m_fmClass.methods = formcalc_fm2js_functions; |
7187 m_fmClass.propNum = 0; | 7187 m_fmClass.propNum = 0; |
7188 m_fmClass.methNum = | 7188 m_fmClass.methNum = |
7189 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); | 7189 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); |
7190 m_hFMClass = FXJSE_DefineClass(hScriptContext, &m_fmClass); | 7190 m_hFMClass = FXJSE_DefineClass(pScriptContext, &m_fmClass); |
7191 m_hValue = FXJSE_Value_Create(hScriptRuntime); | 7191 m_hValue = FXJSE_Value_Create(pScriptIsolate); |
7192 FXJSE_Value_SetNull(m_hValue); | 7192 FXJSE_Value_SetNull(m_hValue); |
7193 FXJSE_Value_SetObject(m_hValue, this, m_hFMClass); | 7193 FXJSE_Value_SetObject(m_hValue, this, m_hFMClass); |
7194 } | 7194 } |
7195 void CXFA_FM2JSContext::GlobalPropertyGetter(FXJSE_HVALUE hValue) { | 7195 void CXFA_FM2JSContext::GlobalPropertyGetter(FXJSE_HVALUE hValue) { |
7196 FXJSE_Value_Set(hValue, m_hValue); | 7196 FXJSE_Value_Set(hValue, m_hValue); |
7197 } | 7197 } |
7198 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { | 7198 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { |
7199 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); | 7199 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
7200 ASSERT(pAppProvider); | 7200 ASSERT(pAppProvider); |
7201 CFX_WideString wsFormat; | 7201 CFX_WideString wsFormat; |
7202 pAppProvider->LoadString(iStringID, wsFormat); | 7202 pAppProvider->LoadString(iStringID, wsFormat); |
7203 CFX_WideString wsMessage; | 7203 CFX_WideString wsMessage; |
7204 va_list arg_ptr; | 7204 va_list arg_ptr; |
7205 va_start(arg_ptr, iStringID); | 7205 va_start(arg_ptr, iStringID); |
7206 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7206 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
7207 va_end(arg_ptr); | 7207 va_end(arg_ptr); |
7208 FXJSE_ThrowMessage( | 7208 FXJSE_ThrowMessage( |
7209 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7209 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
7210 } | 7210 } |
OLD | NEW |