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