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" |
(...skipping 99 matching lines...) Loading... |
110 | 110 |
111 static void FXJSE_V8ConstructorCallback_Wrapper( | 111 static void FXJSE_V8ConstructorCallback_Wrapper( |
112 const v8::FunctionCallbackInfo<v8::Value>& info) { | 112 const v8::FunctionCallbackInfo<v8::Value>& info) { |
113 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = | 113 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = |
114 static_cast<FXJSE_CLASS_DESCRIPTOR*>( | 114 static_cast<FXJSE_CLASS_DESCRIPTOR*>( |
115 info.Data().As<v8::External>()->Value()); | 115 info.Data().As<v8::External>()->Value()); |
116 if (!lpClassDefinition) { | 116 if (!lpClassDefinition) { |
117 return; | 117 return; |
118 } | 118 } |
119 ASSERT(info.This()->InternalFieldCount()); | 119 ASSERT(info.This()->InternalFieldCount()); |
120 info.This()->SetAlignedPointerInInternalField(0, NULL); | 120 info.This()->SetAlignedPointerInInternalField(0, nullptr); |
121 } | 121 } |
122 | 122 |
123 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { | 123 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { |
124 return m_pRetValue->GetIsolate(); | 124 return m_pRetValue->GetIsolate(); |
125 } | 125 } |
126 | 126 |
127 int32_t CFXJSE_Arguments::GetLength() const { | 127 int32_t CFXJSE_Arguments::GetLength() const { |
128 return m_pInfo->Length(); | 128 return m_pInfo->Length(); |
129 } | 129 } |
130 | 130 |
(...skipping 54 matching lines...) Loading... |
185 .FromMaybe(v8::Local<v8::String>()); | 185 .FromMaybe(v8::Local<v8::String>()); |
186 info.GetReturnValue().Set(local_str); | 186 info.GetReturnValue().Set(local_str); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 CFXJSE_Class* CFXJSE_Class::Create( | 190 CFXJSE_Class* CFXJSE_Class::Create( |
191 CFXJSE_Context* lpContext, | 191 CFXJSE_Context* lpContext, |
192 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition, | 192 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition, |
193 FX_BOOL bIsJSGlobal) { | 193 FX_BOOL bIsJSGlobal) { |
194 if (!lpContext || !lpClassDefinition) { | 194 if (!lpContext || !lpClassDefinition) { |
195 return NULL; | 195 return nullptr; |
196 } | 196 } |
197 CFXJSE_Class* pClass = | 197 CFXJSE_Class* pClass = |
198 GetClassFromContext(lpContext, lpClassDefinition->name); | 198 GetClassFromContext(lpContext, lpClassDefinition->name); |
199 if (pClass) { | 199 if (pClass) { |
200 return pClass; | 200 return pClass; |
201 } | 201 } |
202 v8::Isolate* pIsolate = lpContext->m_pIsolate; | 202 v8::Isolate* pIsolate = lpContext->m_pIsolate; |
203 pClass = new CFXJSE_Class(lpContext); | 203 pClass = new CFXJSE_Class(lpContext); |
204 pClass->m_szClassName = lpClassDefinition->name; | 204 pClass->m_szClassName = lpClassDefinition->name; |
205 pClass->m_lpClassDefinition = lpClassDefinition; | 205 pClass->m_lpClassDefinition = lpClassDefinition; |
206 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); | 206 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); |
207 v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New( | 207 v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New( |
208 pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper, | 208 pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper, |
209 v8::External::New( | 209 v8::External::New( |
210 pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition))); | 210 pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition))); |
211 hFunctionTemplate->SetClassName( | 211 hFunctionTemplate->SetClassName( |
212 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name)); | 212 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name)); |
213 hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1); | 213 hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1); |
214 v8::Local<v8::ObjectTemplate> hObjectTemplate = | 214 v8::Local<v8::ObjectTemplate> hObjectTemplate = |
215 hFunctionTemplate->InstanceTemplate(); | 215 hFunctionTemplate->InstanceTemplate(); |
216 SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); | 216 SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); |
217 | 217 |
218 if (lpClassDefinition->propNum) { | 218 if (lpClassDefinition->propNum) { |
219 for (int32_t i = 0; i < lpClassDefinition->propNum; i++) { | 219 for (int32_t i = 0; i < lpClassDefinition->propNum; i++) { |
220 hObjectTemplate->SetNativeDataProperty( | 220 hObjectTemplate->SetNativeDataProperty( |
221 v8::String::NewFromUtf8(pIsolate, | 221 v8::String::NewFromUtf8(pIsolate, |
222 lpClassDefinition->properties[i].name), | 222 lpClassDefinition->properties[i].name), |
223 lpClassDefinition->properties[i].getProc | 223 lpClassDefinition->properties[i].getProc |
224 ? FXJSE_V8GetterCallback_Wrapper | 224 ? FXJSE_V8GetterCallback_Wrapper |
225 : NULL, | 225 : nullptr, |
226 lpClassDefinition->properties[i].setProc | 226 lpClassDefinition->properties[i].setProc |
227 ? FXJSE_V8SetterCallback_Wrapper | 227 ? FXJSE_V8SetterCallback_Wrapper |
228 : NULL, | 228 : nullptr, |
229 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( | 229 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( |
230 lpClassDefinition->properties + i)), | 230 lpClassDefinition->properties + i)), |
231 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 231 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
232 } | 232 } |
233 } | 233 } |
234 if (lpClassDefinition->methNum) { | 234 if (lpClassDefinition->methNum) { |
235 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { | 235 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { |
236 hObjectTemplate->Set( | 236 hObjectTemplate->Set( |
237 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), | 237 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), |
238 v8::FunctionTemplate::New( | 238 v8::FunctionTemplate::New( |
(...skipping 39 matching lines...) Loading... |
278 } | 278 } |
279 | 279 |
280 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 280 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
281 const CFX_ByteStringC& szName) { | 281 const CFX_ByteStringC& szName) { |
282 for (const auto& pClass : pContext->m_rgClasses) { | 282 for (const auto& pClass : pContext->m_rgClasses) { |
283 if (pClass->m_szClassName == szName) | 283 if (pClass->m_szClassName == szName) |
284 return pClass.get(); | 284 return pClass.get(); |
285 } | 285 } |
286 return nullptr; | 286 return nullptr; |
287 } | 287 } |
OLD | NEW |