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 "fxjse/include/cfxjse_class.h" | 7 #include "fxjse/include/cfxjse_class.h" |
8 | 8 |
9 #include "fxjse/context.h" | 9 #include "fxjse/context.h" |
10 #include "fxjse/include/cfxjse_arguments.h" | 10 #include "fxjse/include/cfxjse_arguments.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 new CFXJSE_Value(info.GetIsolate())); | 97 new CFXJSE_Value(info.GetIsolate())); |
98 std::unique_ptr<CFXJSE_Value> lpPropValue( | 98 std::unique_ptr<CFXJSE_Value> lpPropValue( |
99 new CFXJSE_Value(info.GetIsolate())); | 99 new CFXJSE_Value(info.GetIsolate())); |
100 lpThisValue->ForceSetValue(info.This()); | 100 lpThisValue->ForceSetValue(info.This()); |
101 lpPropValue->ForceSetValue(value); | 101 lpPropValue->ForceSetValue(value); |
102 lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); | 102 lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); |
103 } | 103 } |
104 | 104 |
105 static void FXJSE_V8ConstructorCallback_Wrapper( | 105 static void FXJSE_V8ConstructorCallback_Wrapper( |
106 const v8::FunctionCallbackInfo<v8::Value>& info) { | 106 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 107 if (!info.IsConstructCall()) { |
| 108 return; |
| 109 } |
107 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = | 110 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = |
108 static_cast<FXJSE_CLASS_DESCRIPTOR*>( | 111 static_cast<FXJSE_CLASS_DESCRIPTOR*>( |
109 info.Data().As<v8::External>()->Value()); | 112 info.Data().As<v8::External>()->Value()); |
110 if (!lpClassDefinition) { | 113 if (!lpClassDefinition) { |
111 return; | 114 return; |
112 } | 115 } |
113 ASSERT(info.This()->InternalFieldCount()); | 116 ASSERT(info.This()->InternalFieldCount()); |
114 info.This()->SetAlignedPointerInInternalField(0, NULL); | 117 info.This()->SetAlignedPointerInInternalField(0, NULL); |
115 } | 118 } |
116 | 119 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 lpClassDefinition->properties[i].setProc | 224 lpClassDefinition->properties[i].setProc |
222 ? FXJSE_V8SetterCallback_Wrapper | 225 ? FXJSE_V8SetterCallback_Wrapper |
223 : NULL, | 226 : NULL, |
224 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( | 227 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( |
225 lpClassDefinition->properties + i)), | 228 lpClassDefinition->properties + i)), |
226 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 229 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
227 } | 230 } |
228 } | 231 } |
229 if (lpClassDefinition->methNum) { | 232 if (lpClassDefinition->methNum) { |
230 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { | 233 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { |
| 234 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( |
| 235 pIsolate, FXJSE_V8FunctionCallback_Wrapper, |
| 236 v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION_DESCRIPTOR*>( |
| 237 lpClassDefinition->methods + i))); |
| 238 fun->RemovePrototype(); |
231 hObjectTemplate->Set( | 239 hObjectTemplate->Set( |
232 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), | 240 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), |
233 v8::FunctionTemplate::New( | 241 fun, |
234 pIsolate, FXJSE_V8FunctionCallback_Wrapper, | |
235 v8::External::New(pIsolate, | |
236 const_cast<FXJSE_FUNCTION_DESCRIPTOR*>( | |
237 lpClassDefinition->methods + i))), | |
238 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 242 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
239 } | 243 } |
240 } | 244 } |
241 if (lpClassDefinition->constructor) { | 245 if (lpClassDefinition->constructor) { |
242 if (bIsJSGlobal) { | 246 if (bIsJSGlobal) { |
243 hObjectTemplate->Set( | 247 hObjectTemplate->Set( |
244 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 248 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
245 v8::FunctionTemplate::New( | 249 v8::FunctionTemplate::New( |
246 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 250 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
247 v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( | 251 v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( |
248 lpClassDefinition))), | 252 lpClassDefinition))), |
249 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 253 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
250 } else { | 254 } else { |
251 v8::Local<v8::Context> hLocalContext = | 255 v8::Local<v8::Context> hLocalContext = |
252 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); | 256 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); |
253 FXJSE_GetGlobalObjectFromContext(hLocalContext) | 257 FXJSE_GetGlobalObjectFromContext(hLocalContext) |
254 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 258 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
255 v8::Function::New( | 259 v8::Function::New( |
256 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 260 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
257 v8::External::New(pIsolate, | 261 v8::External::New(pIsolate, |
258 const_cast<FXJSE_CLASS_DESCRIPTOR*>( | 262 const_cast<FXJSE_CLASS_DESCRIPTOR*>( |
259 lpClassDefinition)))); | 263 lpClassDefinition)))); |
260 } | 264 } |
261 } | 265 } |
262 if (bIsJSGlobal) { | 266 if (bIsJSGlobal) { |
263 hObjectTemplate->Set( | 267 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( |
264 v8::String::NewFromUtf8(pIsolate, "toString"), | 268 pIsolate, FXJSE_Context_GlobalObjToString, |
265 v8::FunctionTemplate::New( | 269 v8::External::New( |
266 pIsolate, FXJSE_Context_GlobalObjToString, | 270 pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition))); |
267 v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( | 271 fun->RemovePrototype(); |
268 lpClassDefinition)))); | 272 hObjectTemplate->Set(v8::String::NewFromUtf8(pIsolate, "toString"), fun); |
269 } | 273 } |
270 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); | 274 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); |
271 lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass)); | 275 lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass)); |
272 return pClass; | 276 return pClass; |
273 } | 277 } |
274 | 278 |
275 CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext) | 279 CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext) |
276 : m_lpClassDefinition(nullptr), m_pContext(lpContext) {} | 280 : m_lpClassDefinition(nullptr), m_pContext(lpContext) {} |
277 | 281 |
278 CFXJSE_Class::~CFXJSE_Class() {} | 282 CFXJSE_Class::~CFXJSE_Class() {} |
279 | 283 |
280 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 284 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
281 const CFX_ByteStringC& szName) { | 285 const CFX_ByteStringC& szName) { |
282 for (const auto& pClass : pContext->m_rgClasses) { | 286 for (const auto& pClass : pContext->m_rgClasses) { |
283 if (pClass->m_szClassName == szName) | 287 if (pClass->m_szClassName == szName) |
284 return pClass.get(); | 288 return pClass.get(); |
285 } | 289 } |
286 return nullptr; | 290 return nullptr; |
287 } | 291 } |
OLD | NEW |