[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

snej at chromium.org snej at chromium.org
Wed Apr 7 23:47:07 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit eb2593c4d4a7703a3398a26ef3a18d7af5157700
Author: snej at chromium.org <snej at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 18 19:57:06 2009 +0000

    Eliminate unnecessary String-->AtomicString conversions from generated V8 bindings,
    by causing the right v8-to-WebCore conversion function to be called for every parameter.
    This no longer requires any IDL metadata, so I've removed the [HintAtomic] annotations.
    To enforce correctness, I added a mode that disables implicit
    String-->AtomicString conversions while compiling the generated bindings.
    https://bugs.webkit.org/show_bug.cgi?id=31168
    
    Reviewed by Darin Adler.
    
    * bindings/scripts/CodeGeneratorV8.pm:  Generate usage of V8Parameter class.
    * bindings/v8/DerivedSourcesAllInOne.cpp:  Enable NO_IMPLICIT_ATOMICSTRING.
    * bindings/v8/V8Binding.h:  Add V8Parameter class.
    * css/WebKitCSSKeyframesRule.h:  Make AtomicString conversions explicit.
    * dom/Document.idl:  Remove obsolete [HintAtomic] annotation.
    * platform/text/AtomicString.h:  Added NO_IMPLICIT_ATOMICSTRING option.
    * svg/SVGAnimatedTemplate.h:  Change some return types to String to avoid implicit conversion.
    * svg/SVGAnimatedProperty.h: Adapt to changed return types in SVGAnimatedTemplate.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51125 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f675e9a..0ed838d 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2009-11-17  Jens Alfke  <snej at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Eliminate unnecessary String-->AtomicString conversions from generated V8 bindings,
+        by causing the right v8-to-WebCore conversion function to be called for every parameter.
+        This no longer requires any IDL metadata, so I've removed the [HintAtomic] annotations.
+        To enforce correctness, I added a mode that disables implicit
+        String-->AtomicString conversions while compiling the generated bindings.
+        https://bugs.webkit.org/show_bug.cgi?id=31168
+
+        * bindings/scripts/CodeGeneratorV8.pm:  Generate usage of V8Parameter class.
+        * bindings/v8/DerivedSourcesAllInOne.cpp:  Enable NO_IMPLICIT_ATOMICSTRING.
+        * bindings/v8/V8Binding.h:  Add V8Parameter class.
+        * css/WebKitCSSKeyframesRule.h:  Make AtomicString conversions explicit.
+        * dom/Document.idl:  Remove obsolete [HintAtomic] annotation.
+        * platform/text/AtomicString.h:  Added NO_IMPLICIT_ATOMICSTRING option.
+        * svg/SVGAnimatedTemplate.h:  Change some return types to String to avoid implicit conversion.
+        * svg/SVGAnimatedProperty.h: Adapt to changed return types in SVGAnimatedTemplate.
+
 2009-11-18  Darin Adler  <darin at apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/WebCore/bindings/scripts/CodeGeneratorV8.pm b/WebCore/bindings/scripts/CodeGeneratorV8.pm
index 1fef83e..8f63e0d 100644
--- a/WebCore/bindings/scripts/CodeGeneratorV8.pm
+++ b/WebCore/bindings/scripts/CodeGeneratorV8.pm
@@ -468,7 +468,7 @@ sub GenerateNormalAttrGetter
     my $attrType = GetTypeFromSignature($attribute->signature);
     my $attrIsPodType = IsPodType($attrType);
 
-    my $nativeType = GetNativeTypeFromSignature($attribute->signature, 0);
+    my $nativeType = GetNativeTypeFromSignature($attribute->signature, -1);
     my $isPodType = IsPodType($implClassName);
     my $skipContext = 0;
 
@@ -947,7 +947,7 @@ END
             push(@implContentDecls, "    bool ${parameterName}Ok;\n");
         }
 
-        push(@implContentDecls, "    " . GetNativeTypeFromSignature($parameter, 1) . " $parameterName = ");
+        push(@implContentDecls, "    " . GetNativeTypeFromSignature($parameter, $paramIndex) . " $parameterName = ");
         push(@implContentDecls, JSValueToNative($parameter, "args[$paramIndex]",
            BasicTypeCanFailConversion($parameter) ?  "${parameterName}Ok" : undef) . ";\n");
 
