⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243486 in webkit


Ignore:
Timestamp:
Mar 25, 2019, 10:53:57 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Expected shouldn't assume its contained types are copyable
https://bugs.webkit.org/show_bug.cgi?id=195986

Patch by Alex Christensen <achristensen@webkit.org> on 2019-03-25
Reviewed by JF Bastien.

Source/WebCore:

  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::loadAction):

Source/WTF:

  • wtf/Expected.h:

(std::experimental::fundamentals_v3::expected_detail::constexpr_base::constexpr_base):
(std::experimental::fundamentals_v3::operator==):
(std::experimental::fundamentals_v3::operator!=):

  • wtf/Unexpected.h:

(std::experimental::fundamentals_v3::unexpected::unexpected):

Tools:

  • TestWebKitAPI/Tests/WTF/Expected.cpp:

(TestWebKitAPI::NonCopyable::operator== const):
(TestWebKitAPI::NonCopyable::operator!= const):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r243429 r243486  
     12019-03-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Expected shouldn't assume its contained types are copyable
     4        https://bugs.webkit.org/show_bug.cgi?id=195986
     5
     6        Reviewed by JF Bastien.
     7
     8        * wtf/Expected.h:
     9        (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base):
     10        (std::experimental::fundamentals_v3::operator==):
     11        (std::experimental::fundamentals_v3::operator!=):
     12        * wtf/Unexpected.h:
     13        (std::experimental::fundamentals_v3::unexpected::unexpected):
     14
    1152019-03-24  Keith Miller  <keith_miller@apple.com>
    216
  • trunk/Source/WTF/wtf/Expected.h

    r242778 r243486  
    250250    constexpr constexpr_storage(value_tag_t) : val() { }
    251251    constexpr constexpr_storage(error_tag_t) : err() { }
    252     constexpr constexpr_storage(value_tag_t, const value_type& v) : val(v) { }
    253     constexpr constexpr_storage(error_tag_t, const error_type& e) : err(e) { }
     252    template<typename U = T>
     253    constexpr constexpr_storage(value_tag_t, U&& v) : val(std::forward<U>(v)) { }
     254    template<typename U = E>
     255    constexpr constexpr_storage(error_tag_t, U&& e) : err(std::forward<U>(e)) { }
    254256    ~constexpr_storage() = default;
    255257};
     
    312314    constexpr constexpr_base(value_tag_t tag) : s(tag), has(true) { }
    313315    constexpr constexpr_base(error_tag_t tag) : s(tag), has(false) { }
    314     constexpr constexpr_base(value_tag_t tag, const value_type& val) : s(tag, val), has(true) { }
    315     constexpr constexpr_base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
     316    template<typename U = T>
     317    constexpr constexpr_base(value_tag_t tag, U&& val) : s(tag, std::forward<U>(val)), has(true) { }
     318    template<typename U = E>
     319    constexpr constexpr_base(error_tag_t tag, U&& err) : s(tag, std::forward<U>(err)), has(false) { }
    316320    ~constexpr_base() = default;
    317321};
     
    559563template<class E> constexpr bool operator==(const expected<void, E>& x, const expected<void, E>& y) { return bool(x) == bool(y) && (x ? true : x.error() == y.error()); }
    560564
    561 template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x == expected<T, E>(y); }
    562 template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
    563 template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x != expected<T, E>(y); }
    564 template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
    565 
    566 template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x == expected<T, E>(y); }
    567 template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
    568 template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x != expected<T, E>(y); }
    569 template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
     565template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x ? *x == y : false; }
     566template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return y ? x == *y : false; }
     567template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x ? *x != y : true; }
     568template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return y ? x != *y : true; }
     569
     570template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x ? false : x.error() == y.value(); }
     571template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return y ? false : x.value() == y.error(); }
     572template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x ? true : x.error() != y.value(); }
     573template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return y ? true : x.value() != y.error(); }
    570574
    571575template<typename T, typename E> void swap(expected<T, E>& x, expected<T, E>& y) { x.swap(y); }
  • trunk/Source/WTF/wtf/Unexpected.h

    r225728 r243486  
    5050    public:
    5151        unexpected() = delete;
    52         constexpr explicit unexpected(const E&);
    53         constexpr explicit unexpected(E&&);
     52        template <class U = E>
     53          constexpr explicit unexpected(E&&);
    5454        constexpr const E& value() const &;
    5555        constexpr E& value() &;
     
    7676public:
    7777    unexpected() = delete;
    78     constexpr explicit unexpected(const E& e) : val(e) { }
    79     constexpr explicit unexpected(E&& e) : val(std::forward<E>(e)) { }
     78    template <class U = E>
     79    constexpr explicit unexpected(U&& u) : val(std::forward<U>(u)) { }
    8080    constexpr const E& value() const & { return val; }
    8181    constexpr E& value() & { return val; }
  • trunk/Source/WebCore/ChangeLog

    r243483 r243486  
     12019-03-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Expected shouldn't assume its contained types are copyable
     4        https://bugs.webkit.org/show_bug.cgi?id=195986
     5
     6        Reviewed by JF Bastien.
     7
     8        * contentextensions/ContentExtensionParser.cpp:
     9        (WebCore::ContentExtensions::loadAction):
     10
    1112019-03-20  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp

    r243319 r243486  
    257257
    258258    if (actionType == "block")
    259         return {{ ActionType::BlockLoad }};
     259        return { Action(ActionType::BlockLoad) };
    260260    if (actionType == "ignore-previous-rules")
    261         return {{ ActionType::IgnorePreviousRules }};
     261        return { Action(ActionType::IgnorePreviousRules) };
    262262    if (actionType == "block-cookies")
    263         return {{ ActionType::BlockCookies }};
     263        return { Action(ActionType::BlockCookies) };
    264264    if (actionType == "css-display-none") {
    265265        JSValue selector = actionObject.get(&exec, Identifier::fromString(&exec, "selector"));
     
    275275    }
    276276    if (actionType == "make-https")
    277         return {{ ActionType::MakeHTTPS }};
     277        return { Action(ActionType::MakeHTTPS) };
    278278    if (actionType == "notify") {
    279279        JSValue notification = actionObject.get(&exec, Identifier::fromString(&exec, "notification"));
  • trunk/Tools/ChangeLog

    r243484 r243486  
     12019-03-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Expected shouldn't assume its contained types are copyable
     4        https://bugs.webkit.org/show_bug.cgi?id=195986
     5
     6        Reviewed by JF Bastien.
     7
     8        * TestWebKitAPI/Tests/WTF/Expected.cpp:
     9        (TestWebKitAPI::NonCopyable::operator== const):
     10        (TestWebKitAPI::NonCopyable::operator!= const):
     11        (TestWebKitAPI::TEST):
     12
    1132019-03-25  Tim Horton  <timothy_horton@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp

    r242778 r243486  
    290290}
    291291
     292template<typename T>
     293struct NonCopyable {
     294    NonCopyable(NonCopyable&&) = default;
     295    NonCopyable(const NonCopyable&) = delete;
     296    NonCopyable& operator=(const NonCopyable&) = delete;
     297    NonCopyable& operator=(NonCopyable&&) = default;
     298    bool operator==(const NonCopyable<T>& other) const { return value == other.value; }
     299    bool operator!=(const NonCopyable<T>& other) const { return value != other.value; }
     300    T value;
     301};
     302
    292303TEST(WTF_Expected, comparison)
    293304{
     
    335346    EXPECT_FALSE(makeUnexpected(oops) == Ex(42));
    336347    EXPECT_NE(makeUnexpected(oops), Ex(42));
     348   
     349    NonCopyable<int> a { 5 };
     350    NonCopyable<int> b { 6 };
     351    Unexpected<NonCopyable<double>> c { makeUnexpected(NonCopyable<double> { 5.0 }) };
     352    Expected<NonCopyable<int>, NonCopyable<double>> d { NonCopyable<int> { 5 } };
     353    Expected<NonCopyable<int>, NonCopyable<double>> e { makeUnexpected(NonCopyable<double> { 5.0 }) };
     354
     355    EXPECT_TRUE(a != e);
     356    EXPECT_TRUE(e != a);
     357    EXPECT_FALSE(a == e);
     358    EXPECT_FALSE(e == a);
     359
     360    EXPECT_TRUE(b != e);
     361    EXPECT_TRUE(e != b);
     362    EXPECT_FALSE(b == e);
     363    EXPECT_FALSE(e == b);
     364
     365    EXPECT_TRUE(c != d);
     366    EXPECT_TRUE(d != c);
     367    EXPECT_FALSE(c == d);
     368    EXPECT_FALSE(d == c);
     369
     370    EXPECT_TRUE(c == e);
     371    EXPECT_TRUE(e == c);
     372    EXPECT_FALSE(c != e);
     373    EXPECT_FALSE(e != c);
    337374}
    338375
Note: See TracChangeset for help on using the changeset viewer.