Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fxjse / src / util_inline.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef FXJSE_UTIL_INLINE_H_\r
8 #define FXJSE_UTIL_INLINE_H_\r
9 static V8_INLINE v8::Local<v8::Object>  FXJSE_GetGlobalObjectFromContext(const v8::Local<v8::Context>& hContext)\r
10 {\r
11     return hContext->Global()->GetPrototype().As<v8::Object>();\r
12 }\r
13 static V8_INLINE void                                   FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, FX_LPVOID lpNewBinding)\r
14 {\r
15     ASSERT(!hObject.IsEmpty());\r
16     ASSERT(hObject->InternalFieldCount() > 0);\r
17     hObject->SetAlignedPointerInInternalField(0, lpNewBinding);\r
18 }\r
19 static V8_INLINE FX_LPVOID                              FXJSE_RetrieveObjectBinding(const v8::Local<v8::Object>& hJSObject, CFXJSE_Class* lpClass = NULL)\r
20 {\r
21     ASSERT(!hJSObject.IsEmpty());\r
22     if(!hJSObject->IsObject()) {\r
23         return NULL;\r
24     }\r
25     v8::Local<v8::Object> hObject = hJSObject;\r
26     if(hObject->InternalFieldCount() == 0) {\r
27         v8::Handle<v8::Value> hProtoObject = hObject->GetPrototype();\r
28         if(hProtoObject.IsEmpty() || !hProtoObject->IsObject()) {\r
29             return NULL;\r
30         }\r
31         hObject = hProtoObject.As<v8::Object>();\r
32         if(hObject->InternalFieldCount() == 0) {\r
33             return NULL;\r
34         }\r
35     }\r
36     if(lpClass) {\r
37         v8::Local<v8::FunctionTemplate> hClass = v8::Local<v8::FunctionTemplate>::New(lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate());\r
38         if(!hClass->HasInstance(hObject)) {\r
39             return NULL;\r
40         }\r
41     }\r
42     return hObject->GetAlignedPointerFromInternalField(0);\r
43 }\r
44 #endif\r