Changeset 147464 in webkit


Ignore:
Timestamp:
Apr 2, 2013 11:12:30 AM (11 years ago)
Author:
peter@chromium.org
Message:

[JSC] Don't create a JSValue if it's not going to be used for nullable attributes
https://bugs.webkit.org/show_bug.cgi?id=112711

Reviewed by Sam Weinig.

When nullable attributes are used, it's possible that we disregard the JSValue
when null should be returned instead. This is a waste, and we should cast the
native type to a JSValue as late as possible.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateImplementation):
(NativeValueToLocal):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::jsTestObjAttrWithGetterException):
(WebCore::jsTestObjStringAttrWithGetterException):
(WebCore::jsTestObjWithScriptStateAttributeRaises):
(WebCore::jsTestObjWithScriptExecutionContextAttributeRaises):
(WebCore::jsTestObjWithScriptExecutionContextAndScriptStateAttributeRaises):
(WebCore::jsTestObjNullableDoubleAttribute):
(WebCore::jsTestObjNullableLongAttribute):
(WebCore::jsTestObjNullableBooleanAttribute):
(WebCore::jsTestObjNullableStringAttribute):
(WebCore::jsTestObjNullableLongSettableAttribute):
(WebCore::jsTestObjNullableStringValue):

  • bindings/scripts/test/JS/JSTestTypedefs.cpp:

(WebCore::jsTestTypedefsAttrWithGetterException):
(WebCore::jsTestTypedefsStringAttrWithGetterException):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r147463 r147464  
     12013-04-02  Peter Beverloo  <peter@chromium.org>
     2
     3        [JSC] Don't create a JSValue if it's not going to be used for nullable attributes
     4        https://bugs.webkit.org/show_bug.cgi?id=112711
     5
     6        Reviewed by Sam Weinig.
     7
     8        When nullable attributes are used, it's possible that we disregard the JSValue
     9        when null should be returned instead. This is a waste, and we should cast the
     10        native type to a JSValue as late as possible.
     11
     12        * bindings/scripts/CodeGeneratorJS.pm:
     13        (GenerateImplementation):
     14        (NativeValueToLocal):
     15        * bindings/scripts/test/JS/JSTestObj.cpp:
     16        (WebCore::jsTestObjAttrWithGetterException):
     17        (WebCore::jsTestObjStringAttrWithGetterException):
     18        (WebCore::jsTestObjWithScriptStateAttributeRaises):
     19        (WebCore::jsTestObjWithScriptExecutionContextAttributeRaises):
     20        (WebCore::jsTestObjWithScriptExecutionContextAndScriptStateAttributeRaises):
     21        (WebCore::jsTestObjNullableDoubleAttribute):
     22        (WebCore::jsTestObjNullableLongAttribute):
     23        (WebCore::jsTestObjNullableBooleanAttribute):
     24        (WebCore::jsTestObjNullableStringAttribute):
     25        (WebCore::jsTestObjNullableLongSettableAttribute):
     26        (WebCore::jsTestObjNullableStringValue):
     27        * bindings/scripts/test/JS/JSTestTypedefs.cpp:
     28        (WebCore::jsTestTypedefsAttrWithGetterException):
     29        (WebCore::jsTestTypedefsStringAttrWithGetterException):
     30
    1312013-04-02  Bem Jones-Bey  <bjonesbe@adobe.com>
    232
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r147038 r147464  
    18241824                my $type = $attribute->signature->type;
    18251825                my $isNullable = $attribute->signature->isNullable;
     1826                my $isCachedAttribute = $attribute->signature->extendedAttributes->{"CachedAttribute"};
    18261827                $codeGenerator->AssertNotSequenceType($type);
    18271828                my $getFunctionName = GetAttributeGetterName($interfaceName, $className, $attribute);
     
    18401841                }
    18411842
    1842                 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) {
     1843                if ($isCachedAttribute) {
    18431844                    $needsMarkChildren = 1;
    18441845                }
     
    18891890
    18901891                    my $cacheIndex = 0;
    1891                     if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) {
     1892                    if ($isCachedAttribute) {
    18921893                        $cacheIndex = $currentCachedAttribute;
    18931894                        $currentCachedAttribute++;
     
    18971898
    18981899                    my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()");
     1900                    my $returnValue = "result";
    18991901
    19001902                    if ($svgListPropertyType) {
     
    19241926                        unshift(@arguments, @callWithArgs);
    19251927
    1926                         my $jsType = NativeToJSValue($attribute->signature, 0, $interfaceName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis");
    19271928                        push(@implContent, "    $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n") if !$attribute->isStatic;
    1928                         if ($codeGenerator->IsSVGAnimatedType($type)) {
    1929                             push(@implContent, "    RefPtr<$type> obj = $jsType;\n");
    1930                             push(@implContent, "    JSValue result =  toJS(exec, castedThis->globalObject(), obj.get());\n");
    1931                         } else {
    1932                             push(@implContent, "    JSValue result = $jsType;\n");
    1933                         }
    1934 
    19351929                        if ($isNullable) {
     1930                            my $nativeType = GetNativeType($type);
     1931                            push(@implContent, "    $nativeType nativeResult = " . NativeValueToLocal("$functionName(" . join(", ", @arguments) . ")", $nativeType) . ";\n");
    19361932                            push(@implContent, "    if (isNull)\n");
    19371933                            push(@implContent, "        return jsNull();\n");
     1934                            if ($isCachedAttribute) {
     1935                                push(@implContent, "    JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "nativeResult", "castedThis") . ";\n");
     1936                            } else {
     1937                                $returnValue = NativeToJSValue($attribute->signature, 0, $interfaceName, "nativeResult", "castedThis");
     1938                            }
     1939                        } else {
     1940                            my $jsType = NativeToJSValue($attribute->signature, 0, $interfaceName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis");
     1941                            if ($codeGenerator->IsSVGAnimatedType($type)) {
     1942                                push(@implContent, "    RefPtr<$type> obj = $jsType;\n");
     1943                                push(@implContent, "    JSValue result = toJS(exec, castedThis->globalObject(), obj.get());\n");
     1944                            } else {
     1945                                push(@implContent, "    JSValue result = $jsType;\n");
     1946                            }
    19381947                        }
    19391948                    }
    19401949
    1941                     push(@implContent, "    castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"});
    1942                     push(@implContent, "    return result;\n");
     1950                    push(@implContent, "    castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if $isCachedAttribute;
     1951                    push(@implContent, "    return $returnValue;\n");
    19431952
    19441953                } else {
     
    19521961
    19531962                    unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"));
     1963                    my $nativeType = GetNativeType($type);
    19541964
    19551965                    if ($svgPropertyOrListPropertyType) {
    19561966                        push(@implContent, "    $svgPropertyOrListPropertyType impl(*castedThis->impl());\n");
    1957                         push(@implContent, "    JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n");
     1967                        push(@implContent, "    $nativeType nativeResult = " . NativeValueToLocal("impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", $nativeType) . ";\n");
    19581968                    } else {
    19591969                        push(@implContent, "    $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n");
    1960                         push(@implContent, "    JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n");
     1970                        push(@implContent, "    $nativeType nativeResult = " . NativeValueToLocal("impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", $nativeType) . ";\n");
    19611971                    }
    19621972
     
    19671977
    19681978                    push(@implContent, "    setDOMException(exec, ec);\n");
    1969                     push(@implContent, "    return result;\n");
     1979                    push(@implContent, "    return " . NativeToJSValue($attribute->signature, 0, $interfaceName, "nativeResult", "castedThis") . ";\n");
    19701980                }
    19711981
     
    31983208}
    31993209
     3210sub NativeValueToLocal
     3211{
     3212    my $value = shift;
     3213    my $type = shift;
     3214
     3215    return "WTF::getPtr($value)" if $type =~ /\*$/;
     3216    return $value;
     3217}
     3218
    32003219sub JSValueToNative
    32013220{
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r147038 r147464  
    658658    ExceptionCode ec = 0;
    659659    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    660     JSC::JSValue result = jsNumber(impl->attrWithGetterException(ec));
     660    int nativeResult = impl->attrWithGetterException(ec);
    661661    setDOMException(exec, ec);
    662     return result;
     662    return jsNumber(nativeResult);
    663663}
    664664
     
    679679    ExceptionCode ec = 0;
    680680    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    681     JSC::JSValue result = jsStringWithCache(exec, impl->stringAttrWithGetterException(ec));
     681    const String& nativeResult = impl->stringAttrWithGetterException(ec);
    682682    setDOMException(exec, ec);
    683     return result;
     683    return jsStringWithCache(exec, nativeResult);
    684684}
    685685
     
    728728    ExceptionCode ec = 0;
    729729    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    730     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->withScriptStateAttributeRaises(exec, ec)));
     730    TestObj* nativeResult = WTF::getPtr(impl->withScriptStateAttributeRaises(exec, ec));
    731731    setDOMException(exec, ec);
    732     return result;
     732    return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult));
    733733}
    734734
     
    742742        return jsUndefined();
    743743    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    744     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->withScriptExecutionContextAttributeRaises(scriptContext, ec)));
     744    TestObj* nativeResult = WTF::getPtr(impl->withScriptExecutionContextAttributeRaises(scriptContext, ec));
    745745    setDOMException(exec, ec);
    746     return result;
     746    return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult));
    747747}
    748748
     
    768768        return jsUndefined();
    769769    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    770     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->withScriptExecutionContextAndScriptStateAttributeRaises(exec, scriptContext, ec)));
     770    TestObj* nativeResult = WTF::getPtr(impl->withScriptExecutionContextAndScriptStateAttributeRaises(exec, scriptContext, ec));
    771771    setDOMException(exec, ec);
    772     return result;
     772    return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult));
    773773}
    774774
     
    988988    bool isNull = false;
    989989    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    990     JSValue result = jsNumber(impl->nullableDoubleAttribute(isNull));
     990    double nativeResult = impl->nullableDoubleAttribute(isNull);
    991991    if (isNull)
    992992        return jsNull();
    993     return result;
     993    return jsNumber(nativeResult);
    994994}
    995995
     
    10011001    bool isNull = false;
    10021002    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    1003     JSValue result = jsNumber(impl->nullableLongAttribute(isNull));
     1003    int nativeResult = impl->nullableLongAttribute(isNull);
    10041004    if (isNull)
    10051005        return jsNull();
    1006     return result;
     1006    return jsNumber(nativeResult);
    10071007}
    10081008
     
    10141014    bool isNull = false;
    10151015    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    1016     JSValue result = jsBoolean(impl->nullableBooleanAttribute(isNull));
     1016    bool nativeResult = impl->nullableBooleanAttribute(isNull);
    10171017    if (isNull)
    10181018        return jsNull();
    1019     return result;
     1019    return jsBoolean(nativeResult);
    10201020}
    10211021
     
    10271027    bool isNull = false;
    10281028    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    1029     JSValue result = jsStringWithCache(exec, impl->nullableStringAttribute(isNull));
     1029    const String& nativeResult = impl->nullableStringAttribute(isNull);
    10301030    if (isNull)
    10311031        return jsNull();
    1032     return result;
     1032    return jsStringWithCache(exec, nativeResult);
    10331033}
    10341034
     
    10401040    bool isNull = false;
    10411041    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    1042     JSValue result = jsNumber(impl->nullableLongSettableAttribute(isNull));
     1042    int nativeResult = impl->nullableLongSettableAttribute(isNull);
    10431043    if (isNull)
    10441044        return jsNull();
    1045     return result;
     1045    return jsNumber(nativeResult);
    10461046}
    10471047
     
    10531053    bool isNull = false;
    10541054    TestObj* impl = static_cast<TestObj*>(castedThis->impl());
    1055     JSC::JSValue result = jsNumber(impl->nullableStringValue(isNull, ec));
     1055    int nativeResult = impl->nullableStringValue(isNull, ec);
    10561056    if (isNull)
    10571057        return jsNull();
    10581058    setDOMException(exec, ec);
    1059     return result;
     1059    return jsNumber(nativeResult);
    10601060}
    10611061
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp

    r147038 r147464  
    226226    ExceptionCode ec = 0;
    227227    TestTypedefs* impl = static_cast<TestTypedefs*>(castedThis->impl());
    228     JSC::JSValue result = jsNumber(impl->attrWithGetterException(ec));
     228    int nativeResult = impl->attrWithGetterException(ec);
    229229    setDOMException(exec, ec);
    230     return result;
     230    return jsNumber(nativeResult);
    231231}
    232232
     
    247247    ExceptionCode ec = 0;
    248248    TestTypedefs* impl = static_cast<TestTypedefs*>(castedThis->impl());
    249     JSC::JSValue result = jsStringWithCache(exec, impl->stringAttrWithGetterException(ec));
     249    const String& nativeResult = impl->stringAttrWithGetterException(ec);
    250250    setDOMException(exec, ec);
    251     return result;
     251    return jsStringWithCache(exec, nativeResult);
    252252}
    253253
Note: See TracChangeset for help on using the changeset viewer.