Changeset 147464 in webkit
- Timestamp:
- Apr 2, 2013 11:12:30 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r147463 r147464 1 2013-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 1 31 2013-04-02 Bem Jones-Bey <bjonesbe@adobe.com> 2 32 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r147038 r147464 1824 1824 my $type = $attribute->signature->type; 1825 1825 my $isNullable = $attribute->signature->isNullable; 1826 my $isCachedAttribute = $attribute->signature->extendedAttributes->{"CachedAttribute"}; 1826 1827 $codeGenerator->AssertNotSequenceType($type); 1827 1828 my $getFunctionName = GetAttributeGetterName($interfaceName, $className, $attribute); … … 1840 1841 } 1841 1842 1842 if ($ attribute->signature->extendedAttributes->{"CachedAttribute"}) {1843 if ($isCachedAttribute) { 1843 1844 $needsMarkChildren = 1; 1844 1845 } … … 1889 1890 1890 1891 my $cacheIndex = 0; 1891 if ($ attribute->signature->extendedAttributes->{"CachedAttribute"}) {1892 if ($isCachedAttribute) { 1892 1893 $cacheIndex = $currentCachedAttribute; 1893 1894 $currentCachedAttribute++; … … 1897 1898 1898 1899 my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"); 1900 my $returnValue = "result"; 1899 1901 1900 1902 if ($svgListPropertyType) { … … 1924 1926 unshift(@arguments, @callWithArgs); 1925 1927 1926 my $jsType = NativeToJSValue($attribute->signature, 0, $interfaceName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis");1927 1928 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 1935 1929 if ($isNullable) { 1930 my $nativeType = GetNativeType($type); 1931 push(@implContent, " $nativeType nativeResult = " . NativeValueToLocal("$functionName(" . join(", ", @arguments) . ")", $nativeType) . ";\n"); 1936 1932 push(@implContent, " if (isNull)\n"); 1937 1933 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 } 1938 1947 } 1939 1948 } 1940 1949 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"); 1943 1952 1944 1953 } else { … … 1952 1961 1953 1962 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()")); 1963 my $nativeType = GetNativeType($type); 1954 1964 1955 1965 if ($svgPropertyOrListPropertyType) { 1956 1966 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"); 1958 1968 } else { 1959 1969 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"); 1961 1971 } 1962 1972 … … 1967 1977 1968 1978 push(@implContent, " setDOMException(exec, ec);\n"); 1969 push(@implContent, " return result;\n");1979 push(@implContent, " return " . NativeToJSValue($attribute->signature, 0, $interfaceName, "nativeResult", "castedThis") . ";\n"); 1970 1980 } 1971 1981 … … 3198 3208 } 3199 3209 3210 sub NativeValueToLocal 3211 { 3212 my $value = shift; 3213 my $type = shift; 3214 3215 return "WTF::getPtr($value)" if $type =~ /\*$/; 3216 return $value; 3217 } 3218 3200 3219 sub JSValueToNative 3201 3220 { -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r147038 r147464 658 658 ExceptionCode ec = 0; 659 659 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 660 JSC::JSValue result = jsNumber(impl->attrWithGetterException(ec));660 int nativeResult = impl->attrWithGetterException(ec); 661 661 setDOMException(exec, ec); 662 return result;662 return jsNumber(nativeResult); 663 663 } 664 664 … … 679 679 ExceptionCode ec = 0; 680 680 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 681 JSC::JSValue result = jsStringWithCache(exec, impl->stringAttrWithGetterException(ec));681 const String& nativeResult = impl->stringAttrWithGetterException(ec); 682 682 setDOMException(exec, ec); 683 return result;683 return jsStringWithCache(exec, nativeResult); 684 684 } 685 685 … … 728 728 ExceptionCode ec = 0; 729 729 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)); 731 731 setDOMException(exec, ec); 732 return result;732 return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult)); 733 733 } 734 734 … … 742 742 return jsUndefined(); 743 743 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)); 745 745 setDOMException(exec, ec); 746 return result;746 return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult)); 747 747 } 748 748 … … 768 768 return jsUndefined(); 769 769 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)); 771 771 setDOMException(exec, ec); 772 return result;772 return toJS(exec, castedThis->globalObject(), WTF::getPtr(nativeResult)); 773 773 } 774 774 … … 988 988 bool isNull = false; 989 989 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 990 JSValue result = jsNumber(impl->nullableDoubleAttribute(isNull));990 double nativeResult = impl->nullableDoubleAttribute(isNull); 991 991 if (isNull) 992 992 return jsNull(); 993 return result;993 return jsNumber(nativeResult); 994 994 } 995 995 … … 1001 1001 bool isNull = false; 1002 1002 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 1003 JSValue result = jsNumber(impl->nullableLongAttribute(isNull));1003 int nativeResult = impl->nullableLongAttribute(isNull); 1004 1004 if (isNull) 1005 1005 return jsNull(); 1006 return result;1006 return jsNumber(nativeResult); 1007 1007 } 1008 1008 … … 1014 1014 bool isNull = false; 1015 1015 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 1016 JSValue result = jsBoolean(impl->nullableBooleanAttribute(isNull));1016 bool nativeResult = impl->nullableBooleanAttribute(isNull); 1017 1017 if (isNull) 1018 1018 return jsNull(); 1019 return result;1019 return jsBoolean(nativeResult); 1020 1020 } 1021 1021 … … 1027 1027 bool isNull = false; 1028 1028 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 1029 JSValue result = jsStringWithCache(exec, impl->nullableStringAttribute(isNull));1029 const String& nativeResult = impl->nullableStringAttribute(isNull); 1030 1030 if (isNull) 1031 1031 return jsNull(); 1032 return result;1032 return jsStringWithCache(exec, nativeResult); 1033 1033 } 1034 1034 … … 1040 1040 bool isNull = false; 1041 1041 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 1042 JSValue result = jsNumber(impl->nullableLongSettableAttribute(isNull));1042 int nativeResult = impl->nullableLongSettableAttribute(isNull); 1043 1043 if (isNull) 1044 1044 return jsNull(); 1045 return result;1045 return jsNumber(nativeResult); 1046 1046 } 1047 1047 … … 1053 1053 bool isNull = false; 1054 1054 TestObj* impl = static_cast<TestObj*>(castedThis->impl()); 1055 JSC::JSValue result = jsNumber(impl->nullableStringValue(isNull, ec));1055 int nativeResult = impl->nullableStringValue(isNull, ec); 1056 1056 if (isNull) 1057 1057 return jsNull(); 1058 1058 setDOMException(exec, ec); 1059 return result;1059 return jsNumber(nativeResult); 1060 1060 } 1061 1061 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp
r147038 r147464 226 226 ExceptionCode ec = 0; 227 227 TestTypedefs* impl = static_cast<TestTypedefs*>(castedThis->impl()); 228 JSC::JSValue result = jsNumber(impl->attrWithGetterException(ec));228 int nativeResult = impl->attrWithGetterException(ec); 229 229 setDOMException(exec, ec); 230 return result;230 return jsNumber(nativeResult); 231 231 } 232 232 … … 247 247 ExceptionCode ec = 0; 248 248 TestTypedefs* impl = static_cast<TestTypedefs*>(castedThis->impl()); 249 JSC::JSValue result = jsStringWithCache(exec, impl->stringAttrWithGetterException(ec));249 const String& nativeResult = impl->stringAttrWithGetterException(ec); 250 250 setDOMException(exec, ec); 251 return result;251 return jsStringWithCache(exec, nativeResult); 252 252 } 253 253
Note: See TracChangeset
for help on using the changeset viewer.