Title: [124940] trunk/Source/WebCore
Revision
124940
Author
[email protected]
Date
2012-08-07 16:38:25 -0700 (Tue, 07 Aug 2012)

Log Message

[V8] Factor out V8Binding methods that configures DOM attributes and methods
https://bugs.webkit.org/show_bug.cgi?id=93239

Reviewed by Adam Barth.

V8Binding is messy. This patch factors out V8Binding methods that configures
DOM attributes and methods into another file. This patch just moves the methods
from V8Binding.{h,cpp} to V8ConfigureDOMAttributesAndMethods.{h,cpp}.

No tests. No change in behavior.

* UseV8.cmake:
* WebCore.gypi:
* bindings/v8/V8Binding.cpp:
* bindings/v8/V8Binding.h:
(WebCore):
* bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp: Added.
(WebCore):
(WebCore::batchConfigureAttributes):
(WebCore::batchConfigureConstants):
(WebCore::batchConfigureCallbacks):
(WebCore::configureTemplate):
* bindings/v8/V8ConfigureDOMAttributesAndMethods.h: Added.
(WebCore):
(BatchedAttribute):
(WebCore::configureAttribute):
(BatchedConstant):
(BatchedCallback):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (124939 => 124940)


--- trunk/Source/WebCore/ChangeLog	2012-08-07 23:37:43 UTC (rev 124939)
+++ trunk/Source/WebCore/ChangeLog	2012-08-07 23:38:25 UTC (rev 124940)
@@ -1,5 +1,36 @@
 2012-08-07  Kentaro Hara  <[email protected]>
 
+        [V8] Factor out V8Binding methods that configures DOM attributes and methods
+        https://bugs.webkit.org/show_bug.cgi?id=93239
+
+        Reviewed by Adam Barth.
+
+        V8Binding is messy. This patch factors out V8Binding methods that configures
+        DOM attributes and methods into another file. This patch just moves the methods
+        from V8Binding.{h,cpp} to V8ConfigureDOMAttributesAndMethods.{h,cpp}.
+
+        No tests. No change in behavior.
+
+        * UseV8.cmake:
+        * WebCore.gypi:
+        * bindings/v8/V8Binding.cpp:
+        * bindings/v8/V8Binding.h:
+        (WebCore):
+        * bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp: Added.
+        (WebCore):
+        (WebCore::batchConfigureAttributes):
+        (WebCore::batchConfigureConstants):
+        (WebCore::batchConfigureCallbacks):
+        (WebCore::configureTemplate):
+        * bindings/v8/V8ConfigureDOMAttributesAndMethods.h: Added.
+        (WebCore):
+        (BatchedAttribute):
+        (WebCore::configureAttribute):
+        (BatchedConstant):
+        (BatchedCallback):
+
+2012-08-07  Kentaro Hara  <[email protected]>
+
         [V8] Replace all V8 undefined values in the rest of custom bindings with v8Undefined()
         https://bugs.webkit.org/show_bug.cgi?id=93220
 

Modified: trunk/Source/WebCore/UseV8.cmake (124939 => 124940)


--- trunk/Source/WebCore/UseV8.cmake	2012-08-07 23:37:43 UTC (rev 124939)
+++ trunk/Source/WebCore/UseV8.cmake	2012-08-07 23:38:25 UTC (rev 124940)
@@ -46,6 +46,7 @@
     bindings/v8/StaticDOMDataStore.cpp
     bindings/v8/V8AbstractEventListener.cpp
     bindings/v8/V8Binding.cpp
+    bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp,
     bindings/v8/V8Collection.cpp
     bindings/v8/V8DOMMap.cpp
     bindings/v8/V8DOMWindowShell.cpp

Modified: trunk/Source/WebCore/WebCore.gypi (124939 => 124940)


--- trunk/Source/WebCore/WebCore.gypi	2012-08-07 23:37:43 UTC (rev 124939)
+++ trunk/Source/WebCore/WebCore.gypi	2012-08-07 23:38:25 UTC (rev 124940)
@@ -2246,6 +2246,8 @@
             'bindings/v8/V8Binding.h',
             'bindings/v8/V8BindingPerContextData.cpp',
             'bindings/v8/V8BindingPerContextData.h',
