Commit 5f911b2e authored by darin@apple.com's avatar darin@apple.com

2009-06-21 Darin Adler <darin@apple.com>

        Reviewed by Sam Weinig.

        Bug 25425: DOM attribute getter/setter functions should use const AtomicString& type
        https://bugs.webkit.org/show_bug.cgi?id=25425

        * bindings/scripts/CodeGeneratorJS.pm: Tweaked mechanism for includes to be a bit
        more consistent and to make SVGElement.h be included in the header rather than in
        every implementation file that includes the header. Added code to use getAttribute
        and setAttribute directly when the [Reflect] extended attribute is used.

        * bindings/scripts/CodeGeneratorObjC.pm: Ditto.

        * html/HTMLElement.idl: Used [Reflect] for all the attributes in this class that
        reflect content attributes. Restricting this to one class for now to keep the
        patch small and start out slowly.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44930 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 09f8e91e
2009-06-21 Darin Adler <darin@apple.com>
Reviewed by Sam Weinig.
Bug 25425: DOM attribute getter/setter functions should use const AtomicString& type
https://bugs.webkit.org/show_bug.cgi?id=25425
* bindings/scripts/CodeGeneratorJS.pm: Tweaked mechanism for includes to be a bit
more consistent and to make SVGElement.h be included in the header rather than in
every implementation file that includes the header. Added code to use getAttribute
and setAttribute directly when the [Reflect] extended attribute is used.
* bindings/scripts/CodeGeneratorObjC.pm: Ditto.
* html/HTMLElement.idl: Used [Reflect] for all the attributes in this class that
reflect content attributes. Restricting this to one class for now to keep the
patch small and start out slowly.
2009-06-21 Sam Weinig <sam@webkit.org>
Reviewed by Oliver Hunt.
......@@ -30,7 +48,9 @@
(WebCore::XSSAuditor::canCreateInlineEventListener):
(WebCore::XSSAuditor::canLoadExternalScriptFromSrc):
(WebCore::XSSAuditor::canLoadObject):
* page/XSSAuditor.h: Removed method setXSSAuditorEnabled, and field m_isEnabled. Moved implementation of isEnabled to XSSAuditor.cpp and changed implementation to query Settings.
* page/XSSAuditor.h: Removed method setXSSAuditorEnabled, and field m_isEnabled.
Moved implementation of isEnabled to XSSAuditor.cpp and changed implementation
to query Settings.
2009-06-21 David Levin <levin@chromium.org>
......
......@@ -34,7 +34,6 @@ my %headerIncludes = ();
my @implContentHeader = ();
my @implContent = ();
my %implIncludes = ();
my %implKJSIncludes = ();
# Default .h template
my $headerTemplate = << "EOF";
......@@ -220,7 +219,7 @@ sub AddClassForwardIfNeeded
{
my $implClassName = shift;
# SVGAnimatedLength/Number/etc.. are typedefs to SVGAnimtatedTemplate, so don't use class forwards for them!
# SVGAnimatedLength/Number/etc. are typedefs to SVGAnimatedTemplate, so don't use class forwards for them!
push(@headerContent, "class $implClassName;\n\n") unless $codeGenerator->IsSVGAnimatedType($implClassName);
}
......@@ -378,36 +377,38 @@ sub GenerateHeader
my $conditionalString;
if ($conditional) {
$conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
push(@headerContentHeader, "\n#if ${conditionalString}\n\n");
push(@headerContentHeader, "#if ${conditionalString}\n\n");
}
if ($hasParent) {
push(@headerContentHeader, "#include \"$parentClassName.h\"\n");
$headerIncludes{"$parentClassName.h"} = 1;
} else {
push(@headerContentHeader, "#include \"JSDOMBinding.h\"\n");
push(@headerContentHeader, "#include <runtime/JSGlobalObject.h>\n");
push(@headerContentHeader, "#include <runtime/ObjectPrototype.h>\n");
$headerIncludes{"JSDOMBinding.h"} = 1;
$headerIncludes{"<runtime/JSGlobalObject.h>"} = 1;
$headerIncludes{"<runtime/ObjectPrototype.h>"} = 1;
}
if ($dataNode->extendedAttributes->{"CustomCall"}) {
push(@headerContentHeader, "#include <runtime/CallData.h>\n");
$headerIncludes{"<runtime/CallData.h>"} = 1;
}
if ($dataNode->extendedAttributes->{"InlineGetOwnPropertySlot"}) {
push(@headerContentHeader, "#include <runtime/Lookup.h>\n");
push(@headerContentHeader, "#include <wtf/AlwaysInline.h>\n");
$headerIncludes{"<runtime/Lookup.h>"} = 1;
$headerIncludes{"<wtf/AlwaysInline.h>"} = 1;
}
if ($hasParent && $dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
push(@headerContentHeader, "#include \"${implClassName}.h\"");
$headerIncludes{"$implClassName.h"} = 1;
}
$headerIncludes{"SVGElement.h"} = 1 if $className =~ /^JSSVG/;
# Get correct pass/store types respecting PODType flag
my $podType = $dataNode->extendedAttributes->{"PODType"};
my $implType = $podType ? "JSSVGPODTypeWrapper<$podType> " : $implClassName;
push(@headerContentHeader, "#include \"$podType.h\"\n") if $podType and $podType ne "float";
$headerIncludes{"$podType.h"} = 1 if $podType and $podType ne "float";
push(@headerContentHeader, "#include \"JSSVGPODTypeWrapper.h\"\n") if $podType;
$headerIncludes{"JSSVGPODTypeWrapper.h"} = 1 if $podType;
my $numConstants = @{$dataNode->constants};
my $numAttributes = @{$dataNode->attributes};
......@@ -742,25 +743,19 @@ sub GenerateImplementation
# - Add default header template
@implContentHeader = split("\r", $headerTemplate);
push(@implContentHeader, "\n#include \"config.h\"\n\n");
push(@implContentHeader, "\n#include \"config.h\"\n");
my $conditionalString;
if ($conditional) {
$conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
push(@implContentHeader, "\n#if ${conditionalString}\n\n");
}
if ($className =~ /^JSSVG/) {
push(@implContentHeader, "#include \"SVGElement.h\"\n");
if ($className =~ /^JSSVGAnimated/) {
AddIncludesForSVGAnimatedType($interfaceName);
}
}
push(@implContentHeader, "#include \"$className.h\"\n\n");
push(@implContentHeader, "#include <wtf/GetPtr.h>\n\n");
push(@implContentHeader, "#include <runtime/PropertyNameArray.h>\n") if $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"};
AddIncludesForSVGAnimatedType($interfaceName) if $className =~ /^JSSVGAnimated/;
$implIncludes{"<wtf/GetPtr.h>"} = 1;
$implIncludes{"<runtime/PropertyNameArray.h>"} = 1 if $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"};
AddIncludesForType($interfaceName);
......@@ -1158,7 +1153,15 @@ sub GenerateImplementation
}
} else {
push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(asObject(slot.slotBase()))->impl());\n");
my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "static_cast<$className*>(asObject(slot.slotBase()))");
my $value;
if (my $reflect = $attribute->signature->extendedAttributes->{"Reflect"}) {
$implIncludes{"HTMLNames.h"} = 1;
my $contentAttributeName = $reflect eq "1" ? $name : $reflect;
$value = "imp->getAttribute(HTMLNames::${contentAttributeName}Attr)"
} else {
$value = "imp->$implGetterFunctionName()";
}
my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, $value, "static_cast<$className*>(asObject(slot.slotBase()))");
if ($codeGenerator->IsSVGAnimatedType($type)) {
push(@implContent, " RefPtr<$type> obj = $jsType;\n");
push(@implContent, " return toJS(exec, obj.get(), imp);\n");
......@@ -1299,8 +1302,15 @@ sub GenerateImplementation
push(@implContent, " static_cast<$className*>(thisObject)->impl()->commitChange(imp, static_cast<$className*>(thisObject)->context());\n");
} else {
push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n");
my $nativeValue = JSValueToNative($attribute->signature, "value");
push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions};
push(@implContent, " imp->set$implSetterFunctionName(" . JSValueToNative($attribute->signature, "value"));
if (my $reflect = $attribute->signature->extendedAttributes->{"Reflect"}) {
$implIncludes{"HTMLNames.h"} = 1;
my $contentAttributeName = $reflect eq "1" ? $name : $reflect;
push(@implContent, " imp->setAttribute(HTMLNames::${contentAttributeName}Attr, $nativeValue");
} else {
push(@implContent, " imp->set$implSetterFunctionName($nativeValue");
}
push(@implContent, ", ec") if @{$attribute->setterExceptions};
push(@implContent, ");\n");
push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions};
......@@ -1348,7 +1358,7 @@ sub GenerateImplementation
push(@implContent, "{\n");
push(@implContent, " UNUSED_PARAM(args);\n");
$implKJSInclude{"Error.h"} = 1;
$implIncludes{"<runtime/Error.h>"} = 1;
if ($interfaceName eq "DOMWindow") {
push(@implContent, " $className* castedThisObj = toJSDOMWindow(thisValue.toThisObject(exec));\n");
......@@ -1664,7 +1674,7 @@ sub NativeToJSValue
return "jsBoolean($value)" if $type eq "boolean";
if ($codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType" or $type eq "DOMTimeStamp") {
$implKJSInclude{"JSNumberCell.h"} = 1;
$implIncludes{"<runtime/JSNumberCell.h>"} = 1;
return "jsNumber(exec, $value)";
}
......@@ -1678,7 +1688,7 @@ sub NativeToJSValue
die "Unknown value for ConvertNullStringTo extended attribute";
}
$implKJSInclude{"JSString.h"} = 1;
$implIncludes{"<runtime/JSString.h>"} = 1;
return "jsString(exec, $value)";
}
......@@ -1964,17 +1974,17 @@ sub WriteData
# Write content to file.
print $IMPL @implContentHeader;
foreach my $implInclude (sort keys(%implIncludes)) {
my $checkType = $implInclude;
my @includes = ();
foreach my $include (keys %implIncludes) {
my $checkType = $include;
$checkType =~ s/\.h//;
next if $codeGenerator->IsSVGAnimatedType($checkType);
print $IMPL "#include \"$implInclude\"\n" unless $codeGenerator->IsSVGAnimatedType($checkType);
$include = "\"$include\"" unless $include =~ /^["<]/; # "
push @includes, $include;
}
print $IMPL "\n";
foreach my $implKJSInclude (sort keys(%implKJSInclude)) {
print $IMPL "#include <runtime/$implKJSInclude>\n";
foreach my $include (sort @includes) {
print $IMPL "#include $include\n";
}
print $IMPL @implContent;
......@@ -1984,15 +1994,19 @@ sub WriteData
@implContentHeader = ();
@implContent = ();
%implIncludes = ();
%implKJSIncludes = ();
}
if (defined($HEADER)) {
# Write content to file.
print $HEADER @headerContentHeader;
foreach my $headerInclude (sort keys(%headerIncludes)) {
print $HEADER "#include \"$headerInclude\"\n";
my @includes = ();
foreach my $include (keys %headerIncludes) {
$include = "\"$include\"" unless $include =~ /^["<]/; # "
push @includes, $include;
}
foreach my $include (sort @includes) {
print $HEADER "#include $include\n";
}
print $HEADER @headerContent;
......@@ -2057,7 +2071,7 @@ bool ${className}Constructor::getOwnPropertySlot(ExecState* exec, const Identifi
EOF
$implKJSInclude{"JSNumberCell.h"} = 1;
$implJSCInclude{"JSNumberCell.h"} = 1;
return $implContent;
}
......
......@@ -1129,7 +1129,14 @@ sub GenerateImplementation
# - GETTER
my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
my $hasGetterException = @{$attribute->getterExceptions};
my $getterContentHead = "IMPL->" . $codeGenerator->WK_lcfirst($attributeName) . "(";
my $getterContentHead;
if (my $reflect = $attribute->signature->extendedAttributes->{"Reflect"}) {
$implIncludes{"HTMLNames.h"} = 1;
my $contentAttributeName = $reflect eq "1" ? $attributeName : $reflect;
$getterContentHead = "IMPL->getAttribute(WebCore::HTMLNames::${contentAttributeName}Attr";
} else {
$getterContentHead = "IMPL->" . $codeGenerator->WK_lcfirst($attributeName) . "(";
}
my $getterContentTail = ")";
# Special case for DOMSVGNumber
......@@ -1226,7 +1233,7 @@ sub GenerateImplementation
# Exception handling
my $hasSetterException = @{$attribute->setterExceptions};
$attributeName = "set" . $codeGenerator->WK_ucfirst($attributeName);
my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
my $setterName = "set" . ucfirst($attributeInterfaceName);
my $argName = "new" . ucfirst($attributeInterfaceName);
my $arg = GetObjCTypeGetter($argName, $idlType);
......@@ -1252,14 +1259,18 @@ sub GenerateImplementation
if ($podType eq "float") {
push(@implContent, " *IMPL = $arg;\n");
} else {
push(@implContent, " IMPL->$attributeName($arg);\n");
push(@implContent, " IMPL->$coreSetterName($arg);\n");
}
} elsif ($hasSetterException) {
push(@implContent, " $exceptionInit\n");
push(@implContent, " IMPL->$attributeName($arg, ec);\n");
push(@implContent, " IMPL->$coreSetterName($arg, ec);\n");
push(@implContent, " $exceptionRaiseOnError\n");
} elsif (my $reflect = $attribute->signature->extendedAttributes->{"Reflect"}) {
$implIncludes{"HTMLNames.h"} = 1;
my $contentAttributeName = $reflect eq "1" ? $attributeName : $reflect;
push(@implContent, " IMPL->setAttribute(WebCore::HTMLNames::${contentAttributeName}Attr, $arg);\n");
} else {
push(@implContent, " IMPL->$attributeName($arg);\n");
push(@implContent, " IMPL->$coreSetterName($arg);\n");
}
push(@implContent, "}\n\n");
......
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
*
* This library is free software; you can redistribute it and/or
......@@ -29,11 +29,11 @@ module html {
] HTMLElement : Element {
// iht.com relies on id returning the empty string when no id is present.
// Other browsers do this as well. So we don't convert null to JS null.
attribute [ConvertNullToNullString] DOMString id;
attribute [ConvertNullToNullString] DOMString title;
attribute [ConvertNullToNullString] DOMString lang;
attribute [ConvertNullToNullString] DOMString dir;
attribute [ConvertNullToNullString] DOMString className;
attribute [ConvertNullToNullString, Reflect] DOMString id;
attribute [ConvertNullToNullString, Reflect] DOMString title;
attribute [ConvertNullToNullString, Reflect] DOMString lang;
attribute [ConvertNullToNullString, Reflect] DOMString dir;
attribute [ConvertNullToNullString, Reflect=class] DOMString className;
attribute long tabIndex;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment