| 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 7054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7065 CFX_ByteString& szOutputString) { | 7065 CFX_ByteString& szOutputString) { |
| 7066 if (FXJSE_Value_IsNull(arg) || FXJSE_Value_IsUndefined(arg)) { | 7066 if (FXJSE_Value_IsNull(arg) || FXJSE_Value_IsUndefined(arg)) { |
| 7067 szOutputString = ""; | 7067 szOutputString = ""; |
| 7068 } else if (FXJSE_Value_IsBoolean(arg)) { | 7068 } else if (FXJSE_Value_IsBoolean(arg)) { |
| 7069 szOutputString = FXJSE_Value_ToBoolean(arg) ? "1" : "0"; | 7069 szOutputString = FXJSE_Value_ToBoolean(arg) ? "1" : "0"; |
| 7070 } else { | 7070 } else { |
| 7071 szOutputString = ""; | 7071 szOutputString = ""; |
| 7072 FXJSE_Value_ToUTF8String(arg, szOutputString); | 7072 FXJSE_Value_ToUTF8String(arg, szOutputString); |
| 7073 } | 7073 } |
| 7074 } | 7074 } |
| 7075 static FXJSE_FUNCTION formcalc_fm2js_functions[] = { | 7075 static FXJSE_FUNCTION_DESCRIPTOR formcalc_fm2js_functions[] = { |
| 7076 {"Abs", CXFA_FM2JSContext::Abs}, | 7076 {"Abs", CXFA_FM2JSContext::Abs}, |
| 7077 {"Avg", CXFA_FM2JSContext::Avg}, | 7077 {"Avg", CXFA_FM2JSContext::Avg}, |
| 7078 {"Ceil", CXFA_FM2JSContext::Ceil}, | 7078 {"Ceil", CXFA_FM2JSContext::Ceil}, |
| 7079 {"Count", CXFA_FM2JSContext::Count}, | 7079 {"Count", CXFA_FM2JSContext::Count}, |
| 7080 {"Floor", CXFA_FM2JSContext::Floor}, | 7080 {"Floor", CXFA_FM2JSContext::Floor}, |
| 7081 {"Max", CXFA_FM2JSContext::Max}, | 7081 {"Max", CXFA_FM2JSContext::Max}, |
| 7082 {"Min", CXFA_FM2JSContext::Min}, | 7082 {"Min", CXFA_FM2JSContext::Min}, |
| 7083 {"Mod", CXFA_FM2JSContext::Mod}, | 7083 {"Mod", CXFA_FM2JSContext::Mod}, |
| 7084 {"Round", CXFA_FM2JSContext::Round}, | 7084 {"Round", CXFA_FM2JSContext::Round}, |
| 7085 {"Sum", CXFA_FM2JSContext::Sum}, | 7085 {"Sum", CXFA_FM2JSContext::Sum}, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7160 {"dotdot_accessor", CXFA_FM2JSContext::dotdot_accessor}, | 7160 {"dotdot_accessor", CXFA_FM2JSContext::dotdot_accessor}, |
| 7161 {"concat_fm_object", CXFA_FM2JSContext::concat_fm_object}, | 7161 {"concat_fm_object", CXFA_FM2JSContext::concat_fm_object}, |
| 7162 {"is_fm_object", CXFA_FM2JSContext::is_fm_object}, | 7162 {"is_fm_object", CXFA_FM2JSContext::is_fm_object}, |
| 7163 {"is_fm_array", CXFA_FM2JSContext::is_fm_array}, | 7163 {"is_fm_array", CXFA_FM2JSContext::is_fm_array}, |
| 7164 {"get_fm_value", CXFA_FM2JSContext::get_fm_value}, | 7164 {"get_fm_value", CXFA_FM2JSContext::get_fm_value}, |
| 7165 {"get_fm_jsobj", CXFA_FM2JSContext::get_fm_jsobj}, | 7165 {"get_fm_jsobj", CXFA_FM2JSContext::get_fm_jsobj}, |
| 7166 {"fm_var_filter", CXFA_FM2JSContext::fm_var_filter}, | 7166 {"fm_var_filter", CXFA_FM2JSContext::fm_var_filter}, |
| 7167 }; | 7167 }; |
| 7168 CXFA_FM2JSContext::CXFA_FM2JSContext() | 7168 CXFA_FM2JSContext::CXFA_FM2JSContext() |
| 7169 : m_pFMClass(nullptr), m_pDocument(nullptr) { | 7169 : m_pFMClass(nullptr), m_pDocument(nullptr) { |
| 7170 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS)); | 7170 FXSYS_memset(&m_ClassDescriptor, 0, sizeof(FXJSE_CLASS_DESCRIPTOR)); |
| 7171 } | 7171 } |
| 7172 | 7172 |
| 7173 CXFA_FM2JSContext::~CXFA_FM2JSContext() { | 7173 CXFA_FM2JSContext::~CXFA_FM2JSContext() { |
| 7174 if (m_pValue) | 7174 if (m_pValue) |
| 7175 FXJSE_Value_Release(m_pValue); | 7175 FXJSE_Value_Release(m_pValue); |
| 7176 } | 7176 } |
| 7177 | 7177 |
| 7178 void CXFA_FM2JSContext::Initialize(v8::Isolate* pScriptIsolate, | 7178 void CXFA_FM2JSContext::Initialize(v8::Isolate* pScriptIsolate, |
| 7179 CFXJSE_Context* pScriptContext, | 7179 CFXJSE_Context* pScriptContext, |
| 7180 CXFA_Document* pDoc) { | 7180 CXFA_Document* pDoc) { |
| 7181 m_pDocument = pDoc; | 7181 m_pDocument = pDoc; |
| 7182 m_pIsolate = pScriptIsolate; | 7182 m_pIsolate = pScriptIsolate; |
| 7183 m_fmClass.name = "XFA_FM2JS_FormCalcClass"; | 7183 m_ClassDescriptor.name = "XFA_FM2JS_FormCalcClass"; |
| 7184 m_fmClass.constructor = NULL; | 7184 m_ClassDescriptor.constructor = NULL; |
| 7185 m_fmClass.properties = NULL; | 7185 m_ClassDescriptor.properties = NULL; |
| 7186 m_fmClass.methods = formcalc_fm2js_functions; | 7186 m_ClassDescriptor.methods = formcalc_fm2js_functions; |
| 7187 m_fmClass.propNum = 0; | 7187 m_ClassDescriptor.propNum = 0; |
| 7188 m_fmClass.methNum = | 7188 m_ClassDescriptor.methNum = |
| 7189 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); | 7189 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]); |
| 7190 m_pFMClass = FXJSE_DefineClass(pScriptContext, &m_fmClass); | 7190 m_pFMClass = FXJSE_DefineClass(pScriptContext, &m_ClassDescriptor); |
| 7191 m_pValue = FXJSE_Value_Create(pScriptIsolate); | 7191 m_pValue = FXJSE_Value_Create(pScriptIsolate); |
| 7192 FXJSE_Value_SetNull(m_pValue); | 7192 FXJSE_Value_SetNull(m_pValue); |
| 7193 FXJSE_Value_SetObject(m_pValue, this, m_pFMClass); | 7193 FXJSE_Value_SetObject(m_pValue, this, m_pFMClass); |
| 7194 } | 7194 } |
| 7195 void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { | 7195 void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { |
| 7196 FXJSE_Value_Set(pValue, m_pValue); | 7196 FXJSE_Value_Set(pValue, m_pValue); |
| 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 |