+            'bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp',
+            'bindings/v8/V8ConfigureDOMAttributesAndMethods.h',
             'bindings/v8/V8Collection.cpp',
             'bindings/v8/V8Collection.h',
             'bindings/v8/V8DOMMap.cpp',

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (124939 => 124940)


--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-07 23:37:43 UTC (rev 124939)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp	2012-08-07 23:38:25 UTC (rev 124940)
@@ -367,32 +367,6 @@
     return v8::Persistent<v8::FunctionTemplate>::New(result);
 }        
 
-v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate> desc,
-                                           const char *interfaceName,
-                                           v8::Persistent<v8::FunctionTemplate> parentClass,
-                                           int fieldCount,
-                                           const BatchedAttribute* attributes, 
-                                           size_t attributeCount,
-                                           const BatchedCallback* callbacks,
-                                           size_t callbackCount)
-{
-    desc->SetClassName(v8::String::New(interfaceName));
-    v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
-    instance->SetInternalFieldCount(fieldCount);
-    if (!parentClass.IsEmpty())
-        desc->Inherit(parentClass);
-    if (attributeCount)
-        batchConfigureAttributes(instance, desc->PrototypeTemplate(),
-                                 attributes, attributeCount);
-    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(desc);
-    if (callbackCount)
-        batchConfigureCallbacks(desc->PrototypeTemplate(),
-                                defaultSignature,
-                                static_cast<v8::PropertyAttribute>(v8::DontDelete),
-                                callbacks, callbackCount);
-    return defaultSignature;
-}
-
 v8::Persistent<v8::String> getToStringName()
 {
     v8::Persistent<v8::String>& toStringName = V8BindingPerIsolateData::current()->toStringName();
@@ -453,40 +427,4 @@
     return ret.release();
 }
 
-void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, 
-                              v8::Handle<v8::ObjectTemplate> proto, 
-                              const BatchedAttribute* attributes, 
-                              size_t attributeCount)
-{
-    for (size_t i = 0; i < attributeCount; ++i)
-        configureAttribute(instance, proto, attributes[i]);
-}
-
-void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate> proto, 
-                             v8::Handle<v8::Signature> signature, 
-                             v8::PropertyAttribute attributes,
-                             const BatchedCallback* callbacks,
-                             size_t callbackCount)
-{
-    for (size_t i = 0; i < callbackCount; ++i) {
-        proto->Set(v8::String::New(callbacks[i].name),
-                   v8::FunctionTemplate::New(callbacks[i].callback, 
-                                             v8::Handle<v8::Value>(),
-                                             signature),
-                   attributes);
-    }
-}
-
-void batchConfigureConstants(v8::Handle<v8::FunctionTemplate> functionDescriptor,
-                             v8::Handle<v8::ObjectTemplate> proto,
-                             const BatchedConstant* constants,
-                             size_t constantCount)
-{
-    for (size_t i = 0; i < constantCount; ++i) {
-        const BatchedConstant* constant = &constants[i];
-        functionDescriptor->Set(v8::String::New(constant->name), v8Integer(constant->value), v8::ReadOnly);
-        proto->Set(v8::String::New(constant->name), v8Integer(constant->value), v8::ReadOnly);
-    }
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (124939 => 124940)


--- trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-07 23:37:43 UTC (rev 124939)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-08-07 23:38:25 UTC (rev 124940)
@@ -36,6 +36,7 @@
 #include "Document.h"
 #include "PlatformString.h"
 #include "V8BindingMacros.h"
+#include "V8ConfigureDOMAttributesAndMethods.h"
 #include "V8DOMWrapper.h"
 #include "V8GCController.h"
 #include "V8HiddenPropertyName.h"
@@ -534,18 +535,6 @@
 
     v8::Persistent<v8::FunctionTemplate> createRawTemplate();
 
-    struct BatchedAttribute;
-    struct BatchedCallback;
-
-    v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>,
-                                               const char* interfaceName,
-                                               v8::Persistent<v8::FunctionTemplate> parentClass,
-                                               int fieldCount,
-                                               const BatchedAttribute*,
-                                               size_t attributeCount,
-                                               const BatchedCallback*,
-                                               size_t callbackCount);
-
     v8::Persistent<v8::String> getToStringName();
     v8::Persistent<v8::FunctionTemplate> getToStringTemplate();
 
