Title: [125242] trunk/Source/WebCore
Revision
125242
Author
[email protected]
Date
2012-08-09 20:05:10 -0700 (Thu, 09 Aug 2012)

Log Message

[V8] Rename V8BindingPerContextData to V8PerContextData
https://bugs.webkit.org/show_bug.cgi?id=93595

Reviewed by Adam Barth.

For a better name. See discussion in bug 93333.

No tests. No change in behavior.

* UseV8.cmake: Added V8PerContextData.cpp. The fact that missing V8BindingPerContextData.cpp
has not caused any problem indicates that UseV8.cmake is not used at all?
* WebCore.gypi:
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::initContextIfNeeded):
* bindings/v8/V8DOMWindowShell.h:
(WebCore::V8DOMWindowShell::perContextData):
(V8DOMWindowShell):
* bindings/v8/V8DOMWrapper.cpp:
(WebCore::V8DOMWrapper::constructorForType):
(WebCore::V8DOMWrapper::perContextData):
(WebCore::V8DOMWrapper::instantiateV8Object):
* bindings/v8/V8DOMWrapper.h:
(WebCore):
(V8DOMWrapper):
* bindings/v8/V8IsolatedContext.cpp:
(WebCore::V8IsolatedContext::V8IsolatedContext):
* bindings/v8/V8IsolatedContext.h:
(WebCore):
(WebCore::V8IsolatedContext::perContextData):
(V8IsolatedContext):
* bindings/v8/V8PerContextData.cpp: Renamed from Source/WebCore/bindings/v8/V8BindingPerContextData.cpp.
(WebCore):
(WebCore::V8PerContextData::dispose):
(WebCore::V8PerContextData::init):
(WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
(WebCore::V8PerContextData::constructorForTypeSlowCase):
* bindings/v8/V8PerContextData.h: Renamed from Source/WebCore/bindings/v8/V8BindingPerContextData.h.
(WebCore):
(V8PerContextData):
(WebCore::V8PerContextData::create):
(WebCore::V8PerContextData::~V8PerContextData):
(WebCore::V8PerContextData::createWrapperFromCache):
(WebCore::V8PerContextData::constructorForType):
(WebCore::V8PerContextData::V8PerContextData):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::retrievePerContextData):
* bindings/v8/V8Proxy.h:
(WebCore):
(V8Proxy):
* bindings/v8/WorkerContextExecutionProxy.cpp:
(WebCore::WorkerContextExecutionProxy::initContextIfNeeded):
* bindings/v8/WorkerContextExecutionProxy.h:
(WebCore):
(WebCore::WorkerContextExecutionProxy::perContextData):
(WorkerContextExecutionProxy):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125241 => 125242)


--- trunk/Source/WebCore/ChangeLog	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/ChangeLog	2012-08-10 03:05:10 UTC (rev 125242)
@@ -1,3 +1,61 @@
+2012-08-09  Kentaro Hara  <[email protected]>
+
+        [V8] Rename V8BindingPerContextData to V8PerContextData
+        https://bugs.webkit.org/show_bug.cgi?id=93595
+
+        Reviewed by Adam Barth.
+
+        For a better name. See discussion in bug 93333.
+
+        No tests. No change in behavior.
+
+        * UseV8.cmake: Added V8PerContextData.cpp. The fact that missing V8BindingPerContextData.cpp
+        has not caused any problem indicates that UseV8.cmake is not used at all?
+        * WebCore.gypi:
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::initContextIfNeeded):
+        * bindings/v8/V8DOMWindowShell.h:
+        (WebCore::V8DOMWindowShell::perContextData):
+        (V8DOMWindowShell):
+        * bindings/v8/V8DOMWrapper.cpp:
+        (WebCore::V8DOMWrapper::constructorForType):
+        (WebCore::V8DOMWrapper::perContextData):
+        (WebCore::V8DOMWrapper::instantiateV8Object):
+        * bindings/v8/V8DOMWrapper.h:
+        (WebCore):
+        (V8DOMWrapper):
+        * bindings/v8/V8IsolatedContext.cpp:
+        (WebCore::V8IsolatedContext::V8IsolatedContext):
+        * bindings/v8/V8IsolatedContext.h:
+        (WebCore):
+        (WebCore::V8IsolatedContext::perContextData):
+        (V8IsolatedContext):
+        * bindings/v8/V8PerContextData.cpp: Renamed from Source/WebCore/bindings/v8/V8BindingPerContextData.cpp.
+        (WebCore):
+        (WebCore::V8PerContextData::dispose):
+        (WebCore::V8PerContextData::init):
+        (WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
+        (WebCore::V8PerContextData::constructorForTypeSlowCase):
+        * bindings/v8/V8PerContextData.h: Renamed from Source/WebCore/bindings/v8/V8BindingPerContextData.h.
+        (WebCore):
+        (V8PerContextData):
+        (WebCore::V8PerContextData::create):
+        (WebCore::V8PerContextData::~V8PerContextData):
+        (WebCore::V8PerContextData::createWrapperFromCache):
+        (WebCore::V8PerContextData::constructorForType):
+        (WebCore::V8PerContextData::V8PerContextData):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::retrievePerContextData):
+        * bindings/v8/V8Proxy.h:
+        (WebCore):
+        (V8Proxy):
+        * bindings/v8/WorkerContextExecutionProxy.cpp:
+        (WebCore::WorkerContextExecutionProxy::initContextIfNeeded):
+        * bindings/v8/WorkerContextExecutionProxy.h:
+        (WebCore):
+        (WebCore::WorkerContextExecutionProxy::perContextData):
+        (WorkerContextExecutionProxy):
+
 2012-08-09  Erik Arvidsson  <[email protected]>
 
         HTMLElement.classList cannot remove classnames with uppercase characters

Modified: trunk/Source/WebCore/UseV8.cmake (125241 => 125242)


--- trunk/Source/WebCore/UseV8.cmake	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/UseV8.cmake	2012-08-10 03:05:10 UTC (rev 125242)
@@ -61,6 +61,7 @@
     bindings/v8/V8IsolatedContext.cpp
     bindings/v8/V8LazyEventListener.cpp
     bindings/v8/V8NodeFilterCondition.cpp
+    bindings/v8/V8PerContextData.cpp
     bindings/v8/V8Proxy.cpp
     bindings/v8/V8RecursionScope.cpp
     bindings/v8/V8Utilities.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (125241 => 125242)


--- trunk/Source/WebCore/WebCore.gypi	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/WebCore.gypi	2012-08-10 03:05:10 UTC (rev 125242)
@@ -2245,10 +2245,6 @@
             'bindings/v8/V8BindingHelpers.cpp',
             'bindings/v8/V8BindingHelpers.h',
             'bindings/v8/V8BindingMacros.h',
-            'bindings/v8/V8BindingPerContextData.cpp',
-            'bindings/v8/V8BindingPerContextData.h',
-            'bindings/v8/V8PerIsolateData.cpp',
-            'bindings/v8/V8PerIsolateData.h',
             'bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp',
             'bindings/v8/V8ConfigureDOMAttributesAndMethods.h',
             'bindings/v8/V8Collection.cpp',
@@ -2279,6 +2275,10 @@
             'bindings/v8/V8NPUtils.h',
             'bindings/v8/V8NodeFilterCondition.cpp',
             'bindings/v8/V8NodeFilterCondition.h',
+            'bindings/v8/V8PerContextData.cpp',
+            'bindings/v8/V8PerContextData.h',
+            'bindings/v8/V8PerIsolateData.cpp',
+            'bindings/v8/V8PerIsolateData.h',
             'bindings/v8/V8Proxy.cpp',
             'bindings/v8/V8Proxy.h',
             'bindings/v8/V8RecursionScope.cpp',

