Bug 132348

Summary: NeverDestroyed objects should be constructable through std::initializer_list
Product: WebKit Reporter: Zan Dobersek <zan>
Component: Web Template FrameworkAssignee: Zan Dobersek <zan>
Status: NEW ---    
Severity: Normal CC: andersca, darin, jer.noble
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 132345    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch darin: review-

Description Zan Dobersek 2014-04-29 12:28:29 PDT
NeverDestroyed objects should be constructable through std::initializer_list
Comment 1 Zan Dobersek 2014-04-29 12:35:57 PDT
Created attachment 230401 [details]
Patch
Comment 2 Darin Adler 2014-04-29 15:08:32 PDT
Comment on attachment 230401 [details]
Patch

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

> Source/WTF/wtf/NeverDestroyed.h:57
> +    template<typename U>
> +    NeverDestroyed(std::initializer_list<U> list)

This header needs to include <initializer_list>.
Comment 3 Darin Adler 2014-04-29 16:02:46 PDT
Comment on attachment 230401 [details]
Patch

Need the include.
Comment 4 Zan Dobersek 2014-04-29 23:45:06 PDT
Created attachment 230463 [details]
Patch

Still relies on the patch in bug #132345.
Comment 5 Darin Adler 2014-04-30 09:20:27 PDT
Comment on attachment 230463 [details]
Patch

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

> Source/WebCore/editing/EditingStyle.cpp:754
> +    static NeverDestroyed<Vector<std::unique_ptr<HTMLElementEquivalent>>> equivalents = {
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyFontWeight, CSSValueBold, HTMLNames::bTag),
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyFontWeight, CSSValueBold, HTMLNames::strongTag),
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyVerticalAlign, CSSValueSub, HTMLNames::subTag),
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyVerticalAlign, CSSValueSuper, HTMLNames::supTag),
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyFontStyle, CSSValueItalic, HTMLNames::iTag),
> +        std::make_unique<HTMLElementEquivalent>(CSSPropertyFontStyle, CSSValueItalic, HTMLNames::emTag),
> +        std::unique_ptr<HTMLElementEquivalent>(std::make_unique<HTMLTextDecorationEquivalent>(CSSValueUnderline, HTMLNames::uTag)),
> +        std::unique_ptr<HTMLElementEquivalent>(std::make_unique<HTMLTextDecorationEquivalent>(CSSValueLineThrough, HTMLNames::sTag)),
> +        std::unique_ptr<HTMLElementEquivalent>(std::make_unique<HTMLTextDecorationEquivalent>(CSSValueLineThrough, HTMLNames::strikeTag)),
> +    };

Anders has suggested that we not make initializer lists support move semantics--I think he’s right and so we should not make this change here.

The explicit cast to a different type of unique_ptr is also quite ugly.

Maybe there’s some other improvement we can make here, but we shouldn’t do exactly this.

> Source/WebCore/editing/EditingStyle.cpp:787
> +        std::make_unique<HTMLAttributeEquivalent>(CSSPropertyColor, HTMLNames::fontTag, HTMLNames::colorAttr),
> +        std::make_unique<HTMLAttributeEquivalent>(CSSPropertyFontFamily, HTMLNames::fontTag, HTMLNames::faceAttr),
> +        std::unique_ptr<HTMLAttributeEquivalent>(std::make_unique<HTMLFontSizeEquivalent>()),
> +        std::unique_ptr<HTMLAttributeEquivalent>(std::make_unique<HTMLAttributeEquivalent>(CSSPropertyDirection, HTMLNames::dirAttr)),
> +        std::unique_ptr<HTMLAttributeEquivalent>(std::make_unique<HTMLAttributeEquivalent>(CSSPropertyUnicodeBidi, HTMLNames::dirAttr)),

Ditto.
Comment 6 Darin Adler 2017-07-21 20:23:35 PDT
*** Bug 157452 has been marked as a duplicate of this bug. ***