Title: [125015] trunk/Source/WebCore
Revision
125015
Author
hara...@chromium.org
Date
2012-08-08 03:20:46 -0700 (Wed, 08 Aug 2012)

Log Message

[V8] Factor out V8BindingPerIsolateData from V8Binding to a separate file
https://bugs.webkit.org/show_bug.cgi?id=93333

Reviewed by Adam Barth.

This patch moves V8BindingPerIsolateData to V8BindingPerIsolateData.{h,cpp}.

To avoid circular #include dependency, I used OwnPtrs for m_stringCache,
m_integerCache, m_hiddenPropertyName and m_gcEventData.

No tests. No change in behavior.

* UseV8.cmake:
* WebCore.gypi:
* bindings/v8/ScriptGCEvent.cpp:
(WebCore::isolateGCEventData):
(WebCore::ScriptGCEvent::addEventListener):
(WebCore::ScriptGCEvent::removeEventListener):
(WebCore::ScriptGCEvent::gcPrologueCallback):
(WebCore::ScriptGCEvent::gcEpilogueCallback):
* bindings/v8/V8Binding.cpp:
* bindings/v8/V8Binding.h:
(GCEventData):
(WebCore):
* bindings/v8/V8BindingPerIsolateData.cpp: Added.
(WebCore):
(WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
(WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData):
(WebCore::V8BindingPerIsolateData::create):
(WebCore::V8BindingPerIsolateData::ensureInitialized):
(WebCore::V8BindingPerIsolateData::dispose):
(WebCore::V8BindingPerIsolateData::reportMemoryUsage):
* bindings/v8/V8BindingPerIsolateData.h: Added.
(WebCore):
(V8BindingPerIsolateData):
(WebCore::V8BindingPerIsolateData::current):
(WebCore::V8BindingPerIsolateData::rawTemplateMap):
(WebCore::V8BindingPerIsolateData::templateMap):
(WebCore::V8BindingPerIsolateData::toStringName):
(WebCore::V8BindingPerIsolateData::toStringTemplate):
(WebCore::V8BindingPerIsolateData::lazyEventListenerToStringTemplate):
(WebCore::V8BindingPerIsolateData::stringCache):
(WebCore::V8BindingPerIsolateData::integerCache):
(WebCore::V8BindingPerIsolateData::allStores):
(WebCore::V8BindingPerIsolateData::hiddenPropertyName):
(WebCore::V8BindingPerIsolateData::auxiliaryContext):
(WebCore::V8BindingPerIsolateData::registerDOMDataStore):
(WebCore::V8BindingPerIsolateData::unregisterDOMDataStore):
(WebCore::V8BindingPerIsolateData::domDataStore):
(WebCore::V8BindingPerIsolateData::setDOMDataStore):
(WebCore::V8BindingPerIsolateData::recursionLevel):
(WebCore::V8BindingPerIsolateData::incrementRecursionLevel):
(WebCore::V8BindingPerIsolateData::decrementRecursionLevel):
(WebCore::V8BindingPerIsolateData::globalHandleMap):
(WebCore::V8BindingPerIsolateData::internalScriptRecursionLevel):
(WebCore::V8BindingPerIsolateData::incrementInternalScriptRecursionLevel):
(WebCore::V8BindingPerIsolateData::decrementInternalScriptRecursionLevel):
(WebCore::V8BindingPerIsolateData::gcEventData):
(WebCore::V8BindingPerIsolateData::setShouldCollectGarbageSoon):
(WebCore::V8BindingPerIsolateData::clearShouldCollectGarbageSoon):
(WebCore::V8BindingPerIsolateData::shouldCollectGarbageSoon):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125014 => 125015)


