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 #ifndef XFA_FXJSE_UTIL_INLINE_H_ | 7 #ifndef XFA_FXJSE_UTIL_INLINE_H_ |
8 #define XFA_FXJSE_UTIL_INLINE_H_ | 8 #define XFA_FXJSE_UTIL_INLINE_H_ |
9 | 9 |
10 #include "xfa/fxjse/context.h" | 10 #include "xfa/fxjse/context.h" |
11 | 11 |
12 static V8_INLINE v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext( | 12 static V8_INLINE v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext( |
13 const v8::Local<v8::Context>& hContext) { | 13 const v8::Local<v8::Context>& hContext) { |
14 return hContext->Global()->GetPrototype().As<v8::Object>(); | 14 return hContext->Global()->GetPrototype().As<v8::Object>(); |
15 } | 15 } |
16 static V8_INLINE void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, | 16 static V8_INLINE void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, |
17 void* lpNewBinding) { | 17 void* lpNewBinding) { |
18 ASSERT(!hObject.IsEmpty()); | 18 ASSERT(!hObject.IsEmpty()); |
19 ASSERT(hObject->InternalFieldCount() > 0); | 19 ASSERT(hObject->InternalFieldCount() > 0); |
20 hObject->SetAlignedPointerInInternalField(0, lpNewBinding); | 20 hObject->SetAlignedPointerInInternalField(0, lpNewBinding); |
21 } | 21 } |
22 static V8_INLINE void* FXJSE_RetrieveObjectBinding( | 22 static V8_INLINE void* FXJSE_RetrieveObjectBinding( |
23 const v8::Local<v8::Object>& hJSObject) { | 23 const v8::Local<v8::Object>& hJSObject, |
| 24 CFXJSE_Class* lpClass = NULL) { |
24 ASSERT(!hJSObject.IsEmpty()); | 25 ASSERT(!hJSObject.IsEmpty()); |
25 if (!hJSObject->IsObject()) { | 26 if (!hJSObject->IsObject()) { |
26 return NULL; | 27 return NULL; |
27 } | 28 } |
28 v8::Local<v8::Object> hObject = hJSObject; | 29 v8::Local<v8::Object> hObject = hJSObject; |
29 if (hObject->InternalFieldCount() == 0) { | 30 if (hObject->InternalFieldCount() == 0) { |
30 v8::Local<v8::Value> hProtoObject = hObject->GetPrototype(); | 31 v8::Local<v8::Value> hProtoObject = hObject->GetPrototype(); |
31 if (hProtoObject.IsEmpty() || !hProtoObject->IsObject()) { | 32 if (hProtoObject.IsEmpty() || !hProtoObject->IsObject()) { |
32 return NULL; | 33 return NULL; |
33 } | 34 } |
34 hObject = hProtoObject.As<v8::Object>(); | 35 hObject = hProtoObject.As<v8::Object>(); |
35 if (hObject->InternalFieldCount() == 0) { | 36 if (hObject->InternalFieldCount() == 0) { |
36 return NULL; | 37 return NULL; |
37 } | 38 } |
38 } | 39 } |
| 40 if (lpClass) { |
| 41 v8::Local<v8::FunctionTemplate> hClass = |
| 42 v8::Local<v8::FunctionTemplate>::New( |
| 43 lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate()); |
| 44 if (!hClass->HasInstance(hObject)) { |
| 45 return NULL; |
| 46 } |
| 47 } |
39 return hObject->GetAlignedPointerFromInternalField(0); | 48 return hObject->GetAlignedPointerFromInternalField(0); |
40 } | 49 } |
41 | 50 |
42 #endif // XFA_FXJSE_UTIL_INLINE_H_ | 51 #endif // XFA_FXJSE_UTIL_INLINE_H_ |
OLD | NEW |