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 7161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7172 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS)); | 7172 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS)); |
7173 } | 7173 } |
7174 CXFA_FM2JSContext::~CXFA_FM2JSContext() { | 7174 CXFA_FM2JSContext::~CXFA_FM2JSContext() { |
7175 m_pDocument = NULL; | 7175 m_pDocument = NULL; |
7176 if (m_hValue) { | 7176 if (m_hValue) { |
7177 FXJSE_Value_Release(m_hValue); | 7177 FXJSE_Value_Release(m_hValue); |
7178 m_hValue = NULL; | 7178 m_hValue = NULL; |
7179 } | 7179 } |
7180 m_hScriptRuntime = NULL; | 7180 m_hScriptRuntime = NULL; |
7181 } | 7181 } |
7182 CXFA_FM2JSContext* CXFA_FM2JSContext::Create() { | |
7183 return new CXFA_FM2JSContext; | |
7184 } | |
7185 void CXFA_FM2JSContext::Initialize(FXJSE_HRUNTIME hScriptRuntime, | 7182 void CXFA_FM2JSContext::Initialize(FXJSE_HRUNTIME hScriptRuntime, |
7186 FXJSE_HCONTEXT hScriptContext, | 7183 FXJSE_HCONTEXT hScriptContext, |
7187 CXFA_Document* pDoc) { | 7184 CXFA_Document* pDoc) { |
7188 m_pDocument = pDoc; | 7185 m_pDocument = pDoc; |
7189 m_hScriptRuntime = hScriptRuntime; | 7186 m_hScriptRuntime = hScriptRuntime; |
7190 m_fmClass.name = "XFA_FM2JS_FormCalcClass"; | 7187 m_fmClass.name = "XFA_FM2JS_FormCalcClass"; |
7191 m_fmClass.constructor = NULL; | 7188 m_fmClass.constructor = NULL; |
7192 m_fmClass.properties = NULL; | 7189 m_fmClass.properties = NULL; |
7193 m_fmClass.methods = formcalc_fm2js_functions; | 7190 m_fmClass.methods = formcalc_fm2js_functions; |
7194 m_fmClass.propNum = 0; | 7191 m_fmClass.propNum = 0; |
7195 m_fmClass.methNum = | 7192 m_fmClass.methNum = |
7196 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); | 7193 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); |
7197 m_hFMClass = FXJSE_DefineClass(hScriptContext, &m_fmClass); | 7194 m_hFMClass = FXJSE_DefineClass(hScriptContext, &m_fmClass); |
7198 m_hValue = FXJSE_Value_Create(hScriptRuntime); | 7195 m_hValue = FXJSE_Value_Create(hScriptRuntime); |
7199 FXJSE_Value_SetNull(m_hValue); | 7196 FXJSE_Value_SetNull(m_hValue); |
7200 FXJSE_Value_SetObject(m_hValue, this, m_hFMClass); | 7197 FXJSE_Value_SetObject(m_hValue, this, m_hFMClass); |
7201 } | 7198 } |
7202 void CXFA_FM2JSContext::GlobalPropertyGetter(FXJSE_HVALUE hValue) { | 7199 void CXFA_FM2JSContext::GlobalPropertyGetter(FXJSE_HVALUE hValue) { |
7203 FXJSE_Value_Set(hValue, m_hValue); | 7200 FXJSE_Value_Set(hValue, m_hValue); |
7204 } | 7201 } |
7205 void CXFA_FM2JSContext::Release() { | |
7206 delete this; | |
7207 } | |
7208 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { | 7202 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) { |
7209 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); | 7203 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
7210 ASSERT(pAppProvider); | 7204 ASSERT(pAppProvider); |
7211 CFX_WideString wsFormat; | 7205 CFX_WideString wsFormat; |
7212 pAppProvider->LoadString(iStringID, wsFormat); | 7206 pAppProvider->LoadString(iStringID, wsFormat); |
7213 CFX_WideString wsMessage; | 7207 CFX_WideString wsMessage; |
7214 va_list arg_ptr; | 7208 va_list arg_ptr; |
7215 va_start(arg_ptr, iStringID); | 7209 va_start(arg_ptr, iStringID); |
7216 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7210 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
7217 va_end(arg_ptr); | 7211 va_end(arg_ptr); |
7218 FXJSE_ThrowMessage( | 7212 FXJSE_ThrowMessage( |
7219 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7213 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
7220 } | 7214 } |
OLD | NEW |