Deleted: trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2012 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 "V8BindingPerContextData.h"
-
-#include "SafeAllocation.h"
-
-namespace WebCore {
-
-void V8BindingPerContextData::dispose()
-{
-    {
-        WrapperBoilerplateMap::iterator it = m_wrapperBoilerplates.begin();
-        for (; it != m_wrapperBoilerplates.end(); ++it) {
-            v8::Persistent<v8::Object> wrapper = it->second;
-            wrapper.Dispose();
-        }
-        m_wrapperBoilerplates.clear();
-    }
-
-    {
-        ConstructorMap::iterator it = m_constructorMap.begin();
-        for (; it != m_constructorMap.end(); ++it) {
-            v8::Persistent<v8::Function> wrapper = it->second;
-            wrapper.Dispose();
-        }
-        m_constructorMap.clear();
-    }
-}
-
-#define V8_STORE_PRIMORDIAL(name, Name) \
-{ \
-    ASSERT(m_##name##Prototype.get().IsEmpty()); \
-    v8::Handle<v8::String> symbol = v8::String::NewSymbol(#Name); \
-    if (symbol.IsEmpty()) \
-        return false; \
-    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(m_context->Global()->Get(symbol)); \
-    if (object.IsEmpty()) \
-        return false; \
-    v8::Handle<v8::Value> prototypeValue = object->Get(prototypeString); \
-    if (prototypeValue.IsEmpty()) \
-        return false; \
-    m_##name##Prototype.set(prototypeValue); \
-}
-
-bool V8BindingPerContextData::init()
-{
-    v8::Handle<v8::String> prototypeString = v8::String::NewSymbol("prototype");
-    if (prototypeString.IsEmpty())
-        return false;
-
-    V8_STORE_PRIMORDIAL(error, Error);
-    V8_STORE_PRIMORDIAL(object, Object);
-
-    return true;
-}
-
-#undef V8_STORE_PRIMORDIAL
-
-v8::Local<v8::Object> V8BindingPerContextData::createWrapperFromCacheSlowCase(WrapperTypeInfo* type)
-{
-    ASSERT(!m_errorPrototype.get().IsEmpty());
-    ASSERT(!m_objectPrototype.get().IsEmpty());
-
-    v8::Context::Scope scope(m_context);
-    v8::Local<v8::Function> function = constructorForType(type);
-    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
-    if (!instance.IsEmpty()) {
-        m_wrapperBoilerplates.set(type, v8::Persistent<v8::Object>::New(instance));
-        return instance->Clone();
-    }
-    return v8::Local<v8::Object>();
-}
-
-v8::Local<v8::Function> V8BindingPerContextData::constructorForTypeSlowCase(WrapperTypeInfo* type)
-{
-    ASSERT(!m_errorPrototype.get().IsEmpty());
-    ASSERT(!m_objectPrototype.get().IsEmpty());
-
-    v8::Context::Scope scope(m_context);
-    v8::Handle<v8::FunctionTemplate> functionTemplate = type->getTemplate();
-    // Getting the function might fail if we're running out of stack or memory.
-    v8::TryCatch tryCatch;
-    v8::Local<v8::Function> function = functionTemplate->GetFunction();
-    if (function.IsEmpty())
-        return v8::Local<v8::Function>();
-
-    function->SetPrototype(m_objectPrototype.get());
-
-    if (type->wrapperTypePrototype == WrapperTypeErrorPrototype) {
-        v8::Local<v8::Value> prototypeValue = function->Get(v8::String::NewSymbol("prototype"));
-        if (!prototypeValue.IsEmpty() && prototypeValue->IsObject())
-            v8::Local<v8::Object>::Cast(prototypeValue)->SetPrototype(m_errorPrototype.get());
-    }
-
-    m_constructorMap.set(type, v8::Persistent<v8::Function>::New(function));
-
-    return function;
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2012 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 V8BindingPerContextData_h
-#define V8BindingPerContextData_h
-
-#include "OwnHandle.h"
-#include "WrapperTypeInfo.h"
-#include <v8.h>
-#include <wtf/HashMap.h>
-#include <wtf/PassOwnPtr.h>
-
-namespace WebCore {
-
-class V8BindingPerContextData {
-public:
-    static PassOwnPtr<V8BindingPerContextData> create(v8::Handle<v8::Context> context)
-    {
-        return adoptPtr(new V8BindingPerContextData(context));
-    }
-
-    ~V8BindingPerContextData()
-    {
-        dispose();
-    }
-
-    bool init();
-
-    // To create JS Wrapper objects, we create a cache of a 'boiler plate'
-    // object, and then simply Clone that object each time we need a new one.
-    // This is faster than going through the full object creation process.
-    v8::Local<v8::Object> createWrapperFromCache(WrapperTypeInfo* type)
-    {
-        v8::Persistent<v8::Object> boilerplate = m_wrapperBoilerplates.get(type);
-        return !boilerplate.IsEmpty() ? boilerplate->Clone() : createWrapperFromCacheSlowCase(type);
-    }
-
-    v8::Local<v8::Function> constructorForType(WrapperTypeInfo* type)
-    {
-        v8::Persistent<v8::Function> function = m_constructorMap.get(type);
-        if (!function.IsEmpty())
-            return v8::Local<v8::Function>::New(function);
-        return constructorForTypeSlowCase(type);
-    }
-
-private:
-    explicit V8BindingPerContextData(v8::Handle<v8::Context> context)
-        : m_context(context)
-    {
-    }
-
-    void dispose();
-
-    v8::Local<v8::Object> createWrapperFromCacheSlowCase(WrapperTypeInfo*);
-    v8::Local<v8::Function> constructorForTypeSlowCase(WrapperTypeInfo*);
-
-    // For each possible type of wrapper, we keep a boilerplate object.
-    // The boilerplate is used to create additional wrappers of the same type.
-    typedef WTF::HashMap<WrapperTypeInfo*, v8::Persistent<v8::Object> > WrapperBoilerplateMap;
-    WrapperBoilerplateMap m_wrapperBoilerplates;
-
-    typedef WTF::HashMap<WrapperTypeInfo*, v8::Persistent<v8::Function> > ConstructorMap;
-    ConstructorMap m_constructorMap;
-
-    v8::Handle<v8::Context> m_context;
-    OwnHandle<v8::Value> m_errorPrototype;
-    OwnHandle<v8::Value> m_objectPrototype;
-};
-
-} // namespace WebCore
-
-#endif // V8BindingPerContextData_h

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -50,7 +50,6 @@
 #include "StorageNamespace.h"
 #include "StylePropertySet.h"
 #include "V8Binding.h"
-#include "V8BindingPerContextData.h"
 #include "V8Collection.h"
 #include "V8DOMMap.h"
 #include "V8DOMWindow.h"
@@ -60,6 +59,7 @@
 #include "V8HiddenPropertyName.h"
 #include "V8History.h"
 #include "V8Location.h"
+#include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "WorkerContextExecutionProxy.h"
 
@@ -324,7 +324,7 @@
 #endif
     }
 
-    m_perContextData = V8BindingPerContextData::create(m_context);
+    m_perContextData = V8PerContextData::create(m_context);
     if (!m_perContextData->init()) {
         disposeContextHandles();
         return false;

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -31,7 +31,7 @@
 #ifndef V8DOMWindowShell_h
 #define V8DOMWindowShell_h
 
-#include "V8BindingPerContextData.h"
+#include "V8PerContextData.h"
 #include "WrapperTypeInfo.h"
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
@@ -78,7 +78,7 @@
 
     void destroyGlobal();
 
-    V8BindingPerContextData* perContextData() { return m_perContextData.get(); }
+    V8PerContextData* perContextData() { return m_perContextData.get(); }
 
 private:
     V8DOMWindowShell(Frame*);
@@ -97,7 +97,7 @@
 
     Frame* m_frame;
 
-    OwnPtr<V8BindingPerContextData> m_perContextData;
+    OwnPtr<V8PerContextData> m_perContextData;
 
     v8::Persistent<v8::Context> m_context;
     v8::Persistent<v8::Object> m_global;

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -41,7 +41,6 @@
 #include "StylePropertySet.h"
 #include "V8AbstractEventListener.h"
 #include "V8Binding.h"
-#include "V8BindingPerContextData.h"
 #include "V8Collection.h"
 #include "V8EventListener.h"
 #include "V8EventListenerList.h"
@@ -52,6 +51,7 @@
 #include "V8NamedNodeMap.h"
 #include "V8NodeFilterCondition.h"
 #include "V8NodeList.h"
+#include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "V8StyleSheet.h"
 #include "V8WorkerContextEventListener.h"
@@ -95,7 +95,7 @@
     if (!frame)
         return v8::Local<v8::Function>();
 
-    if (V8BindingPerContextData* contextData = V8Proxy::retrievePerContextData(frame))
+    if (V8PerContextData* contextData = V8Proxy::retrievePerContextData(frame))
         return contextData->constructorForType(type);
 
     return v8::Local<v8::Function>();
@@ -110,14 +110,14 @@
 }
 #endif
 
-V8BindingPerContextData* V8DOMWrapper::perContextData(V8Proxy* proxy)
+V8PerContextData* V8DOMWrapper::perContextData(V8Proxy* proxy)
 {
     V8DOMWindowShell* shell = proxy->windowShell();
     return shell ? shell->perContextData() : 0;
 }
 
 #if ENABLE(WORKERS)
-V8BindingPerContextData* V8DOMWrapper::perContextData(WorkerContext*)
+V8PerContextData* V8DOMWrapper::perContextData(WorkerContext*)
 {
     WorkerScriptController* controller = WorkerScriptController::controllerForContext();
     WorkerContextExecutionProxy* proxy = controller ? controller->proxy() : 0;
@@ -171,7 +171,7 @@
 #if ENABLE(WORKERS)
     WorkerContext* workerContext = 0;
 #endif
-    V8BindingPerContextData* contextData = 0;
+    V8PerContextData* contextData = 0;
     V8IsolatedContext* isolatedContext;
     if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered()))) {
         contextData = isolatedContext->perContextData();

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -52,7 +52,7 @@
     class EventTarget;
     class Frame;
     class Node;
-    class V8BindingPerContextData;
+    class V8PerContextData;
     class V8Proxy;
     class WorkerContext;
     class XPathResolver;
@@ -148,9 +148,9 @@
             return domNodeMap.get(node);
         }
     private:
-        static V8BindingPerContextData* perContextData(V8Proxy*);
+        static V8PerContextData* perContextData(V8Proxy*);
 #if ENABLE(WORKERS)
-        static V8BindingPerContextData* perContextData(WorkerContext*);
+        static V8PerContextData* perContextData(WorkerContext*);
 #endif
     };
 

