Bug 157706 - Update the list of elements attachShadow is allowed
Summary: Update the list of elements attachShadow is allowed
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
: 157928 (view as bug list)
Depends on: 159767
Blocks: 148695
  Show dependency treegraph
 
Reported: 2016-05-13 22:11 PDT by Ryosuke Niwa
Modified: 2016-07-14 08:29 PDT (History)
7 users (show)

See Also:


Attachments
Patch (28.11 KB, patch)
2016-06-02 01:50 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed GTK/Windows builds (28.84 KB, patch)
2016-06-03 21:26 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another build fix attempt (28.62 KB, patch)
2016-06-03 22:59 PDT, Ryosuke Niwa
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2016-05-13 22:11:16 PDT
The spec has updated the list of element on which attachShadow is allowed.
We should update our implementation accordingly to avoid the future compatibility issues.
Comment 1 Ryosuke Niwa 2016-05-20 02:02:44 PDT
*** Bug 157928 has been marked as a duplicate of this bug. ***
Comment 2 Ryosuke Niwa 2016-06-02 01:50:36 PDT
Created attachment 280320 [details]
Patch
Comment 3 WebKit Commit Bot 2016-06-02 01:52:30 PDT
Attachment 280320 [details] did not pass style-queue:


ERROR: Source/WebCore/dom/Document.cpp:1129:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 10 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Ryosuke Niwa 2016-06-03 21:26:58 PDT
Created attachment 280507 [details]
Fixed GTK/Windows builds
Comment 5 WebKit Commit Bot 2016-06-03 21:29:56 PDT
Attachment 280507 [details] did not pass style-queue:


ERROR: Source/WebCore/dom/Document.cpp:1129:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 11 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 6 Ryosuke Niwa 2016-06-03 22:59:33 PDT
Created attachment 280509 [details]
Another build fix attempt
Comment 7 WebKit Commit Bot 2016-06-03 23:02:04 PDT
Attachment 280509 [details] did not pass style-queue:


ERROR: Source/WebCore/dom/Document.cpp:1129:  Multi line control clauses should use braces.  [whitespace/braces] [4]
Total errors found: 1 in 11 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 Darin Adler 2016-06-04 12:34:57 PDT
Comment on attachment 280509 [details]
Another build fix attempt

View in context: https://bugs.webkit.org/attachment.cgi?id=280509&action=review

Did you change all the headers that you touched to pragma once? Would be nice to do that.

> Source/WebCore/dom/Document.cpp:1124
> +    for (unsigned i = 0; i < localName.length(); i++) {
> +        if (isASCIIUpper(localName[i]))
> +            return CustomElementNameValidationStatus::ContainsUpperCase;
> +        if (localName[i] == '-')
> +            containsHyphen = true;
> +    }

More efficient not to call length() over and over again and index into the string over and over again.

Could use a couple local variables, or alternatively something like the StringView::codeUnits() iterator.

> Source/WebCore/dom/Document.cpp:1138
> +#if ENABLE(MATHML)
> +        || localName == MathMLNames::annotation_xmlTag.localName()
> +#endif

Seems like we might want to check this even if MathML was not turned on.

> Source/WebCore/dom/Element.cpp:1714
> +    static NeverDestroyed<HashSet<AtomicString>> tagNames;
> +    if (tagNames.get().isEmpty()) {
> +        const AtomicString nameList[] = {
> +            articleTag.localName(),
> +            asideTag.localName(),
> +            blockquoteTag.localName(),
> +            bodyTag.localName(),
> +            divTag.localName(),
> +            footerTag.localName(),
> +            h1Tag.localName(),
> +            h2Tag.localName(),
> +            h3Tag.localName(),
> +            h4Tag.localName(),
> +            h5Tag.localName(),
> +            h6Tag.localName(),
> +            headerTag.localName(),
> +            navTag.localName(),
> +            pTag.localName(),
> +            sectionTag.localName(),
> +            spanTag.localName()
> +        };
> +        for (auto& name : nameList)
> +            tagNames.get().add(name);
> +    }

This is not the best idiom, because we end up checking if the set is empty every time.

Also, we don’t want an array of reference counted local names. Instead we want an array of tags, ideally something that can be initialized without any code running.

Something like this:

    static NeverDestroyed<HashSet<AtomicString>> tagNames = [] {
        HashSet<AtomicString> set;
        const HTMLQualifiedName& const tagList[] = {
            articleTag,
            ...
        };
        for (auto& tag : tagList)
            set.add(tag());
        return set;
    };

> Source/WebCore/dom/Element.cpp:1717
> +    if (element.namespaceURI() != xhtmlNamespaceURI)
> +        return false;

I believe it’s more efficient to just check is<HTMLElement>, and I am pretty sure it accomplishes the same thing.

> Source/WebCore/dom/Element.cpp:1719
> +    return tagNames.get().contains(element.localName()) || Document::validateCustomElementName(element.localName()) == CustomElementNameValidationStatus::Valid;

I suggest putting element.localName() into a local variable.
Comment 9 Darin Adler 2016-06-04 12:35:44 PDT
(In reply to comment #8)
>         const HTMLQualifiedName& const tagList[] = {

Actually I think this:

    static const HTMLQualifiedName& const tagList[] = {
Comment 10 Ryosuke Niwa 2016-06-06 21:00:44 PDT
Committed r201739: <http://trac.webkit.org/changeset/201739>
Comment 11 Radar WebKit Bug Importer 2016-06-06 21:10:30 PDT
<rdar://problem/26666315>