diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 835ffbf053bd7af002618e475e5e6aa3b2861854..bd2ecfc387ca1b62c900171678b814b0862a2e0f 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,24 @@ +2009-01-06 Julien Chaffraix + + Reviewed by Nikolas Zimmermann. + + Bug 22858: Simplify make_names.pl code for avoiding multiple definitions or inclusions + https://bugs.webkit.org/show_bug.cgi?id=22858 + + I had introduced an awkward situation using hasCustomJSWrapper and + sometimes boolean parameter in order to ensure JS wrapper generated once + or header included once. + + Simplified the code by using a %seenTag hash to detect multiple definitions + or inclusions and skipping it. + + Also cleaned up a bit make_names.pl by using more explicit names and moving + code to where it belongs. + + * dom/make_names.pl: + * html/HTMLTagNames.in: Necessary changes that were not detected by + the previous syntax but will be required for autogenerating HTMLElementFactory. + 2009-01-06 Anders Carlsson Reviewed by Sam Weinig. diff --git a/WebCore/dom/make_names.pl b/WebCore/dom/make_names.pl index 4f24b95b95fa31f0f82b25fe210e31933c24a7cd..7c3b4daebd9618169ee54d4d34040bfbeb3eb4a5 100755 --- a/WebCore/dom/make_names.pl +++ b/WebCore/dom/make_names.pl @@ -110,6 +110,12 @@ sub initializeParametersHash 'exportStrings' => 0); } +sub defaultInterfaceName +{ + die "No namespace found" if !$parameters{'namespace'}; + return $parameters{'namespace'} . upperCaseName($_[0]) . "Element" +} + ### Parsing handlers sub tagsHandler @@ -436,23 +442,28 @@ print F "\nvoid init() sub printJSElementIncludes { my $F = shift; - for my $name (sort keys %tags) { - next if hasCustomJSInterfaceName($name); - my $ucName = $tags{$name}{"JSInterfaceName"}; - print F "#include \"JS${ucName}.h\"\n"; + my %tagsSeen; + for my $tagName (sort keys %tags) { + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; + next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); + $tagsSeen{$JSInterfaceName} = 1; + + print F "#include \"JS${JSInterfaceName}.h\"\n"; } } sub printElementIncludes { - my ($F, $shouldSkipCustomMappings) = @_; + my $F = shift; - for my $name (sort keys %tags) { - next if ($shouldSkipCustomMappings && hasCustomJSInterfaceName($name)); + my %tagsSeen; + for my $tagName (sort keys %tags) { + my $interfaceName = $tags{$tagName}{"interfaceName"}; + next if defined($tagsSeen{$interfaceName}); + $tagsSeen{$interfaceName} = 1; - my $ucName = $tags{$name}{"interfaceName"}; - print F "#include \"${ucName}.h\"\n"; + print F "#include \"${interfaceName}.h\"\n"; } } @@ -524,7 +535,7 @@ print F < @@ -656,23 +667,7 @@ END ## Wrapper Factory routines -sub defaultInterfaceName -{ - die "No namespace found" if !$parameters{'namespace'}; - return $parameters{'namespace'} . upperCaseName($_[0]) . "Element" -} - -sub hasCustomJSInterfaceName -{ - my $tag = shift; - - # We have a custom JSInterface if the JSInterfaceName is not the same as the interfaceName. - # FIXME: The 'img' tag matches completely the 'image' tag and cannot be distinguished - # so we have to check for it. - return !($tags{$tag}{'JSInterfaceName'} eq $tags{$tag}{'interfaceName'}) || $tag eq "img"; -} - -sub usesDefaultWrapper +sub usesDefaultJSWrapper { my $name = shift; @@ -684,28 +679,30 @@ sub printWrapperFunctions { my $F = shift; - for my $name (sort keys %tags) { - # A custom JSInterface means that we reuse another tag's constructor. - next if hasCustomJSInterfaceName($name) || usesDefaultWrapper($name); + my %tagsSeen; + for my $tagName (sort keys %tags) { + # Avoid defining the same wrapper method twice. + my $JSInterfaceName = $tags{$tagName}{"JSInterfaceName"}; + next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName); + $tagsSeen{$JSInterfaceName} = 1; - my $ucName = $tags{$name}{"JSInterfaceName"}; # Hack for the media tags - if ($tags{$name}{"wrapperOnlyIfMediaIsAvailable"}) { + if ($tags{$tagName}{"wrapperOnlyIfMediaIsAvailable"}) { print F < element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) { if (!MediaPlayer::isAvailable()) return CREATE_DOM_NODE_WRAPPER(exec, $parameters{'namespace'}Element, element.get()); - return CREATE_DOM_NODE_WRAPPER(exec, ${ucName}, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get()); } END ; } else { print F < element) +static JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, PassRefPtr<$parameters{'namespace'}Element> element) { - return CREATE_DOM_NODE_WRAPPER(exec, ${ucName}, element.get()); + return CREATE_DOM_NODE_WRAPPER(exec, ${JSInterfaceName}, element.get()); } END @@ -732,7 +729,7 @@ sub printWrapperFactoryCppFile print F "\n#include \"$parameters{'namespace'}Names.h\"\n\n"; - printElementIncludes($F, 1); + printElementIncludes($F); print F "\n#include \n\n"; @@ -761,7 +758,7 @@ END for my $tag (sort keys %tags) { # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper. - next if usesDefaultWrapper($tag, \%tags); + next if usesDefaultJSWrapper($tag, \%tags); my $ucTag = $tags{$tag}{"JSInterfaceName"}; print F " map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n"; diff --git a/WebCore/html/HTMLTagNames.in b/WebCore/html/HTMLTagNames.in index 1cb8817e79c3e50494e35331b5114ba202389969..ed6961a8e248ba023541c538863ef179a9c9c87b 100644 --- a/WebCore/html/HTMLTagNames.in +++ b/WebCore/html/HTMLTagNames.in @@ -3,38 +3,38 @@ namespacePrefix="xhtml" namespaceURI="http://www.w3.org/1999/xhtml" a interfaceName=HTMLAnchorElement -abbr JSInterfaceName=HTMLElement -acronym JSInterfaceName=HTMLElement -address JSInterfaceName=HTMLElement +abbr interfaceName=HTMLElement +acronym interfaceName=HTMLElement +address interfaceName=HTMLElement applet area #if ENABLE_VIDEO audio wrapperOnlyIfMediaIsAvailable=1 #endif -b JSInterfaceName=HTMLElement +b interfaceName=HTMLElement base basefont interfaceName=HTMLBaseFontElement -bdo JSInterfaceName=HTMLElement -big JSInterfaceName=HTMLElement +bdo interfaceName=HTMLElement +big interfaceName=HTMLElement blockquote body br interfaceName=HTMLBRElement button canvas caption interfaceName=HTMLTableCaptionElement -center JSInterfaceName=HTMLElement -cite JSInterfaceName=HTMLElement -code JSInterfaceName=HTMLElement +center interfaceName=HTMLElement +cite interfaceName=HTMLElement +code interfaceName=HTMLElement col interfaceName=HTMLTableColElement -colgroup JSInterfaceName=HTMLTableColElement -dd JSInterfaceName=HTMLElement +colgroup interfaceName=HTMLTableColElement +dd interfaceName=HTMLElement del interfaceName=HTMLModElement -dfn JSInterfaceName=HTMLElement +dfn interfaceName=HTMLElement dir interfaceName=HTMLDirectoryElement div dl interfaceName=HTMLDListElement -dt JSInterfaceName=HTMLElement -em JSInterfaceName=HTMLElement +dt interfaceName=HTMLElement +em interfaceName=HTMLElement embed fieldset interfaceName=HTMLFieldSetElement font @@ -43,75 +43,75 @@ frame constructorNeedsCreatedByParser=1 frameset interfaceName=HTMLFrameSetElement head h1 interfaceName=HTMLHeadingElement -h2 JSInterfaceName=HTMLHeadingElement -h3 JSInterfaceName=HTMLHeadingElement -h4 JSInterfaceName=HTMLHeadingElement -h5 JSInterfaceName=HTMLHeadingElement -h6 JSInterfaceName=HTMLHeadingElement +h2 interfaceName=HTMLHeadingElement +h3 interfaceName=HTMLHeadingElement +h4 interfaceName=HTMLHeadingElement +h5 interfaceName=HTMLHeadingElement +h6 interfaceName=HTMLHeadingElement hr interfaceName=HTMLHRElement html -i JSInterfaceName=HTMLElement +i interfaceName=HTMLElement iframe interfaceName=HTMLIFrameElement, constructorNeedsCreatedByParser=1 image img interfaceName=HTMLImageElement input -ins JSInterfaceName=HTMLModElement +ins interfaceName=HTMLModElement isindex interfaceName=HTMLIsIndexElement -kbd JSInterfaceName=HTMLElement +kbd interfaceName=HTMLElement keygen JSInterfaceName=HTMLSelectElement label -layer JSInterfaceName=HTMLElement +layer interfaceName=HTMLElement legend li interfaceName=HTMLLIElement link constructorNeedsCreatedByParser=1 -listing JSInterfaceName=HTMLPreElement +listing interfaceName=HTMLPreElement map marquee menu meta -nobr JSInterfaceName=HTMLElement -noembed JSInterfaceName=HTMLElement -noframes JSInterfaceName=HTMLElement -nolayer JSInterfaceName=HTMLElement -noscript JSInterfaceName=HTMLElement +nobr interfaceName=HTMLElement +noembed interfaceName=HTMLElement +noframes interfaceName=HTMLElement +nolayer interfaceName=HTMLElement +noscript interfaceName=HTMLElement object ol interfaceName=HTMLOListElement optgroup interfaceName=HTMLOptGroupElement option p interfaceName=HTMLParagraphElement param -plaintext JSInterfaceName=HTMLElement +plaintext interfaceName=HTMLElement pre q interfaceName=HTMLQuoteElement -s JSInterfaceName=HTMLElement -samp JSInterfaceName=HTMLElement +s interfaceName=HTMLElement +samp interfaceName=HTMLElement script constructorNeedsCreatedByParser=1 select -small JSInterfaceName=HTMLElement +small interfaceName=HTMLElement #if ENABLE_VIDEO source wrapperOnlyIfMediaIsAvailable=1 #endif -span JSInterfaceName=HTMLElement -strike JSInterfaceName=HTMLElement -strong JSInterfaceName=HTMLElement +span interfaceName=HTMLElement +strike interfaceName=HTMLElement +strong interfaceName=HTMLElement style constructorNeedsCreatedByParser=1 -sub JSInterfaceName=HTMLElement -sup JSInterfaceName=HTMLElement +sub interfaceName=HTMLElement +sup interfaceName=HTMLElement table tbody interfaceName=HTMLTableSectionElement td interfaceName=HTMLTableCellElement textarea interfaceName=HTMLTextAreaElement -tfoot JSInterfaceName=HTMLTableSectionElement -th JSInterfaceName=HTMLTableCellElement -thead JSInterfaceName=HTMLTableSectionElement +tfoot interfaceName=HTMLTableSectionElement +th interfaceName=HTMLTableCellElement +thead interfaceName=HTMLTableSectionElement title tr interfaceName=HTMLTableRowElement -tt JSInterfaceName=HTMLElement -u JSInterfaceName=HTMLElement +tt interfaceName=HTMLElement +u interfaceName=HTMLElement ul interfaceName=HTMLUListElement -var JSInterfaceName=HTMLElement +var interfaceName=HTMLElement #if ENABLE_VIDEO video wrapperOnlyIfMediaIsAvailable=1 #endif -wbr JSInterfaceName=HTMLElement -xmp JSInterfaceName=HTMLPreElement +wbr interfaceName=HTMLElement +xmp interfaceName=HTMLPreElement