Modified: trunk/Source/WebCore/bindings/v8/V8IsolatedContext.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8IsolatedContext.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8IsolatedContext.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -36,8 +36,8 @@
 #include "FrameLoaderClient.h"
 #include "InspectorInstrumentation.h"
 #include "SecurityOrigin.h"
-#include "V8BindingPerContextData.h"
 #include "V8DOMWindow.h"
+#include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include <wtf/StringExtras.h>
 
@@ -87,7 +87,7 @@
 
     getGlobalObject(m_context->get())->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, this);
 
-    m_perContextData = V8BindingPerContextData::create(m_context->get());
+    m_perContextData = V8PerContextData::create(m_context->get());
     m_perContextData->init();
 
     // FIXME: This will go away once we have a windowShell for the isolated world.

Modified: trunk/Source/WebCore/bindings/v8/V8IsolatedContext.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8IsolatedContext.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8IsolatedContext.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -40,7 +40,7 @@
 namespace WebCore {
 
 class SecurityOrigin;
-class V8BindingPerContextData;
+class V8PerContextData;
 class V8Proxy;
 
 // V8IsolatedContext
@@ -97,7 +97,7 @@
     SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
     void setSecurityOrigin(PassRefPtr<SecurityOrigin>);
 
-    V8BindingPerContextData* perContextData() { return m_perContextData.get(); }
+    V8PerContextData* perContextData() { return m_perContextData.get(); }
 
 private:
     static v8::Handle<v8::Object> getGlobalObject(v8::Handle<v8::Context> context)
@@ -121,7 +121,7 @@
 
     Frame* m_frame;
 
-    OwnPtr<V8BindingPerContextData> m_perContextData;
+    OwnPtr<V8PerContextData> m_perContextData;
 };
 
 } // namespace WebCore

