Changeset 122912 in webkit
- Timestamp:
- Jul 17, 2012 6:16:14 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r122911 r122912 1 2012-07-17 Jon Lee <jonlee@apple.com> 2 3 Teach CodeGenerator to support for static, readonly, attributes 4 https://bugs.webkit.org/show_bug.cgi?id=88920 5 <rdar://problem/11650330> 6 7 Reviewed by Oliver Hunt. 8 9 Update the parser to be able to accept the static keyword for attribute. We will treat static attributes 10 like custom static functions. They call the implementing class directly, and pass in the ExecState as a script context. 11 12 * bindings/scripts/CodeGeneratorJS.pm: 13 (GetAttributeGetterName): Factor out the construction of the attribute getter function name. 14 (GetAttributeSetterName): Factor out the construction of the attribute setter function name. 15 (GenerateHeader): Determine that a class has read-write properties only if there is a read-write attribute that 16 is not static. 17 (GenerateAttributesHashTable): Skip static attributes in the object hash table. They will be added to the constructor 18 hash table. 19 (GenerateImplementation): Look for static attributes to add to the constructor hash table. Make a call to the static 20 function in the class. 21 * bindings/scripts/IDLParser.pm: 22 (ParseInterface): Update the processing because of the regex change. 23 * bindings/scripts/IDLStructure.pm: Update the attribute regex. 24 * bindings/scripts/test/JS/JSTestObj.cpp: Update test results. 25 * bindings/scripts/test/JS/JSTestObj.h: Update test results. 26 * bindings/scripts/test/TestObj.idl: Add test cases. 27 1 28 2012-07-17 Kenichi Ishibashi <bashi@chromium.org> 2 29 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r122561 r122912 635 635 } 636 636 637 sub GetAttributeGetterName 638 { 639 my ($interfaceName, $className, $attribute) = @_; 640 if ($attribute->isStatic) { 641 return $codeGenerator->WK_lcfirst($className) . "Constructor" . $codeGenerator->WK_ucfirst($attribute->signature->name); 642 } 643 return "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); 644 } 645 646 sub GetAttributeSetterName 647 { 648 my ($interfaceName, $className, $attribute) = @_; 649 if ($attribute->isStatic) { 650 return "set" . $codeGenerator->WK_ucfirst($className) . "Constructor" . $codeGenerator->WK_ucfirst($attribute->signature->name); 651 } 652 return "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); 653 } 654 637 655 sub GetFunctionName 638 656 { … … 786 804 my $hasReadWriteProperties = 0; 787 805 foreach (@{$dataNode->attributes}) { 788 if ($_->type !~ /^readonly\ attribute$/ ) {806 if ($_->type !~ /^readonly\ attribute$/ && !$_->isStatic) { 789 807 $hasReadWriteProperties = 1; 790 808 } … … 1118 1136 my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); 1119 1137 push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; 1120 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1138 my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); 1121 1139 push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);\n"); 1122 1140 unless ($attribute->type =~ /readonly/) { 1123 my $setter = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1141 my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); 1124 1142 push(@headerContent, "void ${setter}(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);\n"); 1125 1143 } … … 1187 1205 1188 1206 foreach my $attribute (@{$dataNode->attributes}) { 1207 next if ($attribute->isStatic); 1189 1208 my $name = $attribute->signature->name; 1190 1209 push(@hashKeys, $name); … … 1197 1216 push(@hashSpecials, $special); 1198 1217 1199 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1218 my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); 1200 1219 push(@hashValue1, $getter); 1201 1220 … … 1203 1222 push(@hashValue2, "0"); 1204 1223 } else { 1205 my $setter = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1224 my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); 1206 1225 push(@hashValue2, $setter); 1207 1226 } … … 1409 1428 } 1410 1429 my $conditional = $constant->extendedAttributes->{"Conditional"}; 1430 if ($conditional) { 1431 $conditionals{$name} = $conditional; 1432 } 1433 } 1434 1435 foreach my $attribute (@{$dataNode->attributes}) { 1436 next unless ($attribute->isStatic); 1437 my $name = $attribute->signature->name; 1438 push(@hashKeys, $name); 1439 1440 my @specials = (); 1441 push(@specials, "DontDelete") unless $attribute->signature->extendedAttributes->{"Deletable"}; 1442 push(@specials, "ReadOnly") if $attribute->type =~ /readonly/; 1443 my $special = (@specials > 0) ? join(" | ", @specials) : "0"; 1444 push(@hashSpecials, $special); 1445 1446 my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); 1447 push(@hashValue1, $getter); 1448 1449 if ($attribute->type =~ /readonly/) { 1450 push(@hashValue2, "0"); 1451 } else { 1452 my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); 1453 push(@hashValue2, $setter); 1454 } 1455 1456 my $conditional = $attribute->signature->extendedAttributes->{"Conditional"}; 1411 1457 if ($conditional) { 1412 1458 $conditionals{$name} = $conditional; … … 1715 1761 my $type = $codeGenerator->StripModule($attribute->signature->type); 1716 1762 $codeGenerator->AssertNotSequenceType($type); 1717 my $getFunctionName = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1763 my $getFunctionName = GetAttributeGetterName($interfaceName, $className, $attribute); 1718 1764 my $implGetterFunctionName = $codeGenerator->WK_lcfirst($name); 1719 1765 … … 1721 1767 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; 1722 1768 1723 push(@implContent, "JSValue ${getFunctionName}(ExecState* exec, JSValue slotBase, PropertyName)\n"); 1769 push(@implContent, "JSValue ${getFunctionName}(ExecState* exec, JSValue"); 1770 push(@implContent, " slotBase") if !$attribute->isStatic; 1771 push(@implContent, ", PropertyName)\n"); 1724 1772 push(@implContent, "{\n"); 1725 push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n"); 1726 1727 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1728 $needsMarkChildren = 1; 1729 } 1730 1731 if ($dataNode->extendedAttributes->{"CheckSecurity"} && 1732 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"} && 1733 !$attribute->signature->extendedAttributes->{"DoNotCheckSecurityOnGetter"}) { 1734 push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n"); 1773 1774 if ($attribute->isStatic) { 1775 push(@implContent, " ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();\n"); 1776 push(@implContent, " if (!scriptContext)\n"); 1735 1777 push(@implContent, " return jsUndefined();\n"); 1736 } 1737 1738 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}) { 1739 push(@implContent, " return castedThis->$implGetterFunctionName(exec);\n"); 1740 } elsif ($attribute->signature->extendedAttributes->{"CheckSecurityForNode"}) { 1741 $implIncludes{"JSDOMBinding.h"} = 1; 1742 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1743 push(@implContent, " return shouldAllowAccessToNode(exec, impl->" . $attribute->signature->name . "()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName()", "castedThis") . " : jsNull();\n"); 1744 } elsif ($type eq "EventListener") { 1745 $implIncludes{"EventListener.h"} = 1; 1746 push(@implContent, " UNUSED_PARAM(exec);\n"); 1747 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1748 push(@implContent, " if (EventListener* listener = impl->$implGetterFunctionName()) {\n"); 1749 push(@implContent, " if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {\n"); 1750 if ($implClassName eq "Document" || $implClassName eq "WorkerContext" || $implClassName eq "SharedWorkerContext" || $implClassName eq "DedicatedWorkerContext") { 1751 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl))\n"); 1778 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "${implClassName}::$implGetterFunctionName(scriptContext)", "") . ";\n"); 1779 push(@implContent, " return result;\n"); 1780 } else { 1781 push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n"); 1782 1783 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { 1784 $needsMarkChildren = 1; 1785 } 1786 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 1752 1870 } else { 1753 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl->scriptExecutionContext()))\n"); 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"); 1754 1886 } 1755 push(@implContent, " return jsFunction;\n");1756 push(@implContent, " }\n");1757 push(@implContent, " }\n");1758 push(@implContent, " return jsNull();\n");1759 } elsif ($attribute->signature->type =~ /Constructor$/) {1760 my $constructorType = $codeGenerator->StripModule($attribute->signature->type);1761 $constructorType =~ s/Constructor$//;1762 # Constructor attribute is only used by DOMWindow.idl, so it's correct to pass castedThis as the global object1763 # Once JSDOMWrappers have a back-pointer to the globalObject we can pass castedThis->globalObject()1764 push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis);\n");1765 } elsif (!@{$attribute->getterExceptions}) {1766 push(@implContent, " UNUSED_PARAM(exec);\n") if !$attribute->signature->extendedAttributes->{"CallWith"};1767 1768 my $cacheIndex = 0;1769 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) {1770 $cacheIndex = $currentCachedAttribute;1771 $currentCachedAttribute++;1772 push(@implContent, " if (JSValue cachedValue = castedThis->m_" . $attribute->signature->name . ".get())\n");1773 push(@implContent, " return cachedValue;\n");1774 }1775 1776 my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()");1777 1778 if ($svgListPropertyType) {1779 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "castedThis->impl()->$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n");1780 } elsif ($svgPropertyOrListPropertyType) {1781 push(@implContent, " $svgPropertyOrListPropertyType& impl = castedThis->impl()->propertyReference();\n");1782 if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber1783 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl", "castedThis") . ";\n");1784 } else {1785 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n");1786 1787 }1788 } else {1789 my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute);1790 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {1791 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};1792 $implIncludes{"${implementedBy}.h"} = 1;1793 $functionName = "${implementedBy}::${functionName}";1794 unshift(@arguments, "impl");1795 } else {1796 $functionName = "impl->${functionName}";1797 }1798 1799 unshift(@arguments, @callWithArgs);1800 1801 my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis");1802 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n");1803 if ($codeGenerator->IsSVGAnimatedType($type)) {1804 push(@implContent, " RefPtr<$type> obj = $jsType;\n");1805 push(@implContent, " JSValue result = toJS(exec, castedThis->globalObject(), obj.get());\n");1806 } else {1807 push(@implContent, " JSValue result = $jsType;\n");1808 }1809 }1810 1811 push(@implContent, " castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"});1812 push(@implContent, " return result;\n");1813 1814 } else {1815 my @arguments = ("ec");1816 push(@implContent, " ExceptionCode ec = 0;\n");1817 1818 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"));1819 1820 if ($svgPropertyOrListPropertyType) {1821 push(@implContent, " $svgPropertyOrListPropertyType impl(*castedThis->impl());\n");1822 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n");1823 } else {1824 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n");1825 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n");1826 }1827 1828 push(@implContent, " setDOMException(exec, ec);\n");1829 push(@implContent, " return result;\n");1830 1887 } 1831 1888 … … 1857 1914 my $hasReadWriteProperties = 0; 1858 1915 foreach my $attribute (@{$dataNode->attributes}) { 1859 $hasReadWriteProperties = 1 if $attribute->type !~ /^readonly/ ;1916 $hasReadWriteProperties = 1 if $attribute->type !~ /^readonly/ && !$attribute->isStatic; 1860 1917 } 1861 1918 … … 1905 1962 my $name = $attribute->signature->name; 1906 1963 my $type = $codeGenerator->StripModule($attribute->signature->type); 1907 my $putFunctionName = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");1964 my $putFunctionName = GetAttributeSetterName($interfaceName, $className, $attribute); 1908 1965 my $implSetterFunctionName = $codeGenerator->WK_ucfirst($name); 1909 1966 … … 1911 1968 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; 1912 1969 1913 push(@implContent, "void ${putFunctionName}(ExecState* exec, JSObject* thisObject, JSValue value)\n"); 1970 push(@implContent, "void ${putFunctionName}(ExecState* exec, JSObject*"); 1971 push(@implContent, " thisObject") if !$attribute->isStatic; 1972 push(@implContent, ", JSValue value)\n"); 1914 1973 push(@implContent, "{\n"); 1915 push(@implContent, " UNUSED_PARAM(exec);\n"); 1916 1917 if ($dataNode->extendedAttributes->{"CheckSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"}) { 1918 if ($interfaceName eq "DOMWindow") { 1919 push(@implContent, " if (!jsCast<$className*>(thisObject)->allowsAccessFrom(exec))\n"); 1974 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 push(@implContent, " UNUSED_PARAM(exec);\n"); 1983 1984 if ($dataNode->extendedAttributes->{"CheckSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"}) { 1985 if ($interfaceName eq "DOMWindow") { 1986 push(@implContent, " if (!jsCast<$className*>(thisObject)->allowsAccessFrom(exec))\n"); 1987 } else { 1988 push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl()->frame()))\n"); 1989 } 1990 push(@implContent, " return;\n"); 1991 } 1992 1993 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCustomSetter"}) { 1994 push(@implContent, " jsCast<$className*>(thisObject)->set$implSetterFunctionName(exec, value);\n"); 1995 } elsif ($type eq "EventListener") { 1996 $implIncludes{"JSEventListener.h"} = 1; 1997 push(@implContent, " UNUSED_PARAM(exec);\n"); 1998 push(@implContent, " ${className}* castedThis = jsCast<${className}*>(thisObject);\n"); 1999 my $windowEventListener = $attribute->signature->extendedAttributes->{"JSWindowEventListener"}; 2000 if ($windowEventListener) { 2001 push(@implContent, " JSDOMGlobalObject* globalObject = castedThis->globalObject();\n"); 2002 } 2003 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 2004 if ((($interfaceName eq "DOMWindow") or ($interfaceName eq "WorkerContext")) and $name eq "onerror") { 2005 $implIncludes{"JSErrorHandler.h"} = 1; 2006 push(@implContent, " impl->set$implSetterFunctionName(createJSErrorHandler(exec, value, thisObject));\n"); 2007 } else { 2008 push(@implContent, GenerateAttributeEventListenerCall($className, $implSetterFunctionName, $windowEventListener)); 2009 } 2010 } elsif ($attribute->signature->type =~ /Constructor$/) { 2011 my $constructorType = $attribute->signature->type; 2012 $constructorType =~ s/Constructor$//; 2013 # $constructorType ~= /Constructor$/ indicates that it is NamedConstructor. 2014 # We do not generate the header file for NamedConstructor of class XXXX, 2015 # since we generate the NamedConstructor declaration into the header file of class XXXX. 2016 if ($constructorType ne "DOMObject" and $constructorType !~ /Constructor$/) { 2017 AddToImplIncludes("JS" . $constructorType . ".h", $attribute->signature->extendedAttributes->{"Conditional"}); 2018 } 2019 push(@implContent, " // Shadowing a built-in constructor\n"); 2020 if ($interfaceName eq "DOMWindow" && $className eq "JSblah") { 2021 # FIXME: This branch never executes and should be removed. 2022 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), exec->propertyNames().constructor, value);\n"); 2023 } else { 2024 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); 2025 } 2026 } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) { 2027 push(@implContent, " // Shadowing a built-in object\n"); 2028 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); 1920 2029 } else { 1921 push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl()->frame()))\n"); 1922 } 1923 push(@implContent, " return;\n"); 1924 } 1925 1926 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCustomSetter"}) { 1927 push(@implContent, " jsCast<$className*>(thisObject)->set$implSetterFunctionName(exec, value);\n"); 1928 } elsif ($type eq "EventListener") { 1929 $implIncludes{"JSEventListener.h"} = 1; 1930 push(@implContent, " UNUSED_PARAM(exec);\n"); 1931 push(@implContent, " ${className}* castedThis = jsCast<${className}*>(thisObject);\n"); 1932 my $windowEventListener = $attribute->signature->extendedAttributes->{"JSWindowEventListener"}; 1933 if ($windowEventListener) { 1934 push(@implContent, " JSDOMGlobalObject* globalObject = castedThis->globalObject();\n"); 1935 } 1936 push(@implContent, " $implClassName* impl = static_cast<$implClassName*>(castedThis->impl());\n"); 1937 if ((($interfaceName eq "DOMWindow") or ($interfaceName eq "WorkerContext")) and $name eq "onerror") { 1938 $implIncludes{"JSErrorHandler.h"} = 1; 1939 push(@implContent, " impl->set$implSetterFunctionName(createJSErrorHandler(exec, value, thisObject));\n"); 1940 } else { 1941 push(@implContent, GenerateAttributeEventListenerCall($className, $implSetterFunctionName, $windowEventListener)); 1942 } 1943 } elsif ($attribute->signature->type =~ /Constructor$/) { 1944 my $constructorType = $attribute->signature->type; 1945 $constructorType =~ s/Constructor$//; 1946 # $constructorType ~= /Constructor$/ indicates that it is NamedConstructor. 1947 # We do not generate the header file for NamedConstructor of class XXXX, 1948 # since we generate the NamedConstructor declaration into the header file of class XXXX. 1949 if ($constructorType ne "DOMObject" and $constructorType !~ /Constructor$/) { 1950 AddToImplIncludes("JS" . $constructorType . ".h", $attribute->signature->extendedAttributes->{"Conditional"}); 1951 } 1952 push(@implContent, " // Shadowing a built-in constructor\n"); 1953 if ($interfaceName eq "DOMWindow" && $className eq "JSblah") { 1954 # FIXME: This branch never executes and should be removed. 1955 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), exec->propertyNames().constructor, value);\n"); 1956 } else { 1957 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); 1958 } 1959 } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) { 1960 push(@implContent, " // Shadowing a built-in object\n"); 1961 push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); 1962 } else { 1963 push(@implContent, " $className* castedThis = jsCast<$className*>(thisObject);\n"); 1964 push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); 1965 push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; 1966 1967 # If the "StrictTypeChecking" extended attribute is present, and the attribute's type is an 1968 # interface type, then if the incoming value does not implement that interface, a TypeError 1969 # is thrown rather than silently passing NULL to the C++ code. 1970 # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to 1971 # both strings and numbers, so do not throw TypeError if the attribute is of these types. 1972 if ($attribute->signature->extendedAttributes->{"StrictTypeChecking"}) { 1973 $implIncludes{"<runtime/Error.h>"} = 1; 1974 1975 my $argType = $attribute->signature->type; 1976 if (!IsNativeType($argType)) { 1977 push(@implContent, " if (!value.isUndefinedOrNull() && !value.inherits(&JS${argType}::s_info)) {\n"); 1978 push(@implContent, " throwVMTypeError(exec);\n"); 1979 push(@implContent, " return;\n"); 1980 push(@implContent, " };\n"); 2030 push(@implContent, " $className* castedThis = jsCast<$className*>(thisObject);\n"); 2031 push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); 2032 push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; 2033 2034 # If the "StrictTypeChecking" extended attribute is present, and the attribute's type is an 2035 # interface type, then if the incoming value does not implement that interface, a TypeError 2036 # is thrown rather than silently passing NULL to the C++ code. 2037 # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to 2038 # both strings and numbers, so do not throw TypeError if the attribute is of these types. 2039 if ($attribute->signature->extendedAttributes->{"StrictTypeChecking"}) { 2040 $implIncludes{"<runtime/Error.h>"} = 1; 2041 2042 my $argType = $attribute->signature->type; 2043 if (!IsNativeType($argType)) { 2044 push(@implContent, " if (!value.isUndefinedOrNull() && !value.inherits(&JS${argType}::s_info)) {\n"); 2045 push(@implContent, " throwVMTypeError(exec);\n"); 2046 push(@implContent, " return;\n"); 2047 push(@implContent, " };\n"); 2048 } 1981 2049 } 1982 } 1983 1984 my $nativeValue = JSValueToNative($attribute->signature, "value"); 1985 if ($svgPropertyOrListPropertyType) { 1986 if ($svgPropertyType) { 1987 push(@implContent, " if (impl->isReadOnly()) {\n"); 1988 push(@implContent, " setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);\n"); 1989 push(@implContent, " return;\n"); 1990 push(@implContent, " }\n"); 1991 $implIncludes{"ExceptionCode.h"} = 1; 1992 } 1993 push(@implContent, " $svgPropertyOrListPropertyType& podImpl = impl->propertyReference();\n"); 1994 if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber 1995 push(@implContent, " podImpl = $nativeValue;\n"); 2050 2051 my $nativeValue = JSValueToNative($attribute->signature, "value"); 2052 if ($svgPropertyOrListPropertyType) { 2053 if ($svgPropertyType) { 2054 push(@implContent, " if (impl->isReadOnly()) {\n"); 2055 push(@implContent, " setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);\n"); 2056 push(@implContent, " return;\n"); 2057 push(@implContent, " }\n"); 2058 $implIncludes{"ExceptionCode.h"} = 1; 2059 } 2060 push(@implContent, " $svgPropertyOrListPropertyType& podImpl = impl->propertyReference();\n"); 2061 if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber 2062 push(@implContent, " podImpl = $nativeValue;\n"); 2063 } else { 2064 push(@implContent, " podImpl.set$implSetterFunctionName($nativeValue"); 2065 push(@implContent, ", ec") if @{$attribute->setterExceptions}; 2066 push(@implContent, ");\n"); 2067 push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions}; 2068 } 2069 if ($svgPropertyType) { 2070 if (@{$attribute->setterExceptions}) { 2071 push(@implContent, " if (!ec)\n"); 2072 push(@implContent, " impl->commitChange();\n"); 2073 } else { 2074 push(@implContent, " impl->commitChange();\n"); 2075 } 2076 } 1996 2077 } else { 1997 push(@implContent, " podImpl.set$implSetterFunctionName($nativeValue"); 1998 push(@implContent, ", ec") if @{$attribute->setterExceptions}; 1999 push(@implContent, ");\n"); 2078 my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); 2079 push(@arguments, $nativeValue); 2080 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { 2081 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; 2082 $implIncludes{"${implementedBy}.h"} = 1; 2083 unshift(@arguments, "impl"); 2084 $functionName = "${implementedBy}::${functionName}"; 2085 } else { 2086 $functionName = "impl->${functionName}"; 2087 } 2088 2089 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "")); 2090 2091 push(@arguments, "ec") if @{$attribute->setterExceptions}; 2092 push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n"); 2000 2093 push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions}; 2001 2094 } 2002 if ($svgPropertyType) {2003 if (@{$attribute->setterExceptions}) {2004 push(@implContent, " if (!ec)\n");2005 push(@implContent, " impl->commitChange();\n");2006 } else {2007 push(@implContent, " impl->commitChange();\n");2008 }2009 }2010 } else {2011 my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute);2012 push(@arguments, $nativeValue);2013 if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) {2014 my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"};2015 $implIncludes{"${implementedBy}.h"} = 1;2016 unshift(@arguments, "impl");2017 $functionName = "${implementedBy}::${functionName}";2018 } else {2019 $functionName = "impl->${functionName}";2020 }2021 2022 unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, ""));2023 2024 push(@arguments, "ec") if @{$attribute->setterExceptions};2025 push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n");2026 push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions};2027 2095 } 2028 2096 } -
trunk/Source/WebCore/bindings/scripts/IDLParser.pm
r121714 r122912 338 338 $line =~ /$IDLStructure::interfaceAttributeSelector/; 339 339 340 my $attributeType = (defined($1) ? $1 : die("Parsing error!\nSource:\n$line\n)")); 341 my $attributeExtendedAttributes = (defined($2) ? $2 : " "); chop($attributeExtendedAttributes); 342 343 my $attributeDataType = (defined($3) ? $3 : die("Parsing error!\nSource:\n$line\n)")); 344 my $attributeDataName = (defined($4) ? $4 : die("Parsing error!\nSource:\n$line\n)")); 340 my $isStatic = defined($1); 341 my $attributeType = (defined($2) ? $2 : die("Parsing error!\nSource:\n$line\n)")); 342 my $attributeExtendedAttributes = (defined($3) ? $3 : " "); chop($attributeExtendedAttributes); 343 344 my $attributeDataType = (defined($4) ? $4 : die("Parsing error!\nSource:\n$line\n)")); 345 my $attributeDataName = (defined($5) ? $5 : die("Parsing error!\nSource:\n$line\n)")); 345 346 346 347 ('' =~ /^/); # Reset variables needed for regexp matching … … 354 355 my $newDataNode = new domAttribute(); 355 356 $newDataNode->type($attributeType); 357 $newDataNode->isStatic($isStatic); 356 358 $newDataNode->signature(new domSignature()); 357 359 … … 363 365 push(@$arrayRef, $newDataNode); 364 366 365 print " | |> Attribute; TYPE \"$attributeType\" DATA NAME \"$attributeDataName\" DATA TYPE \"$attributeDataType\" GET EXCEPTION? \"$getterException\" SET EXCEPTION? \"$setterException\"" .367 print " | |> Attribute; STATIC? \"$isStatic\" TYPE \"$attributeType\" DATA NAME \"$attributeDataName\" DATA TYPE \"$attributeDataType\" GET EXCEPTION? \"$getterException\" SET EXCEPTION? \"$setterException\"" . 366 368 dumpExtendedAttributes("\n | ", $newDataNode->signature->extendedAttributes) . "\n" unless $beQuiet; 367 369 … … 392 394 $newDataNode->signature->extendedAttributes(parseExtendedAttributes($methodExtendedAttributes)); 393 395 394 print " | |- Method; TYPE \"$methodType\" NAME \"$methodName\" EXCEPTION? \"$methodException\"" .396 print " | |- Method; STATIC? \"$isStatic\" TYPE \"$methodType\" NAME \"$methodName\" EXCEPTION? \"$methodException\"" . 395 397 dumpExtendedAttributes("\n | ", $newDataNode->signature->extendedAttributes) . "\n" unless $beQuiet; 396 398 -
trunk/Source/WebCore/bindings/scripts/IDLStructure.pm
r121714 r122912 56 56 struct( domAttribute => { 57 57 type => '$', # Attribute type (including namespace) 58 isStatic => '$', 58 59 signature => '$', # Attribute signature 59 60 getterExceptions => '@', # Possibly raised exceptions. … … 111 112 our $interfaceParameterSelector = '(in|out)\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . $supportedTypeSuffix . '\s*(' . $idlIdNs . '*)'; 112 113 113 our $interfaceAttributeSelector = '\s*( readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)';114 our $interfaceAttributeSelector = '\s*(static\s+)?(readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)'; 114 115 115 116 1; -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r121817 r122912 167 167 { "CONST_VALUE_14", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCONST_VALUE_14), (intptr_t)0, NoIntrinsic }, 168 168 { "CONST_JAVASCRIPT", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCONST_JAVASCRIPT), (intptr_t)0, NoIntrinsic }, 169 { "staticReadOnlyIntAttr", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorStaticReadOnlyIntAttr), (intptr_t)0, NoIntrinsic }, 170 { "staticStringAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjConstructorStaticStringAttr), (intptr_t)setJSTestObjConstructorStaticStringAttr, NoIntrinsic }, 169 171 { "classMethod", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionClassMethod), (intptr_t)0, NoIntrinsic }, 170 172 { "classMethodWithOptional", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionClassMethodWithOptional), (intptr_t)1, NoIntrinsic }, … … 412 414 413 415 416 JSValue jsTestObjConstructorStaticReadOnlyIntAttr(ExecState* exec, JSValue, PropertyName) 417 { 418 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 419 if (!scriptContext) 420 return jsUndefined(); 421 JSC::JSValue result = jsNumber(TestObj::staticReadOnlyIntAttr(scriptContext)); 422 return result; 423 } 424 425 426 JSValue jsTestObjConstructorStaticStringAttr(ExecState* exec, JSValue, PropertyName) 427 { 428 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 429 if (!scriptContext) 430 return jsUndefined(); 431 JSC::JSValue result = jsString(exec, TestObj::staticStringAttr(scriptContext)); 432 return result; 433 } 434 435 414 436 JSValue jsTestObjShortAttr(ExecState* exec, JSValue slotBase, PropertyName) 415 437 { … … 914 936 lookupPut<JSTestObj, Base>(exec, propertyName, value, &JSTestObjTable, thisObject, slot); 915 937 } 938 939 void setJSTestObjConstructorStaticStringAttr(ExecState* exec, JSObject*, JSValue value) 940 { 941 ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); 942 if (!scriptContext) 943 return; 944 TestObj::setStaticStringAttr(scriptContext, ustringToString(value.isEmpty() ? UString() : value.toString(exec)->value(exec))); 945 } 946 916 947 917 948 void setJSTestObjShortAttr(ExecState* exec, JSObject* thisObject, JSValue value) -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
r120304 r122912 221 221 JSC::JSValue jsTestObjReadOnlyStringAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName); 222 222 JSC::JSValue jsTestObjReadOnlyTestObjAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName); 223 JSC::JSValue jsTestObjConstructorStaticReadOnlyIntAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName); 224 JSC::JSValue jsTestObjConstructorStaticStringAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName); 225 void setJSTestObjConstructorStaticStringAttr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue); 223 226 JSC::JSValue jsTestObjShortAttr(JSC::ExecState*, JSC::JSValue, JSC::PropertyName); 224 227 void setJSTestObjShortAttr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue); -
trunk/Source/WebCore/bindings/scripts/test/TestObj.idl
r121817 r122912 39 39 readonly attribute DOMString readOnlyStringAttr; 40 40 readonly attribute TestObj readOnlyTestObjAttr; 41 #if defined(TESTING_JS) 42 static readonly attribute long staticReadOnlyIntAttr; 43 static attribute DOMString staticStringAttr; 44 #endif 41 45 attribute short shortAttr; 42 46 attribute unsigned short unsignedShortAttr;
Note: See TracChangeset
for help on using the changeset viewer.