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/fxjse/class.h" | 7 #include "xfa/fxjse/class.h" |
8 | 8 |
9 #include "xfa/fxjse/cfxjse_arguments.h" | 9 #include "xfa/fxjse/cfxjse_arguments.h" |
10 #include "xfa/fxjse/context.h" | 10 #include "xfa/fxjse/context.h" |
11 #include "xfa/fxjse/scope_inline.h" | 11 #include "xfa/fxjse/scope_inline.h" |
12 #include "xfa/fxjse/util_inline.h" | 12 #include "xfa/fxjse/util_inline.h" |
13 #include "xfa/fxjse/value.h" | 13 #include "xfa/fxjse/value.h" |
14 | 14 |
15 static void FXJSE_V8ConstructorCallback_Wrapper( | 15 static void FXJSE_V8ConstructorCallback_Wrapper( |
16 const v8::FunctionCallbackInfo<v8::Value>& info); | 16 const v8::FunctionCallbackInfo<v8::Value>& info); |
17 static void FXJSE_V8FunctionCallback_Wrapper( | 17 static void FXJSE_V8FunctionCallback_Wrapper( |
18 const v8::FunctionCallbackInfo<v8::Value>& info); | 18 const v8::FunctionCallbackInfo<v8::Value>& info); |
19 static void FXJSE_V8GetterCallback_Wrapper( | 19 static void FXJSE_V8GetterCallback_Wrapper( |
20 v8::Local<v8::String> property, | 20 v8::Local<v8::String> property, |
21 const v8::PropertyCallbackInfo<v8::Value>& info); | 21 const v8::PropertyCallbackInfo<v8::Value>& info); |
22 static void FXJSE_V8SetterCallback_Wrapper( | 22 static void FXJSE_V8SetterCallback_Wrapper( |
23 v8::Local<v8::String> property, | 23 v8::Local<v8::String> property, |
24 v8::Local<v8::Value> value, | 24 v8::Local<v8::Value> value, |
25 const v8::PropertyCallbackInfo<void>& info); | 25 const v8::PropertyCallbackInfo<void>& info); |
26 | 26 |
27 FXJSE_HCLASS FXJSE_DefineClass(CFXJSE_Context* pContext, | 27 CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext, |
28 const FXJSE_CLASS* lpClass) { | 28 const FXJSE_CLASS* lpClass) { |
29 ASSERT(pContext); | 29 ASSERT(pContext); |
30 return reinterpret_cast<FXJSE_HCLASS>( | 30 return CFXJSE_Class::Create(pContext, lpClass, FALSE); |
31 CFXJSE_Class::Create(pContext, lpClass, FALSE)); | |
32 } | 31 } |
33 | 32 |
34 static void FXJSE_V8FunctionCallback_Wrapper( | 33 static void FXJSE_V8FunctionCallback_Wrapper( |
35 const v8::FunctionCallbackInfo<v8::Value>& info) { | 34 const v8::FunctionCallbackInfo<v8::Value>& info) { |
36 const FXJSE_FUNCTION* lpFunctionInfo = | 35 const FXJSE_FUNCTION* lpFunctionInfo = |
37 static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value()); | 36 static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value()); |
38 if (!lpFunctionInfo) { | 37 if (!lpFunctionInfo) { |
39 return; | 38 return; |
40 } | 39 } |
41 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); | 40 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 174 } |
176 | 175 |
177 CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { | 176 CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { |
178 const CFXJSE_ArgumentsImpl* lpArguments = | 177 const CFXJSE_ArgumentsImpl* lpArguments = |
179 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 178 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
180 v8::Local<v8::String> hString = (*lpArguments->m_pInfo)[index]->ToString(); | 179 v8::Local<v8::String> hString = (*lpArguments->m_pInfo)[index]->ToString(); |
181 v8::String::Utf8Value szStringVal(hString); | 180 v8::String::Utf8Value szStringVal(hString); |
182 return CFX_ByteString(*szStringVal); | 181 return CFX_ByteString(*szStringVal); |
183 } | 182 } |
184 | 183 |
185 void* CFXJSE_Arguments::GetObject(int32_t index, FXJSE_HCLASS hClass) const { | 184 void* CFXJSE_Arguments::GetObject(int32_t index, CFXJSE_Class* pClass) const { |
186 const CFXJSE_ArgumentsImpl* lpArguments = | 185 const CFXJSE_ArgumentsImpl* lpArguments = |
187 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 186 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
188 v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index]; | 187 v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index]; |
189 ASSERT(!hValue.IsEmpty()); | 188 ASSERT(!hValue.IsEmpty()); |
190 if (!hValue->IsObject()) { | 189 if (!hValue->IsObject()) { |
191 return NULL; | 190 return NULL; |
192 } | 191 } |
193 CFXJSE_Class* lpClass = reinterpret_cast<CFXJSE_Class*>(hClass); | 192 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); |
194 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass); | |
195 } | 193 } |
196 | 194 |
197 FXJSE_HVALUE CFXJSE_Arguments::GetReturnValue() { | 195 FXJSE_HVALUE CFXJSE_Arguments::GetReturnValue() { |
198 const CFXJSE_ArgumentsImpl* lpArguments = | 196 const CFXJSE_ArgumentsImpl* lpArguments = |
199 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 197 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
200 return reinterpret_cast<FXJSE_HVALUE>(lpArguments->m_pRetValue); | 198 return reinterpret_cast<FXJSE_HVALUE>(lpArguments->m_pRetValue); |
201 } | 199 } |
202 static void FXJSE_Context_GlobalObjToString( | 200 static void FXJSE_Context_GlobalObjToString( |
203 const v8::FunctionCallbackInfo<v8::Value>& info) { | 201 const v8::FunctionCallbackInfo<v8::Value>& info) { |
204 const FXJSE_CLASS* lpClass = | 202 const FXJSE_CLASS* lpClass = |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 306 } |
309 | 307 |
310 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 308 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
311 const CFX_ByteStringC& szName) { | 309 const CFX_ByteStringC& szName) { |
312 for (const auto& pClass : pContext->m_rgClasses) { | 310 for (const auto& pClass : pContext->m_rgClasses) { |
313 if (pClass->m_szClassName == szName) | 311 if (pClass->m_szClassName == szName) |
314 return pClass.get(); | 312 return pClass.get(); |
315 } | 313 } |
316 return nullptr; | 314 return nullptr; |
317 } | 315 } |
OLD | NEW |