@@ -1718,19 +1718,14 @@ sub GetTypeFromSignature
 {
     my $signature = shift;
 
-    my $type = $codeGenerator->StripModule($signature->type);
-    if (($type eq "DOMString") && ($signature->extendedAttributes->{"HintAtomic"} || $signature->extendedAttributes->{"Reflect"})) {
-        $type = "AtomicString";
-    }
-
-    return $type;
+    return $codeGenerator->StripModule($signature->type);
 }
 
 
 sub GetNativeTypeFromSignature
 {
     my $signature = shift;
-    my $isParameter = shift;
+    my $parameterIndex = shift;
 
     my $type = GetTypeFromSignature($signature);
 
@@ -1739,7 +1734,19 @@ sub GetNativeTypeFromSignature
         return "int";
     }
 
-    return GetNativeType($type, $isParameter);
+    $type = GetNativeType($type, $parameterIndex >= 0 ? 1 : 0);
+    
+    if ($parameterIndex >= 0 && $type eq "V8Parameter") {
+        my $mode = "";
+        if ($signature->extendedAttributes->{"ConvertUndefinedOrNullToNullString"}) {
+            $mode = "WithUndefinedOrNullCheck";
+        } elsif ($signature->extendedAttributes->{"ConvertNullToNullString"}) {
+            $mode = "WithNullCheck";
+        }
+        $type .= "<$mode>";
+    }
+    
+    return $type;
 }
 
 sub IsRefPtrType
@@ -1857,10 +1864,11 @@ sub GetNativeType
     my $type = shift;
     my $isParameter = shift;
 