Copied: trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp (from rev 125241, trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.cpp) (0 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2012 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 "V8PerContextData.h"
+
+#include "SafeAllocation.h"
+
+namespace WebCore {
+
+void V8PerContextData::dispose()
+{
+    {
+        WrapperBoilerplateMap::iterator it = m_wrapperBoilerplates.begin();
+        for (; it != m_wrapperBoilerplates.end(); ++it) {
+            v8::Persistent<v8::Object> wrapper = it->second;
+            wrapper.Dispose();
+        }
+        m_wrapperBoilerplates.clear();
+    }
+
+    {
+        ConstructorMap::iterator it = m_constructorMap.begin();
+        for (; it != m_constructorMap.end(); ++it) {
+            v8::Persistent<v8::Function> wrapper = it->second;
+            wrapper.Dispose();
+        }
+        m_constructorMap.clear();
+    }
+}
+
+#define V8_STORE_PRIMORDIAL(name, Name) \
+{ \
+    ASSERT(m_##name##Prototype.get().IsEmpty()); \
+    v8::Handle<v8::String> symbol = v8::String::NewSymbol(#Name); \
+    if (symbol.IsEmpty()) \
+        return false; \
+    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(m_context->Global()->Get(symbol)); \
+    if (object.IsEmpty()) \
+        return false; \
+    v8::Handle<v8::Value> prototypeValue = object->Get(prototypeString); \
+    if (prototypeValue.IsEmpty()) \
+        return false; \
+    m_##name##Prototype.set(prototypeValue); \
+}
+
+bool V8PerContextData::init()
+{
+    v8::Handle<v8::String> prototypeString = v8::String::NewSymbol("prototype");
+    if (prototypeString.IsEmpty())
+        return false;
+
+    V8_STORE_PRIMORDIAL(error, Error);
+    V8_STORE_PRIMORDIAL(object, Object);
+
+    return true;
+}
+
+#undef V8_STORE_PRIMORDIAL
+
+v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(WrapperTypeInfo* type)
+{
+    ASSERT(!m_errorPrototype.get().IsEmpty());
+    ASSERT(!m_objectPrototype.get().IsEmpty());
+
+    v8::Context::Scope scope(m_context);
+    v8::Local<v8::Function> function = constructorForType(type);
+    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+    if (!instance.IsEmpty()) {
+        m_wrapperBoilerplates.set(type, v8::Persistent<v8::Object>::New(instance));
+        return instance->Clone();
+    }
+    return v8::Local<v8::Object>();
+}
+
+v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(WrapperTypeInfo* type)
+{
+    ASSERT(!m_errorPrototype.get().IsEmpty());
+    ASSERT(!m_objectPrototype.get().IsEmpty());
+
+    v8::Context::Scope scope(m_context);
+    v8::Handle<v8::FunctionTemplate> functionTemplate = type->getTemplate();
+    // Getting the function might fail if we're running out of stack or memory.
+    v8::TryCatch tryCatch;
+    v8::Local<v8::Function> function = functionTemplate->GetFunction();
+    if (function.IsEmpty())
+        return v8::Local<v8::Function>();
+
+    function->SetPrototype(m_objectPrototype.get());
+
+    if (type->wrapperTypePrototype == WrapperTypeErrorPrototype) {
+        v8::Local<v8::Value> prototypeValue = function->Get(v8::String::NewSymbol("prototype"));
+        if (!prototypeValue.IsEmpty() && prototypeValue->IsObject())
+            v8::Local<v8::Object>::Cast(prototypeValue)->SetPrototype(m_errorPrototype.get());
+    }
+
+    m_constructorMap.set(type, v8::Persistent<v8::Function>::New(function));
+
+    return function;
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/bindings/v8/V8PerContextData.h (from rev 125241, trunk/Source/WebCore/bindings/v8/V8BindingPerContextData.h) (0 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 V8PerContextData_h
+#define V8PerContextData_h
+
+#include "OwnHandle.h"
+#include "WrapperTypeInfo.h"
+#include <v8.h>
+#include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class V8PerContextData {
+public:
+    static PassOwnPtr<V8PerContextData> create(v8::Handle<v8::Context> context)
+    {
+        return adoptPtr(new V8PerContextData(context));
+    }
+
+    ~V8PerContextData()
+    {
+        dispose();
+    }
+
+    bool init();
+
+    // To create JS Wrapper objects, we create a cache of a 'boiler plate'
+    // object, and then simply Clone that object each time we need a new one.
+    // This is faster than going through the full object creation process.
+    v8::Local<v8::Object> createWrapperFromCache(WrapperTypeInfo* type)
+    {
+        v8::Persistent<v8::Object> boilerplate = m_wrapperBoilerplates.get(type);
+        return !boilerplate.IsEmpty() ? boilerplate->Clone() : createWrapperFromCacheSlowCase(type);
+    }
+
+    v8::Local<v8::Function> constructorForType(WrapperTypeInfo* type)
+    {
+        v8::Persistent<v8::Function> function = m_constructorMap.get(type);
+        if (!function.IsEmpty())
+            return v8::Local<v8::Function>::New(function);
+        return constructorForTypeSlowCase(type);
+    }
+
+private:
+    explicit V8PerContextData(v8::Handle<v8::Context> context)
+        : m_context(context)
+    {
+    }
+
+    void dispose();
+
+    v8::Local<v8::Object> createWrapperFromCacheSlowCase(WrapperTypeInfo*);
+    v8::Local<v8::Function> constructorForTypeSlowCase(WrapperTypeInfo*);
+
+    // For each possible type of wrapper, we keep a boilerplate object.
+    // The boilerplate is used to create additional wrappers of the same type.
+    typedef WTF::HashMap<WrapperTypeInfo*, v8::Persistent<v8::Object> > WrapperBoilerplateMap;
+    WrapperBoilerplateMap m_wrapperBoilerplates;
+
+    typedef WTF::HashMap<WrapperTypeInfo*, v8::Persistent<v8::Function> > ConstructorMap;
+    ConstructorMap m_constructorMap;
+
+    v8::Handle<v8::Context> m_context;
+    OwnHandle<v8::Value> m_errorPrototype;
+    OwnHandle<v8::Value> m_objectPrototype;
+};
+
+} // namespace WebCore
+
+#endif // V8PerContextData_h

Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -428,7 +428,7 @@
     return 0;
 }
 
-V8BindingPerContextData* V8Proxy::retrievePerContextData(Frame* frame)
+V8PerContextData* V8Proxy::retrievePerContextData(Frame* frame)
 {
     V8IsolatedContext* isolatedContext;
     if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered())))

Modified: trunk/Source/WebCore/bindings/v8/V8Proxy.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/V8Proxy.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/V8Proxy.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -62,7 +62,7 @@
     class ScriptExecutionContext;
     class ScriptSourceCode;
     class SecurityOrigin;
-    class V8BindingPerContextData;
+    class V8PerContextData;
     class V8EventListener;
     class V8IsolatedContext;
     class WorldContextHandle;
@@ -134,7 +134,7 @@
         // a context.
         static Frame* retrieveFrame(v8::Handle<v8::Context>);
 
-        static V8BindingPerContextData* retrievePerContextData(Frame*);
+        static V8PerContextData* retrievePerContextData(Frame*);
 
         // Returns V8 Context of a frame. If none exists, creates
         // a new context. It is potentially slow and consumes memory.

Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp	2012-08-10 03:05:10 UTC (rev 125242)
@@ -42,10 +42,10 @@
 #include "SharedWorker.h"
 #include "SharedWorkerContext.h"
 #include "V8Binding.h"
-#include "V8BindingPerContextData.h"
 #include "V8DOMMap.h"
 #include "V8DOMWindowShell.h"
 #include "V8DedicatedWorkerContext.h"
+#include "V8PerContextData.h"
 #include "V8Proxy.h"
 #include "V8RecursionScope.h"
 #include "V8SharedWorkerContext.h"
@@ -153,7 +153,7 @@
 
     v8::Context::Scope scope(context);
 
-    m_perContextData = V8BindingPerContextData::create(m_context);
+    m_perContextData = V8PerContextData::create(m_context);
     if (!m_perContextData->init()) {
         dispose();
         return false;

Modified: trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h (125241 => 125242)


--- trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h	2012-08-10 02:47:07 UTC (rev 125241)
+++ trunk/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.h	2012-08-10 03:05:10 UTC (rev 125242)
@@ -44,7 +44,7 @@
 
     class Event;
     class EventTarget;
-    class V8BindingPerContextData;
+    class V8PerContextData;
     class WorkerContext;
     struct WrapperTypeInfo;
 
@@ -74,7 +74,7 @@
         // Returns a local handle of the context.
         v8::Local<v8::Context> context() { return v8::Local<v8::Context>::New(m_context); }
 
-        V8BindingPerContextData* perContextData() { return m_perContextData.get(); }
+        V8PerContextData* perContextData() { return m_perContextData.get(); }
 
     private:
         void initIsolate();
@@ -93,7 +93,7 @@
 
         Vector<Event*> m_events;
 
-        OwnPtr<V8BindingPerContextData> m_perContextData;
+        OwnPtr<V8PerContextData> m_perContextData;
     };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to