Changeset 123433 in webkit
- Timestamp:
- Jul 24, 2012 12:21:25 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r123429 r123433 1 2012-07-24 Kentaro Hara <haraken@chromium.org> 2 3 [JSC] REGRESSION(r122912): CodeGeneratorJS.pm should not 4 implicitly assume ScriptExecutionContext for static attributes 5 https://bugs.webkit.org/show_bug.cgi?id=91924 6 7 Reviewed by Adam Barth. 8 9 r122912 implemented static attributes in CodeGeneratorJS.pm. 10 However, the generated code assumes that static attributes 11 always require ScriptExecutionContext, which is wrong. 12 If we need a ScriptExecutionContext, we should specify 13 [CallWith=ScriptExecutionContext]. 14 15 This patch fixes CodeGeneratorJS.pm so that static attributes 16 do not assume ScriptExecutionContext. This fix aligns with 17 the fix in CodeGeneratorV8.pm in r123308. 18 19 Test: bindings/scripts/test/TestObj.idl 20 21 * bindings/scripts/CodeGeneratorJS.pm: 22 (GenerateImplementation): 23 * bindings/scripts/test/JS/JSTestInterface.cpp: 24 (WebCore::jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr): 25 (WebCore::jsTestInterfaceConstructorSupplementalStaticAttr): 26 (WebCore::setJSTestInterfaceConstructorSupplementalStaticAttr): 27 * bindings/scripts/test/JS/JSTestObj.cpp: 28 (WebCore::jsTestObjConstructorStaticReadOnlyIntAttr): 29 (WebCore::jsTestObjConstructorStaticStringAttr): 30 (WebCore::setJSTestObjConstructorStaticStringAttr): 31 1 32 2012-07-23 Gyuyoung Kim <gyuyoung.kim@samsung.com> 2 33 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r122912 r123433 1772 1772 push(@implContent, "{\n"); 1773 1773 1774 if ($attribute->isStatic) { 1775 push(@implContent, " ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();\n"); 1776 push(@implContent, " if (!scriptContext)\n"); 1774 if (!$attribute->isStatic) { 1775 push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n"); 1776 } 1777 1778 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1779 $needsMarkChildren = 1; 1780 } 1781 1782 if ($dataNode->extendedAttributes->{"CheckSecurity"} && 1783 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"} && 1784 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurityOnGetter"}) { 1785 push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n"); 1777 1786 push(@implContent, " return jsUndefined();\n"); 1778 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "${implClassName}::$implGetterFunctionName(scriptContext)", "") . ";\n"); 1787 } 1788 1789 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}) { 1790 push(@implContent, " return castedThis->$implGetterFunctionName(exec);\n"); 1791 } elsif ($attribute->signature->extendedAttributes->{"CheckSecurityForNode"}) { 1792 $implIncludes{"JSDOMBinding.h"} = 1; 1793 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1794 push(@implContent, " return shouldAllowAccessToNode(exec, impl->" . $attribute->signature->name . "()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName()", "castedThis") . " : jsNull();\n"); 1795 } elsif ($type eq "EventListener") { 1796 $implIncludes{"EventListener.h"} = 1; 1797 push(@implContent, " UNUSED_PARAM(exec);\n"); 1798 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1799 push(@implContent, " if (EventListener* listener = impl->$implGetterFunctionName()) {\n"); 1800 push(@implContent, " if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {\n"); 1801 if ($implClassName eq "Document" || $implClassName eq "WorkerContext" || $implClassName eq "SharedWorkerContext" || $implClassName eq "DedicatedWorkerContext") { 1802 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl))\n"); 1803 } else { 1804 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl->scriptExecutionContext()))\n"); 1805 } 1806 push(@implContent, " return jsFunction;\n"); 1807 push(@implContent, " }\n"); 1808 push(@implContent, " }\n"); 1809 push(@implContent, " return jsNull();\n"); 1810 } elsif ($attribute->signature->type =~ /Constructor$/) { 1811 my $constructorType = $codeGenerator->StripModule($attribute->signature->type); 1812 $constructorType =~ s/Constructor$//; 1813 # Constructor attribute is only used by DOMWindow.idl, so it's correct to pass castedThis as the global object 1814 # Once JSDOMWrappers have a back-pointer to the globalObject we can pass castedThis->globalObject() 1815 push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis);\n"); 1816 } elsif (!@{$attribute->getterExceptions}) { 1817 push(@implContent, " UNUSED_PARAM(exec);\n") if !$attribute->signature->extendedAttributes->{"CallWith"}; 1818 1819 my $cacheIndex = 0; 1820 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1821 $cacheIndex = $currentCachedAttribute; 1822 $currentCachedAttribute++; 1823 push(@implContent, " if (JSValue cachedValue = castedThis->m_" . $attribute->signature->name . ".get())\n"); 1824 push(@implContent, " return cachedValue;\n"); 1825 } 1826 1827 my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"); 1828 1829 if ($svgListPropertyType) { 1830 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "castedThis->impl()->$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); 1831 } elsif ($svgPropertyOrListPropertyType) { 1832 push(@implContent, " $svgPropertyOrListPropertyType& impl = castedThis->impl()->propertyReference();\n"); 1833 if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber 1834 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl", "castedThis") . ";\n"); 1835 } else { 1836 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); 1837 1838 } 1839 } else { 1840 my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); 1841 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { 1842 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; 1843 $implIncludes{"${implementedBy}.h"} = 1; 1844 $functionName = "${implementedBy}::${functionName}"; 1845 unshift(@arguments, "impl"); 1846 } elsif ($attribute->isStatic) { 1847 $functionName = "${implClassName}::${functionName}"; 1848 } else { 1849 $functionName = "impl->${functionName}"; 1850 } 1851 1852 unshift(@arguments, @callWithArgs); 1853 1854 my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis"); 1855 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n") if !$attribute->isStatic; 1856 if ($codeGenerator->IsSVGAnimatedType($type)) { 1857 push(@implContent, " RefPtr<$type> obj = $jsType;\n"); 1858 push(@implContent, " JSValue result = toJS(exec, castedThis->globalObject(), obj.get());\n"); 1859 } else { 1860 push(@implContent, " JSValue result = $jsType;\n"); 1861 } 1862 } 1863 1864 push(@implContent, " castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"}); 1779 1865 push(@implContent, " return result;\n"); 1866 1780 1867 } else { 1781 push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n"); 1782 1783 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1784 $needsMarkChildren = 1; 1868 my @arguments = ("ec"); 1869 push(@implContent, " ExceptionCode ec = 0;\n"); 1870 1871 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()")); 1872 1873 if ($svgPropertyOrListPropertyType) { 1874 push(@implContent, " $svgPropertyOrListPropertyType impl(*castedThis->impl());\n"); 1875 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); 1876 } else { 1877 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1878 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); 1785 1879 } 1786 1880 1787 if ($dataNode->extendedAttributes->{"CheckSecurity"} && 1788 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"} && 1789 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurityOnGetter"}) { 1790 push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n"); 1791 push(@implContent, " return jsUndefined();\n"); 1792 } 1793 1794 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}) { 1795 push(@implContent, " return castedThis->$implGetterFunctionName(exec);\n"); 1796 } elsif ($attribute->signature->extendedAttributes->{"CheckSecurityForNode"}) { 1797 $implIncludes{"JSDOMBinding.h"} = 1; 1798 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1799 push(@implContent, " return shouldAllowAccessToNode(exec, impl->" . $attribute->signature->name . "()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName()", "castedThis") . " : jsNull();\n"); 1800 } elsif ($type eq "EventListener") { 1801 $implIncludes{"EventListener.h"} = 1; 1802 push(@implContent, " UNUSED_PARAM(exec);\n"); 1803 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1804 push(@implContent, " if (EventListener* listener = impl->$implGetterFunctionName()) {\n"); 1805 push(@implContent, " if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {\n"); 1806 if ($implClassName eq "Document" || $implClassName eq "WorkerContext" || $implClassName eq "SharedWorkerContext" || $implClassName eq "DedicatedWorkerContext") { 1807 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl))\n"); 1808 } else { 1809 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl->scriptExecutionContext()))\n"); 1810 } 1811 push(@implContent, " return jsFunction;\n"); 1812 push(@implContent, " }\n"); 1813 push(@implContent, " }\n"); 1814 push(@implContent, " return jsNull();\n"); 1815 } elsif ($attribute->signature->type =~ /Constructor$/) { 1816 my $constructorType = $codeGenerator->StripModule($attribute->signature->type); 1817 $constructorType =~ s/Constructor$//; 1818 # Constructor attribute is only used by DOMWindow.idl, so it's correct to pass castedThis as the global object 1819 # Once JSDOMWrappers have a back-pointer to the globalObject we can pass castedThis->globalObject() 1820 push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis);\n"); 1821 } elsif (!@{$attribute->getterExceptions}) { 1822 push(@implContent, " UNUSED_PARAM(exec);\n") if !$attribute->signature->extendedAttributes->{"CallWith"}; 1823 1824 my $cacheIndex = 0; 1825 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1826 $cacheIndex = $currentCachedAttribute; 1827 $currentCachedAttribute++; 1828 push(@implContent, " if (JSValue cachedValue = castedThis->m_" . $attribute->signature->name . ".get())\n"); 1829 push(@implContent, " return cachedValue;\n"); 1830 } 1831 1832 my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"); 1833 1834 if ($svgListPropertyType) { 1835 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "castedThis->impl()->$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); 1836 } elsif ($svgPropertyOrListPropertyType) { 1837 push(@implContent, " $svgPropertyOrListPropertyType& impl = castedThis->impl()->propertyReference();\n"); 1838 if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber 1839 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl", "castedThis") . ";\n"); 1840 } else { 1841 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); 1842 1843 } 1844 } else { 1845 my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); 1846 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { 1847 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; 1848 $implIncludes{"${implementedBy}.h"} = 1; 1849 $functionName = "${implementedBy}::${functionName}"; 1850 unshift(@arguments, "impl"); 1851 } else { 1852 $functionName = "impl->${functionName}"; 1853 } 1854 1855 unshift(@arguments, @callWithArgs); 1856 1857 my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis"); 1858 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1859 if ($codeGenerator->IsSVGAnimatedType($type)) { 1860 push(@implContent, " RefPtr<$type> obj = $jsType;\n"); 1861 push(@implContent, " JSValue result = toJS(exec, castedThis->globalObject(), obj.get());\n"); 1862 } else { 1863 push(@implContent, " JSValue result = $jsType;\n"); 1864 } 1865 } 1866 1867 push(@implContent, " castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"}); 1868 push(@implContent, " return result;\n"); 1869 1870 } else { 1871 my @arguments = ("ec"); 1872 push(@implContent, " ExceptionCode ec = 0;\n"); 1873 1874 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()")); 1875 1876 if ($svgPropertyOrListPropertyType) { 1877 push(@implContent, " $svgPropertyOrListPropertyType impl(*castedThis->impl());\n"); 1878 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); 1879 } else { 1880 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1881 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); 1882 } 1883 1884 push(@implContent, " setDOMException(exec, ec);\n"); 1885 push(@implContent, " return result;\n"); 1886 } 1881 push(@implContent, " setDOMException(exec, ec);\n"); 1882 push(@implContent, " return result;\n"); 1887 1883 } 1888 1884 … … 1973 1969 push(@implContent, "{\n"); 1974 1970 1975 if ($attribute->isStatic) {1976 push(@implContent, " ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();\n");1977 push(@implContent, " if (!scriptContext)\n");1978 push(@implContent, " return;\n");1979 my $nativeValue = JSValueToNative($attribute->signature, "value");1980 push(@implContent, " ${implClassName}::set$implSetterFunctionName(scriptContext, ${nativeValue});\n");1981 } else {1982 1971 push(@implContent, " UNUSED_PARAM(exec);\n"); 1983 1972 … … 2028 2017 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); 2029 2018 } else { 2030 push(@implContent, " $className* castedThis = jsCast<$className*>(thisObject);\n"); 2031 push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); 2019 if (!$attribute->isStatic) { 2020 push(@implContent, " $className* castedThis = jsCast<$className*>(thisObject);\n"); 2021 push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); 2022 } 2032 2023 push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; 2033 2024 … … 2083 2074 unshift(@arguments, "impl"); 2084 2075 $functionName = "${implementedBy}::${functionName}"; 2076 } elsif ($attribute->isStatic) { 2077 $functionName = "${implClassName}::${functionName}"; 2085 2078 } else { 2086 2079 $functionName = "impl->${functionName}"; … … 2094 2087 } 2095 2088 } 2096 }2097 2089 2098 2090 push(@implContent, "}\n\n"); -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
r123308 r123433 245 245 JSValue jsTestInterfaceConstructorSupplementalStaticReadOnlyAttr(ExecState* exec, JSValue, PropertyName) 246 246 { 247 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 248 if (!scriptContext) 249 return jsUndefined(); 250 JSC::JSValue result = jsNumber(TestInterface::supplementalStaticReadOnlyAttr(scriptContext)); 247 UNUSED_PARAM(exec); 248 JSValue result = jsNumber(TestSupplemental::supplementalStaticReadOnlyAttr(impl)); 251 249 return result; 252 250 } … … 257 255 JSValue jsTestInterfaceConstructorSupplementalStaticAttr(ExecState* exec, JSValue, PropertyName) 258 256 { 259 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 260 if (!scriptContext) 261 return jsUndefined(); 262 JSC::JSValue result = jsString(exec, TestInterface::supplementalStaticAttr(scriptContext)); 257 UNUSED_PARAM(exec); 258 JSValue result = jsString(exec, TestSupplemental::supplementalStaticAttr(impl)); 263 259 return result; 264 260 } … … 329 325 void setJSTestInterfaceConstructorSupplementalStaticAttr(ExecState* exec, JSObject*, JSValue value) 330 326 { 331 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 332 if (!scriptContext) 333 return; 334 TestInterface::setSupplementalStaticAttr(scriptContext, ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec))); 327 UNUSED_PARAM(exec); 328 TestSupplemental::setSupplementalStaticAttr(impl, ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec))); 335 329 } 336 330 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r123047 r123433 417 417 JSValue jsTestObjConstructorStaticReadOnlyIntAttr(ExecState* exec, JSValue, PropertyName) 418 418 { 419 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 420 if (!scriptContext) 421 return jsUndefined(); 422 JSC::JSValue result = jsNumber(TestObj::staticReadOnlyIntAttr(scriptContext)); 419 UNUSED_PARAM(exec); 420 JSValue result = jsNumber(TestObj::staticReadOnlyIntAttr()); 423 421 return result; 424 422 } … … 427 425 JSValue jsTestObjConstructorStaticStringAttr(ExecState* exec, JSValue, PropertyName) 428 426 { 429 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 430 if (!scriptContext) 431 return jsUndefined(); 432 JSC::JSValue result = jsString(exec, TestObj::staticStringAttr(scriptContext)); 427 UNUSED_PARAM(exec); 428 JSValue result = jsString(exec, TestObj::staticStringAttr()); 433 429 return result; 434 430 } … … 950 946 void setJSTestObjConstructorStaticStringAttr(ExecState* exec, JSObject*, JSValue value) 951 947 { 952 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 953 if (!scriptContext) 954 return; 955 TestObj::setStaticStringAttr(scriptContext, ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec))); 948 UNUSED_PARAM(exec); 949 TestObj::setStaticStringAttr(ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec))); 956 950 } 957 951
Note: See TracChangeset
for help on using the changeset viewer.