-    if ($type eq "float" or $type eq "AtomicString" or $type eq "double") {
+    if ($type eq "float" or $type eq "double") {
         return $type;
     }
 
+    return "V8Parameter" if ($type eq "DOMString" or $type eq "DOMUserData") and $isParameter;
     return "int" if $type eq "int";
     return "int" if $type eq "short" or $type eq "unsigned short";
     return "unsigned" if $type eq "unsigned long";
@@ -1896,7 +1904,6 @@ sub GetNativeType
 
 
 my %typeCanFailConversion = (
-    "AtomicString" => 0,
     "Attr" => 1,
     "WebGLArray" => 0,
     "WebGLBuffer" => 0,
@@ -2011,21 +2018,8 @@ sub JSValueToNative
     return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow";
     return "static_cast<SVGPaint::SVGPaintType>($value->ToInt32()->Int32Value())" if $type eq "SVGPaintType";
 
-    if ($type eq "AtomicString") {
-        return "toAtomicWebCoreStringWithNullCheck($value)" if $signature->extendedAttributes->{"ConvertNullToNullString"};
-        return "v8ValueToAtomicWebCoreString($value)";
-    }
-
-    if ($type eq "DOMUserData") {
-        return "toWebCoreString(args, $1)" if $value =~ /args\[(\d+)]/;
-        return "toWebCoreString($value)";
-    }
-    if ($type eq "DOMString") {
-        return "toWebCoreStringWithNullCheck($value)" if $signature->extendedAttributes->{"ConvertNullToNullString"};
-        return "toWebCoreStringWithNullOrUndefinedCheck($value)" if $signature->extendedAttributes->{"ConvertUndefinedOrNullToNullString"};
-        
-        return "toWebCoreString(args, $1)" if $value =~ /args\[(\d+)]/;
-        return "toWebCoreString($value)";
+    if ($type eq "DOMString" or $type eq "DOMUserData") {
+        return $value;
     }
 
     if ($type eq "SerializedScriptValue") {
@@ -2149,7 +2143,6 @@ sub RequiresCustomSignature
 
 my %non_wrapper_types = (
     'float' => 1,
-    'AtomicString' => 1,
     'double' => 1,
     'short' => 1,
     'unsigned short' => 1,
diff --git a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
index 4e81c94..508cd45 100644
--- a/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
+++ b/WebCore/bindings/v8/DerivedSourcesAllInOne.cpp
@@ -31,6 +31,10 @@
 // This source file coalesces the V8 derived sources into a single object file to
 // reduce bloat and allow us to link release builds on 32-bit Windows.
 
+// Require explicit conversion to AtomicString. This helps catch cases where
+// the generated bindings cause an expensive implicit conversion.
+#define NO_IMPLICIT_ATOMICSTRING
+
 #include "bindings/V8Attr.cpp"
 #include "bindings/V8BarInfo.cpp"
 #include "bindings/V8BeforeLoadEvent.cpp"
diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h
index 7bf5d94..de5bb4c 100644
--- a/WebCore/bindings/v8/V8Binding.h
+++ b/WebCore/bindings/v8/V8Binding.h
@@ -229,6 +229,31 @@ namespace WebCore {
 
     v8::Handle<v8::Value> getElementEventHandlerAttr(const v8::AccessorInfo&,
                                                      const AtomicString&);
+    
+    // V8Parameter is an adapter class that converts V8 values to Strings
+    // or AtomicStrings as appropriate, using multiple typecast operators.
+    enum V8ParameterMode {
+        DefaultMode,
+        WithNullCheck,
+        WithUndefinedOrNullCheck
+    };
+    template <V8ParameterMode MODE = DefaultMode>
+    class V8Parameter {
+    public:
+        V8Parameter (v8::Local<v8::Value> object) :m_v8Object(object) { }
+        operator String();
+        operator AtomicString();
+    private:
+        v8::Local<v8::Value> m_v8Object;
+    };
+    
+    template<> inline V8Parameter<DefaultMode>::operator String() { return toWebCoreString(m_v8Object); }
+    template<> inline V8Parameter<WithNullCheck>::operator String() { return toWebCoreStringWithNullCheck(m_v8Object); }
+    template<> inline V8Parameter<WithUndefinedOrNullCheck>::operator String() { return toWebCoreStringWithNullOrUndefinedCheck(m_v8Object); }
+
+    template<> inline V8Parameter<DefaultMode>::operator AtomicString() { return v8ValueToAtomicWebCoreString(m_v8Object); }
+    template<> inline V8Parameter<WithNullCheck>::operator AtomicString() { return toAtomicWebCoreStringWithNullCheck(m_v8Object); }
+    template<> inline V8Parameter<WithUndefinedOrNullCheck>::operator AtomicString() { return toAtomicWebCoreStringWithNullCheck(m_v8Object); }
 
 } // namespace WebCore
 
diff --git a/WebCore/css/WebKitCSSKeyframesRule.h b/WebCore/css/WebKitCSSKeyframesRule.h
index 8c76b61..f58406f 100644
--- a/WebCore/css/WebKitCSSKeyframesRule.h
+++ b/WebCore/css/WebKitCSSKeyframesRule.h
@@ -64,7 +64,7 @@ public:
     // themselves, or know that it will get called later.
     void setNameInternal(const String& name)
     {   
-        m_name = name;
+        m_name = AtomicString(name);
     }
 
     CSSRuleList* cssRules() { return m_lstCSSRules.get(); }
diff --git a/WebCore/dom/Document.idl b/WebCore/dom/Document.idl
index e9b5480..76a4edb 100644
--- a/WebCore/dom/Document.idl
+++ b/WebCore/dom/Document.idl
@@ -35,7 +35,7 @@ module core {
         readonly attribute [V8Custom] DOMImplementation implementation;
         readonly attribute Element documentElement;
 
-        [ReturnsNew] Element createElement(in [ConvertNullToNullString, HintAtomic] DOMString tagName)
+        [ReturnsNew] Element createElement(in [ConvertNullToNullString] DOMString tagName)
             raises (DOMException);
         DocumentFragment   createDocumentFragment();
         [ReturnsNew] Text createTextNode(in DOMString data);
@@ -64,7 +64,7 @@ module core {
             raises (DOMException);
         [OldStyleObjC] NodeList getElementsByTagNameNS(in [ConvertNullToNullString] DOMString namespaceURI,
                                                        in DOMString localName);
-        Element            getElementById(in [HintAtomic] DOMString elementId);
+        Element            getElementById(in DOMString elementId);
 
         // DOM Level 3 Core
 
diff --git a/WebCore/platform/text/AtomicString.h b/WebCore/platform/text/AtomicString.h
index 4bde1b0..47d07c5 100644
--- a/WebCore/platform/text/AtomicString.h
+++ b/WebCore/platform/text/AtomicString.h
@@ -24,6 +24,14 @@
 #include "AtomicStringImpl.h"
 #include "PlatformString.h"
 
+// Define 'NO_IMPLICIT_ATOMICSTRING' before including this header,
+// to disallow (expensive) implicit String-->AtomicString conversions.
+#ifdef NO_IMPLICIT_ATOMICSTRING
+#define ATOMICSTRING_CONVERSION explicit
+#else
+#define ATOMICSTRING_CONVERSION
+#endif
+
 namespace WebCore {
 
 struct AtomicStringHash;
@@ -40,9 +48,9 @@ public:
     AtomicString(const JSC::UString& s) : m_string(add(s)) { }
     AtomicString(const JSC::Identifier& s) : m_string(add(s)) { }
 #endif
-    AtomicString(StringImpl* imp) : m_string(add(imp)) { }
+    ATOMICSTRING_CONVERSION AtomicString(StringImpl* imp) : m_string(add(imp)) { }
     AtomicString(AtomicStringImpl* imp) : m_string(imp) { }
-    AtomicString(const String& s) : m_string(add(s.impl())) { }
+    ATOMICSTRING_CONVERSION AtomicString(const String& s) : m_string(add(s.impl())) { }
 
     // Hash table deleted values, which are only constructed and never copied or destroyed.
     AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
diff --git a/WebCore/svg/SVGAnimatedProperty.h b/WebCore/svg/SVGAnimatedProperty.h
index 984046f..5ae677f 100644
--- a/WebCore/svg/SVGAnimatedProperty.h
+++ b/WebCore/svg/SVGAnimatedProperty.h
@@ -474,7 +474,7 @@ namespace WebCore {
     struct PropertySynchronizer<OwnerElement, DecoratedType, true> : Noncopyable {
         static void synchronize(const OwnerElement* ownerElement, const QualifiedName& attributeName, DecoratedType baseValue)
         {
-            AtomicString value(SVGAnimatedTypeValue<DecoratedType>::toString(baseValue));
+            String value(SVGAnimatedTypeValue<DecoratedType>::toString(baseValue));
 
             NamedNodeMap* namedAttrMap = ownerElement->attributes(false); 
             Attribute* old = namedAttrMap->getAttributeItem(attributeName);
@@ -483,7 +483,7 @@ namespace WebCore {
             else if (!old && !value.isNull()) 
                 namedAttrMap->addAttribute(const_cast<OwnerElement*>(ownerElement)->createAttribute(attributeName, value));
             else if (old && !value.isNull()) 
-                old->setValue(value); 
+                old->setValue(AtomicString(value)); 
         }
     };
 
diff --git a/WebCore/svg/SVGAnimatedTemplate.h b/WebCore/svg/SVGAnimatedTemplate.h
index e7c49c1..d65fe0b 100644
--- a/WebCore/svg/SVGAnimatedTemplate.h
+++ b/WebCore/svg/SVGAnimatedTemplate.h
@@ -172,7 +172,7 @@ namespace WebCore {
         typedef Type* DecoratedType;
 
         static Type null() { return 0; }
-        static AtomicString toString(Type type) { return type ? AtomicString(type->valueAsString()) : nullAtom; }
+        static String toString(Type type) { return type ? type->valueAsString() : String(); }
     };
 
     template<>
@@ -181,7 +181,7 @@ namespace WebCore {
         typedef bool DecoratedType;
 
         static bool null() { return false; }
-        static AtomicString toString(bool type) { return type ? "true" : "false"; }
+        static String toString(bool type) { return type ? "true" : "false"; }
     };
 
     template<>
@@ -190,7 +190,7 @@ namespace WebCore {
         typedef int DecoratedType;
 
         static int null() { return 0; }
-        static AtomicString toString(int type) { return String::number(type); }
+        static String toString(int type) { return String::number(type); }
     };
 
     template<>
@@ -199,7 +199,7 @@ namespace WebCore {
         typedef long DecoratedType;
 
         static long null() { return 0l; }
-        static AtomicString toString(long type) { return String::number(type); }
+        static String toString(long type) { return String::number(type); }
     };
 
     template<>
@@ -208,7 +208,7 @@ namespace WebCore {
         typedef SVGLength DecoratedType;
 
         static SVGLength null() { return SVGLength(); }
-        static AtomicString toString(const SVGLength& type) { return type.valueAsString(); }
+        static String toString(const SVGLength& type) { return type.valueAsString(); }
     };
 
     template<>
@@ -217,7 +217,7 @@ namespace WebCore {
         typedef float DecoratedType;
 
         static float null() { return 0.0f; }
-        static AtomicString toString(float type) { return String::number(type); }
+        static String toString(float type) { return String::number(type); }
     };
 
     template<>
@@ -226,7 +226,7 @@ namespace WebCore {
         typedef FloatRect DecoratedType;
 
         static FloatRect null() { return FloatRect(); }
-        static AtomicString toString(const FloatRect& type) { return String::format("%f %f %f %f", type.x(), type.y(), type.width(), type.height()); }
+        static String toString(const FloatRect& type) { return String::format("%f %f %f %f", type.x(), type.y(), type.width(), type.height()); }
     };
 
     template<>
@@ -235,7 +235,7 @@ namespace WebCore {
         typedef String DecoratedType;
 
         static String null() { return String(); }
-        static AtomicString toString(const String& type) { return type; }
+        static String toString(const String& type) { return type; }
     };
 
     // Common type definitions, to ease IDL generation.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list