Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / v8 / WrapperTypeInfo.h
index aaea3f6..2813aa6 100644 (file)
 #define WrapperTypeInfo_h
 
 #include "gin/public/wrapper_info.h"
+#include "heap/Handle.h"
 #include "wtf/Assertions.h"
 #include <v8.h>
 
 namespace WebCore {
 
     class ActiveDOMObject;
-    class DOMDataStore;
     class EventTarget;
     class Node;
 
@@ -102,12 +102,6 @@ namespace WebCore {
 
         v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate* isolate, WrapperWorldType worldType) const { return domTemplateFunction(isolate, worldType); }
 
-        void derefObject(void* object) const
-        {
-            if (derefObjectFunction)
-                derefObjectFunction(object);
-        }
-
         void installPerContextEnabledMethods(v8::Handle<v8::Object> prototypeTemplate, v8::Isolate* isolate) const
         {
             if (installPerContextEnabledMethodsFunction)
@@ -147,6 +141,7 @@ namespace WebCore {
         const InstallPerContextEnabledPrototypePropertiesFunction installPerContextEnabledMethodsFunction;
         const WrapperTypeInfo* parentClass;
         const WrapperTypePrototype wrapperTypePrototype;
+        const bool isGarbageCollected;
     };
 
 
@@ -162,30 +157,54 @@ namespace WebCore {
     }
 
     template<typename T, int offset>
-    inline T* getInternalField(v8::Handle<v8::Object> object)
+    inline T* getInternalField(v8::Handle<v8::Object> wrapper)
     {
-        ASSERT(offset < object->InternalFieldCount());
-        return static_cast<T*>(object->GetAlignedPointerFromInternalField(offset));
+        ASSERT(offset < wrapper->InternalFieldCount());
+        return static_cast<T*>(wrapper->GetAlignedPointerFromInternalField(offset));
+    }
+
+    inline void* toNative(const v8::Persistent<v8::Object>& wrapper)
+    {
+        return getInternalField<void, v8DOMWrapperObjectIndex>(wrapper);
+    }
+
+    inline void* toNative(v8::Handle<v8::Object> wrapper)
+    {
+        return getInternalField<void, v8DOMWrapperObjectIndex>(wrapper);
     }
 
-    inline void* toNative(const v8::Persistent<v8::Object>& object)
+    inline const WrapperTypeInfo* toWrapperTypeInfo(const v8::Persistent<v8::Object>& wrapper)
     {
-        return getInternalField<void, v8DOMWrapperObjectIndex>(object);
+        return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper);
     }
 
-    inline void* toNative(v8::Handle<v8::Object> object)
+    inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Handle<v8::Object> wrapper)
     {
-        return getInternalField<void, v8DOMWrapperObjectIndex>(object);
+        return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper);
     }
 
-    inline const WrapperTypeInfo* toWrapperTypeInfo(const v8::Persistent<v8::Object>& object)
+    inline const PersistentNode* toPersistentHandle(const v8::Handle<v8::Object>& wrapper)
     {
-        return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object);
+        // Persistent handle is stored in the last internal field.
+        return static_cast<PersistentNode*>(wrapper->GetAlignedPointerFromInternalField(wrapper->InternalFieldCount() - 1));
     }
 
-    inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Handle<v8::Object> object)
+    inline void releaseObject(v8::Handle<v8::Object> wrapper)
     {
-        return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object);
+        const WrapperTypeInfo* typeInfo = toWrapperTypeInfo(wrapper);
+#if ENABLE(OILPAN)
+        if (typeInfo->isGarbageCollected) {
+            const PersistentNode* handle = toPersistentHandle(wrapper);
+            ASSERT(handle);
+            delete handle;
+        } else {
+            ASSERT(typeInfo->derefObjectFunction);
+            typeInfo->derefObjectFunction(toNative(wrapper));
+        }
+#else
+        ASSERT(typeInfo->derefObjectFunction);
+        typeInfo->derefObjectFunction(toNative(wrapper));
+#endif
     }
 
     struct WrapperConfiguration {