@@ -654,57 +643,6 @@
         DefaultIsNullString
     };
 
-    // The following Batch structs and methods are used for setting multiple
-    // properties on an ObjectTemplate, used from the generated bindings
-    // initialization (ConfigureXXXTemplate). This greatly reduces the binary
-    // size by moving from code driven setup to data table driven setup.
-
-    // BatchedAttribute translates into calls to SetAccessor() on either the
-    // instance or the prototype ObjectTemplate, based on |onProto|.
-    struct BatchedAttribute {
-        const char* const name;
-        v8::AccessorGetter getter;
-        v8::AccessorSetter setter;
-        WrapperTypeInfo* data;
-        v8::AccessControl settings;
-        v8::PropertyAttribute attribute;
-        bool onProto;
-    };
-
-    void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::ObjectTemplate>, const BatchedAttribute*, size_t attributeCount);
-
-    template<class ObjectOrTemplate>
-    inline void configureAttribute(v8::Handle<ObjectOrTemplate> instance, v8::Handle<ObjectOrTemplate> proto, const BatchedAttribute& attribute)
-    {
-        (attribute.onProto ? proto : instance)->SetAccessor(v8::String::New(attribute.name),
-            attribute.getter,
-            attribute.setter,
-            v8::External::Wrap(attribute.data),
-            attribute.settings,
-            attribute.attribute);
-    }
-
-    // BatchedConstant translates into calls to Set() for setting up an object's
-    // constants. It sets the constant on both the FunctionTemplate and the
-    // ObjectTemplate. PropertyAttributes is always ReadOnly.
-    struct BatchedConstant {
-        const char* const name;
-        int value;
-    };
-
-    void batchConfigureConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8::ObjectTemplate>, const BatchedConstant*, size_t constantCount);
-
-    struct BatchedCallback {
-        const char* const name;
-        v8::InvocationCallback callback;
-    };
-
-    void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate>, 
-                                 v8::Handle<v8::Signature>,
-                                 v8::PropertyAttribute,
-                                 const BatchedCallback*, 
-                                 size_t callbackCount);
-
 } // namespace WebCore
 
 #endif // V8Binding_h

Added: trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp (0 => 124940)


--- trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.cpp	2012-08-07 23:38:25 UTC (rev 124940)
@@ -0,0 +1,89 @@
+/*
+ * 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:
+ *
+ * 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE 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 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 "V8ConfigureDOMAttributesAndMethods.h"
+
+#include "V8Binding.h"
+
+namespace WebCore {
+
+void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, 
+                              v8::Handle<v8::ObjectTemplate> proto, 
+                              const BatchedAttribute* attributes, 
+                              size_t attributeCount)
+{
+    for (size_t i = 0; i < attributeCount; ++i)
+        configureAttribute(instance, proto, attributes[i]);
+}
+
+void batchConfigureConstants(v8::Handle<v8::FunctionTemplate> functionDescriptor,
+                             v8::Handle<v8::ObjectTemplate> proto,
+                             const BatchedConstant* constants,
+                             size_t constantCount)
+{
+    for (size_t i = 0; i < constantCount; ++i) {
+        const BatchedConstant* constant = &constants[i];
+        functionDescriptor->Set(v8::String::New(constant->name), v8Integer(constant->value), v8::ReadOnly);
+        proto->Set(v8::String::New(constant->name), v8Integer(constant->value), v8::ReadOnly);
+    }
+}
+
+void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate> proto, 
+                             v8::Handle<v8::Signature> signature, 
+                             v8::PropertyAttribute attributes,
+                             const BatchedCallback* callbacks,
+                             size_t callbackCount)
+{
+    for (size_t i = 0; i < callbackCount; ++i)
+        proto->Set(v8::String::New(callbacks[i].name), v8::FunctionTemplate::New(callbacks[i].callback, v8::Handle<v8::Value>(), signature), attributes);
+}
+
+v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate> desc,
+                                           const char *interfaceName,
+                                           v8::Persistent<v8::FunctionTemplate> parentClass,
+                                           int fieldCount,
+                                           const BatchedAttribute* attributes, 
+                                           size_t attributeCount,
+                                           const BatchedCallback* callbacks,
+                                           size_t callbackCount)
+{
+    desc->SetClassName(v8::String::New(interfaceName));
+    v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
+    instance->SetInternalFieldCount(fieldCount);
+    if (!parentClass.IsEmpty())
+        desc->Inherit(parentClass);
+    if (attributeCount)
+        batchConfigureAttributes(instance, desc->PrototypeTemplate(), attributes, attributeCount);
+    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(desc);
+    if (callbackCount)
+        batchConfigureCallbacks(desc->PrototypeTemplate(), defaultSignature, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount);
+    return defaultSignature;
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.h (0 => 124940)


--- trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/V8ConfigureDOMAttributesAndMethods.h	2012-08-07 23:38:25 UTC (rev 124940)
@@ -0,0 +1,108 @@
+/*
+ * 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:
+ *
+ * 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE 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 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 V8ConfigureDOMAttributesAndMethods_h
+#define V8ConfigureDOMAttributesAndMethods_h
+
+#include "V8DOMWrapper.h"
+#include <v8.h>
+
+namespace WebCore {
+
+// The following Batch structs and methods are used for setting multiple
+// properties on an ObjectTemplate, used from the generated bindings
+// initialization (ConfigureXXXTemplate). This greatly reduces the binary
+// size by moving from code driven setup to data table driven setup.
+
+// BatchedAttribute translates into calls to SetAccessor() on either the
+// instance or the prototype ObjectTemplate, based on |onProto|.
+struct BatchedAttribute {
+    const char* const name;
+    v8::AccessorGetter getter;
+    v8::AccessorSetter setter;
+    WrapperTypeInfo* data;
+    v8::AccessControl settings;
+    v8::PropertyAttribute attribute;
+    bool onProto;
+};
+
+void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate>,
+                              v8::Handle<v8::ObjectTemplate>,
+                              const BatchedAttribute*,
+                              size_t attributeCount);
+
+template<class ObjectOrTemplate>
+inline void configureAttribute(v8::Handle<ObjectOrTemplate> instance,
+                               v8::Handle<ObjectOrTemplate> proto,
+                               const BatchedAttribute& attribute)
+{
+    (attribute.onProto ? proto : instance)->SetAccessor(v8::String::New(attribute.name),
+                                                        attribute.getter,
+                                                        attribute.setter,
+                                                        v8::External::Wrap(attribute.data),
+                                                        attribute.settings,
+                                                        attribute.attribute);
+}
+
+// BatchedConstant translates into calls to Set() for setting up an object's
+// constants. It sets the constant on both the FunctionTemplate and the
+// ObjectTemplate. PropertyAttributes is always ReadOnly.
+struct BatchedConstant {
+    const char* const name;
+    int value;
+};
+
+void batchConfigureConstants(v8::Handle<v8::FunctionTemplate>,
+                             v8::Handle<v8::ObjectTemplate>,
+                             const BatchedConstant*,
+                             size_t constantCount);
+
+// BatchedCallback translates into calls to Set() on the prototype ObjectTemplate.
+struct BatchedCallback {
+    const char* const name;
+    v8::InvocationCallback callback;
+};
+
+void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate>, 
+                             v8::Handle<v8::Signature>,
+                             v8::PropertyAttribute,
+                             const BatchedCallback*, 
+                             size_t callbackCount);
+
+v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>,
+                                           const char* interfaceName,
+                                           v8::Persistent<v8::FunctionTemplate> parentClass,
+                                           int fieldCount,
+                                           const BatchedAttribute*,
+                                           size_t attributeCount,
+                                           const BatchedCallback*,
+                                           size_t callbackCount);
+
+} // namespace WebCore
+
+#endif // V8ConfigureDOMAttributesAndMethods_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to