diff options
Diffstat (limited to 'Source/WebCore/dom/make_names.pl')
-rwxr-xr-x | Source/WebCore/dom/make_names.pl | 407 |
1 files changed, 246 insertions, 161 deletions
diff --git a/Source/WebCore/dom/make_names.pl b/Source/WebCore/dom/make_names.pl index 3bc298325..071f22d35 100755 --- a/Source/WebCore/dom/make_names.pl +++ b/Source/WebCore/dom/make_names.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# Copyright (C) 2005, 2006, 2007, 2009, 2013 Apple Inc. All rights reserved. +# Copyright (C) 2005-2007, 2009, 2013-2014 Apple Inc. All rights reserved. # Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org> # Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) # Copyright (C) 2011 Ericsson AB. All rights reserved. @@ -14,7 +14,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of +# 3. Neither the name of Apple Inc. ("Apple") nor the names of # its contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # @@ -30,6 +30,8 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use strict; +use FindBin; +use lib "$FindBin::Bin/../bindings/scripts"; use StaticString; use Config; @@ -62,19 +64,23 @@ my %extensionAttrs = (); require Config; -my $gccLocation = ""; +my $ccLocation = ""; if ($ENV{CC}) { - $gccLocation = $ENV{CC}; + $ccLocation = $ENV{CC}; } elsif (($Config::Config{"osname"}) =~ /solaris/i) { - $gccLocation = "/usr/sfw/bin/gcc"; + $ccLocation = "/usr/sfw/bin/gcc"; } elsif ($Config::Config{"osname"} eq "darwin" && $ENV{SDKROOT}) { - chomp($gccLocation = `xcrun -find cc -sdk '$ENV{SDKROOT}'`); -} elsif ($Config::Config{"osname"} eq "msys") { - $gccLocation = "gcc"; + chomp($ccLocation = `xcrun -find cc -sdk '$ENV{SDKROOT}'`); } else { - $gccLocation = "/usr/bin/cc"; + $ccLocation = "/usr/bin/cc"; +} + +my $preprocessor = ""; +if ($Config::Config{"osname"} eq "MSWin32") { + $preprocessor = "\"$ccLocation\" /EP"; +} else { + $preprocessor = $ccLocation . " -E -x c++"; } -my $preprocessor = $gccLocation . " -E -x c++"; GetOptions( 'tags=s' => \$tagsFile, @@ -105,7 +111,7 @@ if (length($fontNamesIn)) { open F, ">$header" or die "Unable to open $header for writing."; printLicenseHeader($F); - printHeaderHead($F, "CSS", $familyNamesFileBase, "#include <wtf/text/AtomicString.h>"); + printHeaderHead($F, "CSS", $familyNamesFileBase, "#include <wtf/text/AtomicString.h>", ""); printMacros($F, "extern const WTF::AtomicString", "", \%parameters); print F "#endif\n\n"; @@ -121,7 +127,7 @@ if (length($fontNamesIn)) { print F StaticString::GenerateStrings(\%parameters); - while ( my ($name, $identifier) = each %parameters ) { + for my $name (sort keys %parameters) { print F "DEFINE_GLOBAL(AtomicString, $name)\n"; } @@ -130,7 +136,7 @@ if (length($fontNamesIn)) { print F "\n"; print F StaticString::GenerateStringAsserts(\%parameters); - while ( my ($name, $identifier) = each %parameters ) { + for my $name (sort keys %parameters) { # FIXME: Would like to use static_cast here, but there are differences in const # depending on whether SKIP_STATIC_CONSTRUCTORS_ON_GCC is used, so stick with a # C-style cast for now. @@ -194,9 +200,10 @@ sub defaultTagPropertyHash 'JSInterfaceName' => defaultInterfaceName($_[0]), 'mapToTagName' => '', 'wrapperOnlyIfMediaIsAvailable' => 0, + 'settingsConditional' => 0, 'conditional' => 0, 'runtimeConditional' => 0, - 'generateTypeHelpers' => 0 + 'customTypeHelper' => 0, ); } @@ -211,6 +218,7 @@ sub defaultParametersHash 'attrsNullNamespace' => 0, 'fallbackInterfaceName' => '', 'fallbackJSInterfaceName' => '', + 'customElementInterfaceName' => '', ); } @@ -383,7 +391,7 @@ sub printConstructorSignature { my ($F, $tagName, $constructorName, $constructorTagName) = @_; - print F "static PassRefPtr<$parameters{namespace}Element> ${constructorName}Constructor(const QualifiedName& $constructorTagName, Document& document"; + print F "static Ref<$parameters{namespace}Element> ${constructorName}Constructor(const QualifiedName& $constructorTagName, Document& document"; if ($parameters{namespace} eq "HTML") { print F ", HTMLFormElement*"; print F " formElement" if $enabledTags{$tagName}{constructorNeedsFormElement}; @@ -407,9 +415,8 @@ sub printConstructorInterior # instead of having all the support for this here in this script? if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { print F <<END - Settings* settings = document.settings(); - if (!MediaPlayer::isAvailable() || (settings && !settings->mediaEnabled())) - return 0; + if (!MediaPlayer::isAvailable() || !document.settings().mediaEnabled()) + return $parameters{fallbackInterfaceName}::create($constructorTagName, document); END ; @@ -424,6 +431,15 @@ END ; } + my $settingsConditional = $enabledTags{$tagName}{settingsConditional}; + if ($settingsConditional) { + print F <<END + if (!document.settings().${settingsConditional}()) + return $parameters{fallbackInterfaceName}::create($constructorTagName, document); +END +; + } + # Call the constructor with the right parameters. print F " return ${interfaceName}::create($constructorTagName, document"; print F ", formElement" if $enabledTags{$tagName}{constructorNeedsFormElement}; @@ -527,34 +543,41 @@ sub upperCaseName sub printHeaderHead { - my ($F, $prefix, $nsName, $includes) = @_; + my ($F, $prefix, $namespace, $includes, $definitions) = @_; + + print F<<END +#ifndef ${prefix}_${namespace}Names_h - print F "#ifndef ${prefix}_${nsName}Names_h\n"; - print F "#define ${prefix}_${nsName}Names_h\n\n"; - print F "$includes\n\n"; +#define ${prefix}_${namespace}Names_h - print F "namespace WebCore {\n\n"; - print F "namespace ${nsName}Names {\n\n"; +$includes + +namespace WebCore { + +${definitions}namespace ${namespace}Names { - print F "#ifndef ${prefix}_${nsName}NAMES_HIDE_GLOBALS\n"; +#ifndef ${prefix}_${namespace}_NAMES_HIDE_GLOBALS + +END + ; } sub printCppHead { - my ($F, $prefix, $nsName, $usedNamespace) = @_; + my ($F, $prefix, $namespace, $usedNamespace) = @_; print F "#include \"config.h\"\n\n"; print F "#ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC\n"; - print F "#define ${prefix}_${nsName}NAMES_HIDE_GLOBALS 1\n"; + print F "#define ${prefix}_${namespace}_NAMES_HIDE_GLOBALS 1\n"; print F "#else\n"; print F "#define QNAME_DEFAULT_CONSTRUCTOR 1\n"; print F "#endif\n\n"; - print F "#include \"${nsName}Names.h\"\n\n"; + print F "#include \"${namespace}Names.h\"\n\n"; print F "#include <wtf/StaticConstructors.h>\n"; print F "namespace WebCore {\n\n"; - print F "namespace ${nsName}Names {\n\n"; + print F "namespace ${namespace}Names {\n\n"; print F "using namespace $usedNamespace;\n\n"; } @@ -563,7 +586,7 @@ sub printInit my ($F, $isDefinition) = @_; if ($isDefinition) { - print F "\nvoid init();\n\n"; + print F "\nWEBCORE_EXPORT void init();\n\n"; print F "} }\n\n"; print F "#endif\n\n"; return; @@ -601,10 +624,10 @@ sub printLicenseHeader * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -622,57 +645,51 @@ sub printTypeHelpers my ($F, $namesRef) = @_; my %names = %$namesRef; - for my $name (sort keys %names) { - if (!$parsedTags{$name}{generateTypeHelpers}) { - next; - } - + # Do a first pass to discard classes that map to several tags. + my %classToTags = (); + for my $name (keys %names) { my $class = $parsedTags{$name}{interfaceName}; - my $checkHelper = "is$class"; + push(@{$classToTags{$class}}, $name) if defined $class; + } + + for my $class (sort keys %classToTags) { + my $name = $classToTags{$class}[0]; + next if $parsedTags{$name}{customTypeHelper}; + # Skip classes that map to more than 1 tag. + my $tagCount = scalar @{$classToTags{$class}}; + next if $tagCount > 1; print F <<END +namespace WebCore { class $class; -void $checkHelper(const $class&); // Catch unnecessary runtime check of type known at compile time. -void $checkHelper(const $class*); // Catch unnecessary runtime check of type known at compile time. -END - ; - - if ($parameters{namespace} eq "HTML") { - if ($parsedTags{$name}{wrapperOnlyIfMediaIsAvailable}) { - # We need to check for HTMLUnknownElement if it might have been created by the factory. - print F <<END -inline bool $checkHelper(const HTMLElement& element) { return !element.isHTMLUnknownElement() && element.hasLocalName($parameters{namespace}Names::${name}Tag); } -inline bool $checkHelper(const HTMLElement* element) { ASSERT(element); return $checkHelper(*element); } +} +namespace WTF { +template <typename ArgType> +class TypeCastTraits<const WebCore::$class, ArgType, false /* isBaseType */> { +public: + static bool isOfType(ArgType& node) { return checkTagName(node); } +private: END - ; - } else { - print F <<END -inline bool $checkHelper(const HTMLElement& element) { return element.hasLocalName(HTMLNames::${name}Tag); } -inline bool $checkHelper(const HTMLElement* element) { ASSERT(element); return $checkHelper(*element); } + ; + if ($parameters{namespace} eq "HTML" && ($parsedTags{$name}{wrapperOnlyIfMediaIsAvailable} || $parsedTags{$name}{settingsConditional})) { + print F <<END + static bool checkTagName(const WebCore::HTMLElement& element) { return !element.isHTMLUnknownElement() && element.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); } + static bool checkTagName(const WebCore::Node& node) { return is<WebCore::HTMLElement>(node) && checkTagName(downcast<WebCore::HTMLElement>(node)); } END - ; - } - - print F <<END -inline bool $checkHelper(const Node& node) { return node.isHTMLElement() && $checkHelper(toHTMLElement(node)); } -inline bool $checkHelper(const Node* node) { ASSERT(node); return $checkHelper(*node); } -template <> inline bool isElementOfType<const $class>(const HTMLElement& element) { return $checkHelper(element); } -template <> inline bool isElementOfType<const $class>(const Element& element) { return $checkHelper(element); } + ; + } else { + print F <<END + static bool checkTagName(const WebCore::$parameters{namespace}Element& element) { return element.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); } + static bool checkTagName(const WebCore::Node& node) { return node.hasTagName(WebCore::$parameters{namespace}Names::${name}Tag); } END - ; - - } else { - print F <<END -inline bool $checkHelper(const Element& element) { return element.hasTagName($parameters{namespace}Names::${name}Tag); } -inline bool $checkHelper(const Element* element) { ASSERT(element); return $checkHelper(*element); } -inline bool $checkHelper(const Node& node) { return node.isElementNode() && $checkHelper(toElement(node)); } -inline bool $checkHelper(const Node* node) { ASSERT(node); return node->isElementNode() && $checkHelper(toElement(node)); } -template <> inline bool isElementOfType<const $class>(const Element& element) { return $checkHelper(element); } + ; + } + print F <<END +}; +} END - ; - } - - print F "\n"; + ; + print F "\n"; } } @@ -686,11 +703,9 @@ sub printTypeHelpersHeaderFile print F "#ifndef ".$parameters{namespace}."ElementTypeHelpers_h\n"; print F "#define ".$parameters{namespace}."ElementTypeHelpers_h\n\n"; print F "#include \"".$parameters{namespace}."Names.h\"\n\n"; - print F "namespace WebCore {\n\n"; printTypeHelpers($F, \%allTags); - print F "}\n\n"; print F "#endif\n"; close F; @@ -703,31 +718,32 @@ sub printNamesHeaderFile open F, ">$headerPath"; printLicenseHeader($F); - printHeaderHead($F, "DOM", $parameters{namespace}, "#include \"QualifiedName.h\""); + printHeaderHead($F, "DOM", $parameters{namespace}, '#include "QualifiedName.h"', "class $parameters{namespace}QualifiedName : public QualifiedName { };\n\n"); + + my $lowercaseNamespacePrefix = lc($parameters{namespacePrefix}); - my $lowerNamespace = lc($parameters{namespacePrefix}); print F "// Namespace\n"; - print F "extern const WTF::AtomicString ${lowerNamespace}NamespaceURI;\n\n"; + print F "WEBCORE_EXPORT extern const WTF::AtomicString ${lowercaseNamespacePrefix}NamespaceURI;\n\n"; if (keys %allTags) { print F "// Tags\n"; - printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%allTags); + printMacros($F, "WEBCORE_EXPORT extern const WebCore::$parameters{namespace}QualifiedName", "Tag", \%allTags); } if (keys %allAttrs) { print F "// Attributes\n"; - printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%allAttrs); + printMacros($F, "WEBCORE_EXPORT extern const WebCore::QualifiedName", "Attr", \%allAttrs); } print F "#endif\n\n"; if (keys %allTags) { print F "const unsigned $parameters{namespace}TagsCount = ", scalar(keys %allTags), ";\n"; - print F "const WebCore::QualifiedName* const * get$parameters{namespace}Tags();\n"; + print F "const WebCore::$parameters{namespace}QualifiedName* const* get$parameters{namespace}Tags();\n"; } if (keys %allAttrs) { print F "const unsigned $parameters{namespace}AttrsCount = ", scalar(keys %allAttrs), ";\n"; - print F "const WebCore::QualifiedName* const * get$parameters{namespace}Attrs();\n"; + print F "const WebCore::QualifiedName* const* get$parameters{namespace}Attrs();\n"; } printInit($F, 1); @@ -743,22 +759,22 @@ sub printNamesCppFile printLicenseHeader($F); printCppHead($F, "DOM", $parameters{namespace}, "WebCore"); - my $lowerNamespace = lc($parameters{namespacePrefix}); + my $lowercaseNamespacePrefix = lc($parameters{namespacePrefix}); - print F "DEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI)\n\n"; + print F "WEBCORE_EXPORT DEFINE_GLOBAL(AtomicString, ${lowercaseNamespacePrefix}NamespaceURI)\n\n"; print F StaticString::GenerateStrings(\%allStrings); if (keys %allTags) { print F "// Tags\n"; for my $name (sort keys %allTags) { - print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Tag)\n"; + print F "WEBCORE_EXPORT DEFINE_GLOBAL($parameters{namespace}QualifiedName, ", $name, "Tag)\n"; } - print F "\n\nconst WebCore::QualifiedName* const * get$parameters{namespace}Tags()\n"; - print F "{\n static const WebCore::QualifiedName* const $parameters{namespace}Tags[] = {\n"; + print F "\n\nconst WebCore::$parameters{namespace}QualifiedName* const* get$parameters{namespace}Tags()\n"; + print F "{\n static const WebCore::$parameters{namespace}QualifiedName* const $parameters{namespace}Tags[] = {\n"; for my $name (sort keys %allTags) { - print F " reinterpret_cast<const WebCore::QualifiedName*>(&${name}Tag),\n"; + print F " reinterpret_cast<const WebCore::$parameters{namespace}QualifiedName*>(&${name}Tag),\n"; } print F " };\n"; print F " return $parameters{namespace}Tags;\n"; @@ -768,9 +784,9 @@ sub printNamesCppFile if (keys %allAttrs) { print F "\n// Attributes\n"; for my $name (sort keys %allAttrs) { - print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr)\n"; + print F "WEBCORE_EXPORT DEFINE_GLOBAL(QualifiedName, ", $name, "Attr)\n"; } - print F "\n\nconst WebCore::QualifiedName* const * get$parameters{namespace}Attrs()\n"; + print F "\n\nconst WebCore::QualifiedName* const* get$parameters{namespace}Attrs()\n"; print F "{\n static const WebCore::QualifiedName* const $parameters{namespace}Attrs[] = {\n"; for my $name (sort keys %allAttrs) { print F " reinterpret_cast<const WebCore::QualifiedName*>(&${name}Attr),\n"; @@ -782,19 +798,19 @@ sub printNamesCppFile printInit($F, 0); - print(F " AtomicString ${lowerNamespace}NS(\"$parameters{namespaceURI}\", AtomicString::ConstructFromLiteral);\n\n"); + print(F " AtomicString ${lowercaseNamespacePrefix}NS(\"$parameters{namespaceURI}\", AtomicString::ConstructFromLiteral);\n\n"); print(F " // Namespace\n"); - print(F " new (NotNull, (void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n"); + print(F " new (NotNull, (void*)&${lowercaseNamespacePrefix}NamespaceURI) AtomicString(${lowercaseNamespacePrefix}NS);\n"); print(F "\n"); print F StaticString::GenerateStringAsserts(\%allStrings); if (keys %allTags) { - my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; + my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowercaseNamespacePrefix}NS"; printDefinitions($F, \%allTags, "tags", $tagsNamespace); } if (keys %allAttrs) { - my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS"; + my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowercaseNamespacePrefix}NS"; printDefinitions($F, \%allAttrs, "attributes", $attrsNamespace); } @@ -957,17 +973,42 @@ namespace WebCore { using namespace $parameters{namespace}Names; -typedef PassRefPtr<$parameters{namespace}Element> (*$parameters{namespace}ConstructorFunction)(const QualifiedName&, Document&$formElementArgumentForDeclaration, bool createdByParser); +typedef Ref<$parameters{namespace}Element> (*$parameters{namespace}ConstructorFunction)(const QualifiedName&, Document&$formElementArgumentForDeclaration, bool createdByParser); END ; my %tagConstructorMap = buildConstructorMap(); + my $argumentList; + + if ($parameters{namespace} eq "HTML") { + $argumentList = "name, document, formElement, createdByParser"; + } else { + $argumentList = "name, document, createdByParser"; + } + + my $lowercaseNamespacePrefix = lc($parameters{namespacePrefix}); printConstructors($F, \%tagConstructorMap); print F <<END -static NEVER_INLINE void populate$parameters{namespace}FactoryMap(HashMap<AtomicStringImpl*, $parameters{namespace}ConstructorFunction>& map) + +struct ConstructorFunctionMapEntry { + ConstructorFunctionMapEntry($parameters{namespace}ConstructorFunction function, const QualifiedName& name) + : function(function) + , qualifiedName(&name) + { } + + ConstructorFunctionMapEntry() + : function(nullptr) + , qualifiedName(nullptr) + { } + + $parameters{namespace}ConstructorFunction function; + const QualifiedName* qualifiedName; // Use pointer instead of reference so that emptyValue() in HashMap is cheap to create. +}; + +static NEVER_INLINE void populate$parameters{namespace}FactoryMap(HashMap<AtomicStringImpl*, ConstructorFunctionMapEntry>& map) { struct TableEntry { const QualifiedName& name; @@ -984,45 +1025,54 @@ END }; for (unsigned i = 0; i < WTF_ARRAY_LENGTH(table); ++i) - map.add(table[i].name.localName().impl(), table[i].function); + map.add(table[i].name.localName().impl(), ConstructorFunctionMapEntry(table[i].function, table[i].name)); } -PassRefPtr<$parameters{namespace}Element> $parameters{namespace}ElementFactory::createElement(const QualifiedName& name, Document& document$formElementArgumentForDefinition, bool createdByParser) + +static ConstructorFunctionMapEntry find$parameters{namespace}ElementConstructorFunction(const AtomicString& localName) { -END - ; + static NeverDestroyed<HashMap<AtomicStringImpl*, ConstructorFunctionMapEntry>> map; + if (map.get().isEmpty()) + populate$parameters{namespace}FactoryMap(map); + return map.get().get(localName.impl()); +} - if ($parameters{namespace} ne "HTML" and $parameters{namespace} ne "SVG") { - print F <<END -#if ENABLE(DASHBOARD_SUPPORT) - Settings* settings = document.settings(); - if (settings && settings->usesDashboardBackwardCompatibilityMode()) - return 0; -#endif -END - ; +RefPtr<$parameters{namespace}Element> $parameters{namespace}ElementFactory::createKnownElement(const AtomicString& localName, Document& document$formElementArgumentForDefinition, bool createdByParser) +{ + const ConstructorFunctionMapEntry& entry = find$parameters{namespace}ElementConstructorFunction(localName); + if (LIKELY(entry.function)) { + ASSERT(entry.qualifiedName); + const auto& name = *entry.qualifiedName; + return entry.function($argumentList); } + return nullptr; +} - print F <<END - static NeverDestroyed<HashMap<AtomicStringImpl*, $parameters{namespace}ConstructorFunction>> functions; - if (functions.get().isEmpty()) - populate$parameters{namespace}FactoryMap(functions); - if ($parameters{namespace}ConstructorFunction function = functions.get().get(name.localName().impl())) { -END - ; +RefPtr<$parameters{namespace}Element> $parameters{namespace}ElementFactory::createKnownElement(const QualifiedName& name, Document& document$formElementArgumentForDefinition, bool createdByParser) +{ + const ConstructorFunctionMapEntry& entry = find$parameters{namespace}ElementConstructorFunction(name.localName()); + if (LIKELY(entry.function)) + return entry.function($argumentList); + return nullptr; +} - if ($parameters{namespace} eq "HTML") { - print F " if (RefPtr<$parameters{namespace}Element> element = function(name, document, formElement, createdByParser))\n"; - print F " return element.release();\n"; - } else { - print F " if (RefPtr<$parameters{namespace}Element> element = function(name, document, createdByParser))\n"; - print F " return element.release();\n"; +Ref<$parameters{namespace}Element> $parameters{namespace}ElementFactory::createElement(const AtomicString& localName, Document& document$formElementArgumentForDefinition, bool createdByParser) +{ + const ConstructorFunctionMapEntry& entry = find$parameters{namespace}ElementConstructorFunction(localName); + if (LIKELY(entry.function)) { + ASSERT(entry.qualifiedName); + const auto& name = *entry.qualifiedName; + return entry.function($argumentList); } + return $parameters{fallbackInterfaceName}::create(QualifiedName(nullAtom, localName, ${lowercaseNamespacePrefix}NamespaceURI), document); +} - print F " }\n"; - print F " return $parameters{fallbackInterfaceName}::create(name, document);\n"; - - print F <<END +Ref<$parameters{namespace}Element> $parameters{namespace}ElementFactory::createElement(const QualifiedName& name, Document& document$formElementArgumentForDefinition, bool createdByParser) +{ + const ConstructorFunctionMapEntry& entry = find$parameters{namespace}ElementConstructorFunction(name.localName()); + if (LIKELY(entry.function)) + return entry.function($argumentList); + return $parameters{fallbackInterfaceName}::create(name, document); } } // namespace WebCore @@ -1051,23 +1101,36 @@ sub printFactoryHeaderFile namespace WebCore { - class Document; - class HTMLFormElement; - class QualifiedName; +class Document; +class HTMLFormElement; +class QualifiedName; - class $parameters{namespace}Element; +class $parameters{namespace}Element; - class $parameters{namespace}ElementFactory { - public: +class $parameters{namespace}ElementFactory { +public: END ; -print F " static PassRefPtr<$parameters{namespace}Element> createElement(const QualifiedName&, Document&"; +print F "static RefPtr<$parameters{namespace}Element> createKnownElement(const AtomicString&, Document&"; +print F ", HTMLFormElement* = nullptr" if $parameters{namespace} eq "HTML"; +print F ", bool createdByParser = false);\n"; + +print F "static RefPtr<$parameters{namespace}Element> createKnownElement(const QualifiedName&, Document&"; +print F ", HTMLFormElement* = nullptr" if $parameters{namespace} eq "HTML"; +print F ", bool createdByParser = false);\n"; + +print F "static Ref<$parameters{namespace}Element> createElement(const AtomicString&, Document&"; +print F ", HTMLFormElement* = nullptr" if $parameters{namespace} eq "HTML"; +print F ", bool createdByParser = false);\n"; + +print F "static Ref<$parameters{namespace}Element> createElement(const QualifiedName&, Document&"; print F ", HTMLFormElement* = nullptr" if $parameters{namespace} eq "HTML"; print F ", bool createdByParser = false);\n"; printf F<<END - }; +}; + } #endif // $parameters{namespace}ElementFactory_h @@ -1096,7 +1159,7 @@ sub printWrapperFunctions for my $tagName (sort keys %enabledTags) { # Avoid defining the same wrapper method twice. my $JSInterfaceName = $enabledTags{$tagName}{JSInterfaceName}; - next if defined($tagsSeen{$JSInterfaceName}) || (usesDefaultJSWrapper($tagName) && ($parameters{fallbackJSInterfaceName} eq $parameters{namespace} . "Element")); + next if (defined($tagsSeen{$JSInterfaceName}) || (usesDefaultJSWrapper($tagName) && ($parameters{fallbackJSInterfaceName} eq $parameters{namespace} . "Element"))) && !$enabledTags{$tagName}{settingsConditional}; $tagsSeen{$JSInterfaceName} = 1; my $conditional = $enabledTags{$tagName}{conditional}; @@ -1107,11 +1170,22 @@ sub printWrapperFunctions if ($enabledTags{$tagName}{wrapperOnlyIfMediaIsAvailable}) { print F <<END -static JSDOMWrapper* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +static JSDOMObject* create${JSInterfaceName}Wrapper(JSDOMGlobalObject* globalObject, Ref<$parameters{namespace}Element>&& element) { - if (element->isHTMLUnknownElement()) - return CREATE_DOM_WRAPPER(exec, globalObject, $parameters{namespace}Element, element.get()); - return CREATE_DOM_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get()); + if (element->is$parameters{fallbackInterfaceName}()) + return createWrapper<$parameters{fallbackInterfaceName}>(globalObject, WTFMove(element)); + return createWrapper<${JSInterfaceName}>(globalObject, WTFMove(element)); +} + +END + ; + } elsif ($enabledTags{$tagName}{settingsConditional}) { + print F <<END +static JSDOMObject* create$enabledTags{$tagName}{interfaceName}Wrapper(JSDOMGlobalObject* globalObject, Ref<$parameters{namespace}Element>&& element) +{ + if (element->is$parameters{fallbackInterfaceName}()) + return createWrapper<$parameters{fallbackInterfaceName}>(globalObject, WTFMove(element)); + return createWrapper<${JSInterfaceName}>(globalObject, WTFMove(element)); } END @@ -1119,22 +1193,22 @@ END } elsif ($enabledTags{$tagName}{runtimeConditional}) { my $runtimeConditional = $enabledTags{$tagName}{runtimeConditional}; print F <<END -static JSDOMWrapper* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +static JSDOMObject* create${JSInterfaceName}Wrapper(JSDOMGlobalObject* globalObject, Ref<$parameters{namespace}Element>&& element) { if (!RuntimeEnabledFeatures::sharedFeatures().${runtimeConditional}Enabled()) { - ASSERT(!element || element->is$parameters{fallbackInterfaceName}()); - return CREATE_DOM_WRAPPER(exec, globalObject, $parameters{fallbackJSInterfaceName}, element.get()); + ASSERT(element->is$parameters{fallbackInterfaceName}()); + return createWrapper<$parameters{fallbackJSInterfaceName}>(globalObject, WTFMove(element)); } - return CREATE_DOM_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get()); + return createWrapper<${JSInterfaceName}>(globalObject, WTFMove(element)); } END ; } else { print F <<END -static JSDOMWrapper* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +static JSDOMObject* create${JSInterfaceName}Wrapper(JSDOMGlobalObject* globalObject, Ref<$parameters{namespace}Element>&& element) { - return CREATE_DOM_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get()); + return createWrapper<${JSInterfaceName}>(globalObject, WTFMove(element)); } END @@ -1185,7 +1259,7 @@ namespace WebCore { using namespace $parameters{namespace}Names; -typedef JSDOMWrapper* (*Create$parameters{namespace}ElementWrapperFunction)(ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>); +typedef JSDOMObject* (*Create$parameters{namespace}ElementWrapperFunction)(JSDOMGlobalObject*, Ref<$parameters{namespace}Element>&&); END ; @@ -1215,11 +1289,14 @@ END print F "#if ${conditionalString}\n"; } - my $ucTag = $enabledTags{$tag}{JSInterfaceName}; + my $ucTag; + if ($enabledTags{$tag}{settingsConditional}) { + $ucTag = $enabledTags{$tag}{interfaceName}; + } else { + $ucTag = $enabledTags{$tag}{JSInterfaceName}; + } - # FIXME Remove unnecessary '&' from the following (print) line once we switch to a non-broken Visual Studio compiler. - # https://bugs.webkit.org/show_bug.cgi?id=121235: - print F " { ${tag}Tag, &create${ucTag}Wrapper },\n"; + print F " { ${tag}Tag, create${ucTag}Wrapper },\n"; if ($conditional) { print F "#endif\n"; @@ -1233,14 +1310,26 @@ END map.add(table[i].name.localName().impl(), table[i].function); } -JSDOMWrapper* createJS$parameters{namespace}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element) +JSDOMObject* createJS$parameters{namespace}Wrapper(JSDOMGlobalObject* globalObject, Ref<$parameters{namespace}Element>&& element) { static NeverDestroyed<HashMap<AtomicStringImpl*, Create$parameters{namespace}ElementWrapperFunction>> functions; if (functions.get().isEmpty()) populate$parameters{namespace}WrapperMap(functions); if (auto function = functions.get().get(element->localName().impl())) - return function(exec, globalObject, element); - return CREATE_DOM_WRAPPER(exec, globalObject, $parameters{fallbackJSInterfaceName}, element.get()); + return function(globalObject, WTFMove(element)); +END +; + + if ($parameters{customElementInterfaceName}) { + print F <<END + if (element->isCustomElementUpgradeCandidate()) + return createWrapper<$parameters{customElementInterfaceName}>(globalObject, WTFMove(element)); +END +; + } + + print F <<END + return createWrapper<$parameters{fallbackJSInterfaceName}>(globalObject, WTFMove(element)); } } @@ -1269,17 +1358,13 @@ sub printWrapperFactoryHeaderFile print F <<END #include <wtf/Forward.h> -namespace JSC { - class ExecState; -} - namespace WebCore { - class JSDOMWrapper; + class JSDOMObject; class JSDOMGlobalObject; class $parameters{namespace}Element; - JSDOMWrapper* createJS$parameters{namespace}Wrapper(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>); + JSDOMObject* createJS$parameters{namespace}Wrapper(JSDOMGlobalObject*, Ref<$parameters{namespace}Element>&&); } |