--- trunk/Source/WebCore/ChangeLog	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/ChangeLog	2012-08-08 10:20:46 UTC (rev 125015)
@@ -1,3 +1,67 @@
+2012-08-08  Kentaro Hara  <hara...@chromium.org>
+
+        [V8] Factor out V8BindingPerIsolateData from V8Binding to a separate file
+        https://bugs.webkit.org/show_bug.cgi?id=93333
+
+        Reviewed by Adam Barth.
+
+        This patch moves V8BindingPerIsolateData to V8BindingPerIsolateData.{h,cpp}.
+
+        To avoid circular #include dependency, I used OwnPtrs for m_stringCache,
+        m_integerCache, m_hiddenPropertyName and m_gcEventData.
+
+        No tests. No change in behavior.
+
+        * UseV8.cmake:
+        * WebCore.gypi:
+        * bindings/v8/ScriptGCEvent.cpp:
+        (WebCore::isolateGCEventData):
+        (WebCore::ScriptGCEvent::addEventListener):
+        (WebCore::ScriptGCEvent::removeEventListener):
+        (WebCore::ScriptGCEvent::gcPrologueCallback):
+        (WebCore::ScriptGCEvent::gcEpilogueCallback):
+        * bindings/v8/V8Binding.cpp:
+        * bindings/v8/V8Binding.h:
+        (GCEventData):
+        (WebCore):
+        * bindings/v8/V8BindingPerIsolateData.cpp: Added.
+        (WebCore):
+        (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
+        (WebCore::V8BindingPerIsolateData::~V8BindingPerIsolateData):
+        (WebCore::V8BindingPerIsolateData::create):
+        (WebCore::V8BindingPerIsolateData::ensureInitialized):
+        (WebCore::V8BindingPerIsolateData::dispose):
+        (WebCore::V8BindingPerIsolateData::reportMemoryUsage):
+        * bindings/v8/V8BindingPerIsolateData.h: Added.
+        (WebCore):
+        (V8BindingPerIsolateData):
+        (WebCore::V8BindingPerIsolateData::current):
+        (WebCore::V8BindingPerIsolateData::rawTemplateMap):
+        (WebCore::V8BindingPerIsolateData::templateMap):
+        (WebCore::V8BindingPerIsolateData::toStringName):
+        (WebCore::V8BindingPerIsolateData::toStringTemplate):
+        (WebCore::V8BindingPerIsolateData::lazyEventListenerToStringTemplate):
+        (WebCore::V8BindingPerIsolateData::stringCache):
+        (WebCore::V8BindingPerIsolateData::integerCache):
+        (WebCore::V8BindingPerIsolateData::allStores):
+        (WebCore::V8BindingPerIsolateData::hiddenPropertyName):
+        (WebCore::V8BindingPerIsolateData::auxiliaryContext):
+        (WebCore::V8BindingPerIsolateData::registerDOMDataStore):
+        (WebCore::V8BindingPerIsolateData::unregisterDOMDataStore):
+        (WebCore::V8BindingPerIsolateData::domDataStore):
+        (WebCore::V8BindingPerIsolateData::setDOMDataStore):
+        (WebCore::V8BindingPerIsolateData::recursionLevel):
+        (WebCore::V8BindingPerIsolateData::incrementRecursionLevel):
+        (WebCore::V8BindingPerIsolateData::decrementRecursionLevel):
+        (WebCore::V8BindingPerIsolateData::globalHandleMap):
+        (WebCore::V8BindingPerIsolateData::internalScriptRecursionLevel):
+        (WebCore::V8BindingPerIsolateData::incrementInternalScriptRecursionLevel):
+        (WebCore::V8BindingPerIsolateData::decrementInternalScriptRecursionLevel):
+        (WebCore::V8BindingPerIsolateData::gcEventData):
+        (WebCore::V8BindingPerIsolateData::setShouldCollectGarbageSoon):
+        (WebCore::V8BindingPerIsolateData::clearShouldCollectGarbageSoon):
+        (WebCore::V8BindingPerIsolateData::shouldCollectGarbageSoon):
+
 2012-08-08  Pavel Feldman  <pfeld...@chromium.org>
 
         Web Inspector: show whitespace nodes if they are the only tag's children.

Modified: trunk/Source/WebCore/UseV8.cmake (125014 => 125015)


--- trunk/Source/WebCore/UseV8.cmake	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/UseV8.cmake	2012-08-08 10:20:46 UTC (rev 125015)
@@ -46,6 +46,7 @@
     bindings/v8/StaticDOMDataStore.cpp
     bindings/v8/V8AbstractEventListener.cpp
     bindings/v8/V8Binding.cpp
+    bindings/v8/V8BindingPerIsolateData.cpp
     bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp,
     bindings/v8/V8Collection.cpp
     bindings/v8/V8DOMMap.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (125014 => 125015)


--- trunk/Source/WebCore/WebCore.gypi	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/WebCore.gypi	2012-08-08 10:20:46 UTC (rev 125015)
@@ -2252,6 +2252,8 @@
             'bindings/v8/V8BindingMacros.h',
             'bindings/v8/V8BindingPerContextData.cpp',
             'bindings/v8/V8BindingPerContextData.h',
+            'bindings/v8/V8BindingPerIsolateData.cpp',
+            'bindings/v8/V8BindingPerIsolateData.h',
             'bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp',
             'bindings/v8/V8ConfigureDOMAttributesAndMethods.h',
             'bindings/v8/V8Collection.cpp',

Modified: trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp (125014 => 125015)


--- trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/bindings/v8/ScriptGCEvent.cpp	2012-08-08 10:20:46 UTC (rev 125015)
@@ -40,7 +40,7 @@
 
 namespace WebCore {
 
-static GCEventData& isolateGCEventData()
+static GCEventData* isolateGCEventData()
 {
     V8BindingPerIsolateData* isolateData = V8BindingPerIsolateData::current();
     ASSERT(isolateData);
@@ -49,7 +49,7 @@
 
 void ScriptGCEvent::addEventListener(ScriptGCEventListener* eventListener)
 {
-    GCEventData::GCEventListeners& listeners = isolateGCEventData().listeners();
+    GCEventData::GCEventListeners& listeners = isolateGCEventData()->listeners();
     if (listeners.isEmpty()) {
         v8::V8::AddGCPrologueCallback(ScriptGCEvent::gcPrologueCallback);
         v8::V8::AddGCEpilogueCallback(ScriptGCEvent::gcEpilogueCallback);
@@ -60,7 +60,7 @@
 void ScriptGCEvent::removeEventListener(ScriptGCEventListener* eventListener)
 {
     ASSERT(eventListener);
-    GCEventData::GCEventListeners& listeners = isolateGCEventData().listeners();
+    GCEventData::GCEventListeners& listeners = isolateGCEventData()->listeners();
     ASSERT(!listeners.isEmpty());
     size_t i = listeners.find(eventListener);
     ASSERT(i != notFound);
@@ -89,23 +89,23 @@
 
 void ScriptGCEvent::gcPrologueCallback(v8::GCType type, v8::GCCallbackFlags flags)
 {
-    GCEventData& gcEventData = isolateGCEventData();
-    gcEventData.startTime = WTF::monotonicallyIncreasingTime();
-    gcEventData.usedHeapSize = getUsedHeapSize();
+    GCEventData* gcEventData = isolateGCEventData();
+    gcEventData->startTime = WTF::monotonicallyIncreasingTime();
+    gcEventData->usedHeapSize = getUsedHeapSize();
 }
 
 void ScriptGCEvent::gcEpilogueCallback(v8::GCType type, v8::GCCallbackFlags flags)
 {
-    GCEventData& gcEventData = isolateGCEventData();
-    if (!gcEventData.usedHeapSize)
+    GCEventData* gcEventData = isolateGCEventData();
+    if (!gcEventData->usedHeapSize)
         return;
     double endTime = WTF::monotonicallyIncreasingTime();
     size_t usedHeapSize = getUsedHeapSize();
-    size_t collectedBytes = usedHeapSize > gcEventData.usedHeapSize ? 0 : gcEventData.usedHeapSize - usedHeapSize;
-    GCEventData::GCEventListeners& listeners = gcEventData.listeners();
+    size_t collectedBytes = usedHeapSize > gcEventData->usedHeapSize ? 0 : gcEventData->usedHeapSize - usedHeapSize;
+    GCEventData::GCEventListeners& listeners = gcEventData->listeners();
     for (GCEventData::GCEventListeners::iterator i = listeners.begin(); i != listeners.end(); ++i)
-        (*i)->didGC(gcEventData.startTime, endTime, collectedBytes);
-    gcEventData.clear();
+        (*i)->didGC(gcEventData->startTime, endTime, collectedBytes);
+    gcEventData->clear();
 }
     
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (125014 => 125015)


--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-08 10:20:46 UTC (rev 125015)
@@ -52,57 +52,6 @@
 
 namespace WebCore {
 
-
-V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate)
-    : m_domDataStore(0)
-    , m_constructorMode(ConstructorMode::CreateNewObject)
-    , m_recursionLevel(0)
-#ifndef NDEBUG
-    , m_internalScriptRecursionLevel(0)
-#endif
-    , m_shouldCollectGarbageSoon(false)
-{
-}
-
-V8BindingPerIsolateData::~V8BindingPerIsolateData()
-{
-}
-
-V8BindingPerIsolateData* V8BindingPerIsolateData::create(v8::Isolate* isolate)
-{
-    ASSERT(isolate);
-    ASSERT(!isolate->GetData());
-    V8BindingPerIsolateData* data = "" V8BindingPerIsolateData(isolate);
-    isolate->SetData(data);
-    return data;
-}
-
-void V8BindingPerIsolateData::ensureInitialized(v8::Isolate* isolate) 
-{
-    ASSERT(isolate);
-    if (!isolate->GetData()) 
-        create(isolate);
-}
-
-void V8BindingPerIsolateData::dispose(v8::Isolate* isolate)
-{
-    void* data = ""
-    delete static_cast<V8BindingPerIsolateData*>(data);
-    isolate->SetData(0);
-}
-
-void V8BindingPerIsolateData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
-{
-    MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::Binding);
-    info.addHashMap(m_rawTemplates);
-    info.addHashMap(m_templates);
-    info.addInstrumentedMember(m_stringCache);
-    info.addVector(m_domDataList);
-
-    for (size_t i = 0; i < m_domDataList.size(); i++)
-        info.addInstrumentedMember(m_domDataList[i]);
-}
-
 #if ENABLE(INSPECTOR)
 void V8BindingPerIsolateData::visitExternalStrings(ExternalStringVisitor* visitor)
 {

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (125014 => 125015)


--- trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-08 10:16:00 UTC (rev 125014)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-08 10:20:46 UTC (rev 125015)
@@ -36,6 +36,7 @@
 #include "Document.h"
 #include "PlatformString.h"
 #include "V8BindingMacros.h"
+#include "V8BindingPerIsolateData.h"
 #include "V8ConfigureDOMAttributesAndMethods.h"
 #include "V8DOMWrapper.h"
 #include "V8GCController.h"
@@ -68,6 +69,7 @@
         }
         GCEventListeners& listeners() { return m_listeners; }
 
+        // FIXME: Make these members private.
         double startTime;
         size_t usedHeapSize;
 
@@ -75,120 +77,6 @@
         GCEventListeners m_listeners;
     };
 
-    class ConstructorMode;
-
-#ifndef NDEBUG
-    typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap;
-#endif
-
-    class V8BindingPerIsolateData {
-    public:
-        static V8BindingPerIsolateData* create(v8::Isolate*);
-        static void ensureInitialized(v8::Isolate*);
-        static V8BindingPerIsolateData* current(v8::Isolate* isolate = 0)
-        {
-            if (UNLIKELY(!isolate))
-                isolate = v8::Isolate::GetCurrent();
-            ASSERT(isolate->GetData());
-            return static_cast<V8BindingPerIsolateData*>(isolate->GetData()); 
-        }
-        static void dispose(v8::Isolate*);
-
-        typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
-
-        TemplateMap& rawTemplateMap() { return m_rawTemplates; }
-        TemplateMap& templateMap() { return m_templates; }
-        v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
-        v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
-
-        v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
-        {
-            return m_lazyEventListenerToStringTemplate;
-        }
-
-        StringCache* stringCache() { return &m_stringCache; }
-        IntegerCache* integerCache() { return &m_integerCache; }
-
-#if ENABLE(INSPECTOR)
-        void visitExternalStrings(ExternalStringVisitor*);
-#endif
-        DOMDataList& allStores() { return m_domDataList; }
-
-        V8HiddenPropertyName* hiddenPropertyName() { return &m_hiddenPropertyName; }
-        v8::Persistent<v8::Context>& auxiliaryContext() { return m_auxiliaryContext; }
-
-        void registerDOMDataStore(DOMDataStore* domDataStore) 
-        {
-            m_domDataList.append(domDataStore);
-        }
-
-        void unregisterDOMDataStore(DOMDataStore* domDataStore)
-        {
-            ASSERT(m_domDataList.find(domDataStore));
-            m_domDataList.remove(m_domDataList.find(domDataStore));
-        }
-
-
-        DOMDataStore* domDataStore() { return m_domDataStore; }
-        // DOMDataStore is owned outside V8BindingPerIsolateData.
-        void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; }
-
-        int recursionLevel() const { return m_recursionLevel; }
-        int incrementRecursionLevel() { return ++m_recursionLevel; }
-        int decrementRecursionLevel() { return --m_recursionLevel; }
-
-#ifndef NDEBUG
-        GlobalHandleMap& globalHandleMap() { return m_globalHandleMap; }
-
-        int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
-        int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
-        int decrementInternalScriptRecursionLevel() { return --m_internalScriptRecursionLevel; }
-#endif
-
-        GCEventData& gcEventData() { return m_gcEventData; }
-
-        void reportMemoryUsage(MemoryObjectInfo*) const;
-
-        // Gives the system a hint that we should request garbage collection
-        // upon the next close or navigation event, because some expensive
-        // objects have been allocated that we want to take every opportunity
-        // to collect.
-        void setShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = true; }
-        void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
-        bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
-
-    private:
-        explicit V8BindingPerIsolateData(v8::Isolate*);
-        ~V8BindingPerIsolateData();
-
-        TemplateMap m_rawTemplates;
-        TemplateMap m_templates;
-        v8::Persistent<v8::String> m_toStringName;
-        v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
-        v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate;
-        StringCache m_stringCache;
-        IntegerCache m_integerCache;
-
-        DOMDataList m_domDataList;
-        DOMDataStore* m_domDataStore;
-
-        V8HiddenPropertyName m_hiddenPropertyName;
-        v8::Persistent<v8::Context> m_auxiliaryContext;
-
-        bool m_constructorMode;
-        friend class ConstructorMode;
-
-        int m_recursionLevel;
-
-#ifndef NDEBUG
-        GlobalHandleMap m_globalHandleMap;
-        int m_internalScriptRecursionLevel;
-#endif
-        GCEventData m_gcEventData;
-
-        bool m_shouldCollectGarbageSoon;
-    };
-
     class ConstructorMode {
     public:
         enum Mode {

Added: trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.cpp (0 => 125015)


--- trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.cpp	2012-08-08 10:20:46 UTC (rev 125015)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "V8BindingPerIsolateData.h"
+
+#include "V8Binding.h"
+
+namespace WebCore {
+
+V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate)
+    : m_stringCache(adoptPtr(new StringCache()))
+    , m_integerCache(adoptPtr(new IntegerCache()))
+    , m_domDataStore(0)
+    , m_hiddenPropertyName(adoptPtr(new V8HiddenPropertyName()))
+    , m_constructorMode(ConstructorMode::CreateNewObject)
+    , m_recursionLevel(0)
+#ifndef NDEBUG
+    , m_internalScriptRecursionLevel(0)
+#endif
+    , m_gcEventData(adoptPtr(new GCEventData()))
+    , m_shouldCollectGarbageSoon(false)
+{
+}
+
+V8BindingPerIsolateData::~V8BindingPerIsolateData()
+{
+}
+
+V8BindingPerIsolateData* V8BindingPerIsolateData::create(v8::Isolate* isolate)
+{
+    ASSERT(isolate);
+    ASSERT(!isolate->GetData());
+    V8BindingPerIsolateData* data = "" V8BindingPerIsolateData(isolate);
+    isolate->SetData(data);
+    return data;
+}
+
+void V8BindingPerIsolateData::ensureInitialized(v8::Isolate* isolate) 
+{
+    ASSERT(isolate);
+    if (!isolate->GetData()) 
+        create(isolate);
+}
+
+void V8BindingPerIsolateData::dispose(v8::Isolate* isolate)
+{
+    void* data = ""
+    delete static_cast<V8BindingPerIsolateData*>(data);
+    isolate->SetData(0);
+}
+
+void V8BindingPerIsolateData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::Binding);
+    info.addHashMap(m_rawTemplates);
+    info.addHashMap(m_templates);
+    info.addInstrumentedMember(m_stringCache);
+    info.addVector(m_domDataList);
+
+    for (size_t i = 0; i < m_domDataList.size(); i++)
+        info.addInstrumentedMember(m_domDataList[i]);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.h (0 => 125015)


--- trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8BindingPerIsolateData.h	2012-08-08 10:20:46 UTC (rev 125015)
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef V8BindingPerIsolateData_h
+#define V8BindingPerIsolateData_h
+
+#include <v8.h>
+#include <wtf/HashMap.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class DOMDataStore;
+class GCEventData;
+class IntegerCache;
+class MemoryObjectInfo;
+class StringCache;
+class V8HiddenPropertyName;
+class WrapperTypeInfo;
+
+#if ENABLE(INSPECTOR)
+class ExternalStringVisitor;
+#endif
+
+typedef WTF::Vector<DOMDataStore*> DOMDataList;
+
+#ifndef NDEBUG
+class GlobalHandleInfo;
+typedef HashMap<v8::Value*, GlobalHandleInfo*> GlobalHandleMap;
+#endif
+
+class V8BindingPerIsolateData {
+public:
+    static V8BindingPerIsolateData* create(v8::Isolate*);
+    static void ensureInitialized(v8::Isolate*);
+    static V8BindingPerIsolateData* current(v8::Isolate* isolate = 0)
+    {
+        if (UNLIKELY(!isolate))
+            isolate = v8::Isolate::GetCurrent();
+        ASSERT(isolate->GetData());
+        return static_cast<V8BindingPerIsolateData*>(isolate->GetData()); 
+    }
+    static void dispose(v8::Isolate*);
+
+    typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
+
+    TemplateMap& rawTemplateMap() { return m_rawTemplates; }
+    TemplateMap& templateMap() { return m_templates; }
+    v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
+    v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
+
+    v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
+    {
+        return m_lazyEventListenerToStringTemplate;
+    }
+
+    StringCache* stringCache() { return m_stringCache.get(); }
+    IntegerCache* integerCache() { return m_integerCache.get(); }
+
+#if ENABLE(INSPECTOR)
+    void visitExternalStrings(ExternalStringVisitor*);
+#endif
+    DOMDataList& allStores() { return m_domDataList; }
+
+    V8HiddenPropertyName* hiddenPropertyName() { return m_hiddenPropertyName.get(); }
+    v8::Persistent<v8::Context>& auxiliaryContext() { return m_auxiliaryContext; }
+
+    void registerDOMDataStore(DOMDataStore* domDataStore) 
+    {
+        m_domDataList.append(domDataStore);
+    }
+
+    void unregisterDOMDataStore(DOMDataStore* domDataStore)
+    {
+        ASSERT(m_domDataList.find(domDataStore));
+        m_domDataList.remove(m_domDataList.find(domDataStore));
+    }
+
+    // DOMDataStore is owned outside V8BindingPerIsolateData.
+    DOMDataStore* domDataStore() { return m_domDataStore; }
+    void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; }
+
+    int recursionLevel() const { return m_recursionLevel; }
+    int incrementRecursionLevel() { return ++m_recursionLevel; }
+    int decrementRecursionLevel() { return --m_recursionLevel; }
+
+#ifndef NDEBUG
+    GlobalHandleMap& globalHandleMap() { return m_globalHandleMap; }
+
+    int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
+    int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
+    int decrementInternalScriptRecursionLevel() { return --m_internalScriptRecursionLevel; }
+#endif
+
+    GCEventData* gcEventData() { return m_gcEventData.get(); }
+
+    void reportMemoryUsage(MemoryObjectInfo*) const;
+
+    // Gives the system a hint that we should request garbage collection
+    // upon the next close or navigation event, because some expensive
+    // objects have been allocated that we want to take every opportunity
+    // to collect.
+    void setShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = true; }
+    void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
+    bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
+
+private:
+    explicit V8BindingPerIsolateData(v8::Isolate*);
+    ~V8BindingPerIsolateData();
+
+    TemplateMap m_rawTemplates;
+    TemplateMap m_templates;
+    v8::Persistent<v8::String> m_toStringName;
+    v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
+    v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate;
+    OwnPtr<StringCache> m_stringCache;
+    OwnPtr<IntegerCache> m_integerCache;
+
+    DOMDataList m_domDataList;
+    DOMDataStore* m_domDataStore;
+
+    OwnPtr<V8HiddenPropertyName> m_hiddenPropertyName;
+    v8::Persistent<v8::Context> m_auxiliaryContext;
+
+    bool m_constructorMode;
+    friend class ConstructorMode;
+
+    int m_recursionLevel;
+
+#ifndef NDEBUG
+    GlobalHandleMap m_globalHandleMap;
+    int m_internalScriptRecursionLevel;
+#endif
+    OwnPtr<GCEventData> m_gcEventData;
+    bool m_shouldCollectGarbageSoon;
+};
+
+} // namespace WebCore
+
+#endif // V8BindingPerIsolateData_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to