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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 szPropertyName, | 120 szPropertyName, |
121 reinterpret_cast<FXJSE_HVALUE>(lpPropValue)); | 121 reinterpret_cast<FXJSE_HVALUE>(lpPropValue)); |
122 delete lpThisValue; | 122 delete lpThisValue; |
123 lpThisValue = NULL; | 123 lpThisValue = NULL; |
124 delete lpPropValue; | 124 delete lpPropValue; |
125 lpPropValue = NULL; | 125 lpPropValue = NULL; |
126 } | 126 } |
127 | 127 |
128 static void FXJSE_V8ConstructorCallback_Wrapper( | 128 static void FXJSE_V8ConstructorCallback_Wrapper( |
129 const v8::FunctionCallbackInfo<v8::Value>& info) { | 129 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 130 if (!info.IsConstructCall()) { |
| 131 return; |
| 132 } |
130 const FXJSE_CLASS* lpClassDefinition = | 133 const FXJSE_CLASS* lpClassDefinition = |
131 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 134 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); |
132 if (!lpClassDefinition) { | 135 if (!lpClassDefinition) { |
133 return; | 136 return; |
134 } | 137 } |
135 ASSERT(info.This()->InternalFieldCount()); | 138 ASSERT(info.This()->InternalFieldCount()); |
136 info.This()->SetAlignedPointerInInternalField(0, NULL); | 139 info.This()->SetAlignedPointerInInternalField(0, NULL); |
137 } | 140 } |
138 | 141 |
139 FXJSE_HRUNTIME CFXJSE_Arguments::GetRuntime() const { | 142 FXJSE_HRUNTIME CFXJSE_Arguments::GetRuntime() const { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 lpClassDefinition->properties[i].setProc | 263 lpClassDefinition->properties[i].setProc |
261 ? FXJSE_V8SetterCallback_Wrapper | 264 ? FXJSE_V8SetterCallback_Wrapper |
262 : NULL, | 265 : NULL, |
263 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY*>( | 266 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY*>( |
264 lpClassDefinition->properties + i)), | 267 lpClassDefinition->properties + i)), |
265 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 268 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
266 } | 269 } |
267 } | 270 } |
268 if (lpClassDefinition->methNum) { | 271 if (lpClassDefinition->methNum) { |
269 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { | 272 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { |
| 273 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( |
| 274 pIsolate, FXJSE_V8FunctionCallback_Wrapper, |
| 275 v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>( |
| 276 lpClassDefinition->methods + i))); |
| 277 fun->RemovePrototype(); |
270 hObjectTemplate->Set( | 278 hObjectTemplate->Set( |
271 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), | 279 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), |
272 v8::FunctionTemplate::New( | 280 fun, |
273 pIsolate, FXJSE_V8FunctionCallback_Wrapper, | |
274 v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>( | |
275 lpClassDefinition->methods + i))), | |
276 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 281 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
277 } | 282 } |
278 } | 283 } |
279 if (lpClassDefinition->constructor) { | 284 if (lpClassDefinition->constructor) { |
280 if (bIsJSGlobal) { | 285 if (bIsJSGlobal) { |
281 hObjectTemplate->Set( | 286 hObjectTemplate->Set( |
282 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 287 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
283 v8::FunctionTemplate::New( | 288 v8::FunctionTemplate::New( |
284 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 289 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
285 v8::External::New(pIsolate, | 290 v8::External::New(pIsolate, |
286 const_cast<FXJSE_CLASS*>(lpClassDefinition))), | 291 const_cast<FXJSE_CLASS*>(lpClassDefinition))), |
287 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 292 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
288 } else { | 293 } else { |
289 v8::Local<v8::Context> hLocalContext = | 294 v8::Local<v8::Context> hLocalContext = |
290 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); | 295 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); |
291 FXJSE_GetGlobalObjectFromContext(hLocalContext) | 296 FXJSE_GetGlobalObjectFromContext(hLocalContext) |
292 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 297 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
293 v8::Function::New( | 298 v8::Function::New( |
294 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 299 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
295 v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( | 300 v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( |
296 lpClassDefinition)))); | 301 lpClassDefinition)))); |
297 } | 302 } |
298 } | 303 } |
299 if (bIsJSGlobal) { | 304 if (bIsJSGlobal) { |
300 hObjectTemplate->Set( | 305 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( |
301 v8::String::NewFromUtf8(pIsolate, "toString"), | 306 pIsolate, FXJSE_Context_GlobalObjToString, |
302 v8::FunctionTemplate::New( | 307 v8::External::New(pIsolate, |
303 pIsolate, FXJSE_Context_GlobalObjToString, | 308 const_cast<FXJSE_CLASS*>(lpClassDefinition))); |
304 v8::External::New(pIsolate, | 309 fun->RemovePrototype(); |
305 const_cast<FXJSE_CLASS*>(lpClassDefinition)))); | 310 hObjectTemplate->Set(v8::String::NewFromUtf8(pIsolate, "toString"), fun); |
306 } | 311 } |
307 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); | 312 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); |
308 lpContext->m_rgClasses.Add(pClass); | 313 lpContext->m_rgClasses.Add(pClass); |
309 return pClass; | 314 return pClass; |
310 } | 315 } |
311 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 316 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
312 const CFX_ByteStringC& szName) { | 317 const CFX_ByteStringC& szName) { |
313 for (int count = pContext->m_rgClasses.GetSize(), i = 0; i < count; i++) { | 318 for (int count = pContext->m_rgClasses.GetSize(), i = 0; i < count; i++) { |
314 CFXJSE_Class* pClass = pContext->m_rgClasses[i]; | 319 CFXJSE_Class* pClass = pContext->m_rgClasses[i]; |
315 if (pClass->m_szClassName == szName) { | 320 if (pClass->m_szClassName == szName) { |
316 return pClass; | 321 return pClass; |
317 } | 322 } |
318 } | 323 } |
319 return NULL; | 324 return NULL; |
320 } | 325 } |
OLD | NEW |