Changeset 207381 in webkit


Ignore:
Timestamp:
Oct 15, 2016 2:52:09 PM (7 years ago)
Author:
weinig@apple.com
Message:

MessageEvent's source property should be a (DOMWindow or MessagePort)? rather than a EventTarget?
https://bugs.webkit.org/show_bug.cgi?id=163475

Reviewed by Simon Fraser.

Source/WebCore:

Start fleshing out union support, starting with MessageEvent.

  • Simplify things a bit for now by requiring interface types to use RefPtr<T> as their type when used in sequences and unions. We should revisit this later, and see if we can use Ref<T> where possible, but it causes complications for dictionaries, since they want a Ref<T> uninitialized.
  • bindings/generic/IDLTypes.h:

Switch IDLInterface to use RefPtr<T> as its implementation type.

  • bindings/js/JSDOMConvert.h:

(WebCore::Detail::VariadicConverterBase::convert):

  • Remove isJSDOMWrapperType() optimization. It was not correct, due to not being able to detect window and window shell, and not always an optimization, e.g. in the case of a single interface.
  • Switch from JSC::jsDynamicCast<WrapperType*>() to WrapperType::toWrapped() which can be faster and handles window and window shell correctly.
  • Also fix an issue where we would wrongly assert that one interface had to match.
  • bindings/js/JSDOMWrapper.h:

(WebCore::isJSDOMWrapperType): Deleted.
Remove unused predicate.

  • bindings/scripts/IDLParser.pm:

(parseType):
Add missing support for nullable unions.

  • bindings/scripts/test/JS/JSTestObj.cpp:
  • bindings/scripts/test/TestObj.idl:

Add new tests for unions (both non-null and nullable) in dictionaries.

  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::append):
(WebCore::ContainerNode::prepend):

  • dom/ContainerNode.h:
  • dom/Node.cpp:

(WebCore::nodeSetPreTransformedFromNodeOrStringVector):
(WebCore::Node::convertNodesOrStringsIntoNode):
(WebCore::Node::before):
(WebCore::Node::after):
(WebCore::Node::replaceWith):

  • dom/Node.h:

Add using declaration for NodeOrString and change it to use RefPtr<Node>.

  • bindings/js/JSMessageEventCustom.cpp:

(WebCore::handleInitMessageEvent):

  • dom/MessageEvent.cpp:

(WebCore::MessageEvent::MessageEvent):
(WebCore::MessageEvent::create):
(WebCore::MessageEvent::initMessageEvent):
(WebCore::MessageEvent::source):
(WebCore::isValidSource): Deleted.

  • dom/MessageEvent.h:
  • dom/MessageEvent.idl:
  • page/DOMWindow.cpp:

(WebCore::PostMessageTimer::event):
Change MessageEvent's source to be a std::experimental::variant<RefPtr<DOMWindow>, RefPtr<MessagePort>>.
For now, we only enforce this on setting, and leave the getter a EventTarget?, but that should not be
observable, and will rectified in subsequent patches.

Source/WTF:

  • wtf/Variant.h:

Add missing return statement that was tripping up some compilers.

LayoutTests:

  • fast/dom/message-port-deleted-by-accessor.html:

Switch source parameter to null to avoid accidental type error.

  • fast/events/constructors/message-event-constructor-expected.txt:
  • fast/events/constructors/message-event-constructor.html:

Update test expect a thrown type error, as is now expected, for non-window or MessagePort EventTargets.

Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207373 r207381  
     12016-10-15  Sam Weinig  <sam@webkit.org>
     2
     3        MessageEvent's source property should be a (DOMWindow or MessagePort)? rather than a EventTarget?
     4        https://bugs.webkit.org/show_bug.cgi?id=163475
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/dom/message-port-deleted-by-accessor.html:
     9        Switch source parameter to null to avoid accidental type error.
     10
     11        * fast/events/constructors/message-event-constructor-expected.txt:
     12        * fast/events/constructors/message-event-constructor.html:
     13        Update test expect a thrown type error, as is now expected, for non-window or MessagePort EventTargets.
     14
    1152016-10-15  Antoine Quint  <graouts@apple.com>
    216
  • trunk/LayoutTests/fast/dom/message-port-deleted-by-accessor.html

    r120792 r207381  
    1010    event = document.createEvent("MessageEvent");
    1111
    12     event.initMessageEvent(0, 0, 0, 0, 0, 0, 0, [channel.port1, channel.port2]);
     12    event.initMessageEvent(0, 0, 0, 0, 0, 0, null, [channel.port1, channel.port2]);
    1313
    1414    Array.prototype.__defineSetter__(0, function() {
    15         event.initMessageEvent(0, 0, 0, 0, 0, 0, 0, [ ]);
     15        event.initMessageEvent(0, 0, 0, 0, 0, 0, null, [ ]);
    1616    });
    1717
  • trunk/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt

    r207150 r207381  
    6363PASS new MessageEvent('eventType', { ports: [channel.port1], source: channel.port1 }).source is channel.port1
    6464PASS new MessageEvent('eventType', { source: test_object }).source threw exception TypeError: Type error.
    65 PASS new MessageEvent('eventType', { source: document }).source is null
    66 PASS new MessageEvent('eventType', { source: document.body }).source is null
     65PASS new MessageEvent('eventType', { source: document }).source threw exception TypeError: Type error.
     66PASS new MessageEvent('eventType', { source: document.body }).source threw exception TypeError: Type error.
    6767PASS new MessageEvent('eventType', { source: undefined }).source is null
    6868PASS new MessageEvent('eventType', { source: null }).source is null
  • trunk/LayoutTests/fast/events/constructors/message-event-constructor.html

    r207016 r207381  
    7878// Unacceptable source objects (not a Window or a MessagePort).
    7979shouldThrowErrorName("new MessageEvent('eventType', { source: test_object }).source", "TypeError");
    80 shouldBe("new MessageEvent('eventType', { source: document }).source", "null");
    81 shouldBe("new MessageEvent('eventType', { source: document.body }).source", "null");
     80shouldThrowErrorName("new MessageEvent('eventType', { source: document }).source", "TypeError");
     81shouldThrowErrorName("new MessageEvent('eventType', { source: document.body }).source", "TypeError");
    8282shouldBe("new MessageEvent('eventType', { source: undefined }).source", "null");
    8383shouldBe("new MessageEvent('eventType', { source: null }).source", "null");
  • trunk/Source/WTF/ChangeLog

    r207237 r207381  
     12016-10-15  Sam Weinig  <sam@webkit.org>
     2
     3        MessageEvent's source property should be a (DOMWindow or MessagePort)? rather than a EventTarget?
     4        https://bugs.webkit.org/show_bug.cgi?id=163475
     5
     6        Reviewed by Simon Fraser.
     7
     8        * wtf/Variant.h:
     9        Add missing return statement that was tripping up some compilers.
     10
    1112016-10-12  Ryan Haddad  <ryanhaddad@apple.com>
    212
  • trunk/Source/WTF/wtf/Variant.h

    r204433 r207381  
    19451945    static constexpr typename __multi_visitor_return_type<_Visitor,_Variants...>::__type
    19461946    __visit(_Visitor&,_Variants&& ...){
    1947         __throw_bad_variant_access<typename __multi_visitor_return_type<_Visitor,_Variants...>::__type>("Visiting of empty variant");
     1947        return __throw_bad_variant_access<typename __multi_visitor_return_type<_Visitor,_Variants...>::__type>("Visiting of empty variant");
    19481948    }
    19491949};
  • trunk/Source/WebCore/ChangeLog

    r207380 r207381  
     12016-10-14  Sam Weinig  <sam@webkit.org>
     2
     3        MessageEvent's source property should be a (DOMWindow or MessagePort)? rather than a EventTarget?
     4        https://bugs.webkit.org/show_bug.cgi?id=163475
     5
     6        Reviewed by Simon Fraser.
     7
     8        Start fleshing out union support, starting with MessageEvent.
     9        - Simplify things a bit for now by requiring interface types to use RefPtr<T> as their type when
     10          used in sequences and unions. We should revisit this later, and see if we can use Ref<T> where
     11          possible, but it causes complications for dictionaries, since they want a Ref<T> uninitialized.
     12
     13        * bindings/generic/IDLTypes.h:
     14        Switch IDLInterface to use RefPtr<T> as its implementation type.
     15
     16        * bindings/js/JSDOMConvert.h:
     17        (WebCore::Detail::VariadicConverterBase::convert):
     18        - Remove isJSDOMWrapperType() optimization. It was not correct, due to not being able to detect window
     19          and window shell, and not always an optimization, e.g. in the case of a single interface.
     20        - Switch from JSC::jsDynamicCast<WrapperType*>() to WrapperType::toWrapped() which can be faster and
     21          handles window and window shell correctly.
     22        - Also fix an issue where we would wrongly assert that one interface had to match.
     23
     24        * bindings/js/JSDOMWrapper.h:
     25        (WebCore::isJSDOMWrapperType): Deleted.
     26        Remove unused predicate.
     27
     28        * bindings/scripts/IDLParser.pm:
     29        (parseType):
     30        Add missing support for nullable unions.
     31
     32        * bindings/scripts/test/JS/JSTestObj.cpp:
     33        * bindings/scripts/test/TestObj.idl:
     34        Add new tests for unions (both non-null and nullable) in dictionaries.
     35 
     36        * dom/ContainerNode.cpp:
     37        (WebCore::ContainerNode::append):
     38        (WebCore::ContainerNode::prepend):
     39        * dom/ContainerNode.h:
     40        * dom/Node.cpp:
     41        (WebCore::nodeSetPreTransformedFromNodeOrStringVector):
     42        (WebCore::Node::convertNodesOrStringsIntoNode):
     43        (WebCore::Node::before):
     44        (WebCore::Node::after):
     45        (WebCore::Node::replaceWith):
     46        * dom/Node.h:
     47        Add using declaration for NodeOrString and change it to use RefPtr<Node>.
     48
     49        * bindings/js/JSMessageEventCustom.cpp:
     50        (WebCore::handleInitMessageEvent):
     51        * dom/MessageEvent.cpp:
     52        (WebCore::MessageEvent::MessageEvent):
     53        (WebCore::MessageEvent::create):
     54        (WebCore::MessageEvent::initMessageEvent):
     55        (WebCore::MessageEvent::source):
     56        (WebCore::isValidSource): Deleted.
     57        * dom/MessageEvent.h:
     58        * dom/MessageEvent.idl:
     59        * page/DOMWindow.cpp:
     60        (WebCore::PostMessageTimer::event):
     61        Change MessageEvent's source to be a std::experimental::variant<RefPtr<DOMWindow>, RefPtr<MessagePort>>.
     62        For now, we only enforce this on setting, and leave the getter a EventTarget?, but that should not be
     63        observable, and will rectified in subsequent patches.
     64
    1652016-10-15  Chris Dumez  <cdumez@apple.com>
    266
  • trunk/Source/WebCore/bindings/generic/IDLTypes.h

    r207150 r207381  
    8585struct IDLObject : IDLUnsupportedType { };
    8686
    87 template<typename T> struct IDLInterface : IDLType<std::reference_wrapper<T>> {
     87template<typename T> struct IDLInterface : IDLType<RefPtr<T>> {
    8888    using RawType = T;
    89     using NullableType = T*;
     89    using NullableType = RefPtr<T>;
    9090};
    9191
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r207277 r207381  
    516516        //         (FIXME: Add support for object and step 4.2)
    517517        if (brigand::any<TypeList, IsIDLInterface<brigand::_1>>::value) {
    518             if (isJSDOMWrapperType(value)) {
    519                 Optional<ReturnType> returnValue;
    520                 brigand::for_each<InterfaceTypeList>([&](auto&& type) {
    521                     if (returnValue)
    522                         return;
    523                    
    524                     using ImplementationType = typename WTF::RemoveCVAndReference<decltype(type)>::type::type::RawType;
    525                     using WrapperType = typename JSDOMWrapperConverterTraits<ImplementationType>::WrapperClass;
    526 
    527                     auto* castedValue = JSC::jsDynamicCast<WrapperType*>(value);
    528                     if (!castedValue)
    529                         return;
    530                    
    531                     returnValue = ReturnType(castedValue->wrapped());
    532                 });
    533                 ASSERT(returnValue);
    534 
     518            Optional<ReturnType> returnValue;
     519            brigand::for_each<InterfaceTypeList>([&](auto&& type) {
     520                if (returnValue)
     521                    return;
     522               
     523                using ImplementationType = typename WTF::RemoveCVAndReference<decltype(type)>::type::type::RawType;
     524                using WrapperType = typename JSDOMWrapperConverterTraits<ImplementationType>::WrapperClass;
     525
     526                auto* castedValue = WrapperType::toWrapped(value);
     527                if (!castedValue)
     528                    return;
     529               
     530                returnValue = ReturnType(castedValue);
     531            });
     532
     533            if (returnValue)
    535534                return WTFMove(returnValue.value());
    536             }
    537535        }
    538536       
     
    593591            RETURN_IF_EXCEPTION(scope, Nullopt);
    594592
    595             return result;
     593            return WTFMove(result);
    596594        }
    597595    };
     
    599597    template<typename T>
    600598    struct VariadicConverterBase<IDLInterface<T>> {
    601         using Item = typename IDLInterface<T>::ImplementationType;
     599        using Item = std::reference_wrapper<T>;
    602600
    603601        static Optional<Item> convert(JSC::ExecState& state, JSC::JSValue value)
  • trunk/Source/WebCore/bindings/js/JSDOMWrapper.h

    r207239 r207381  
    8787};
    8888
    89 ALWAYS_INLINE bool isJSDOMWrapperType(JSC::JSValue value)
    90 {
    91     if (UNLIKELY(!value.isCell()))
    92         return false;
    93     return value.asCell()->type() >= JSDOMWrapperType;
    94 }
    95 
    9689template<typename ImplementationClass> struct JSDOMWrapperConverterTraits;
    9790
  • trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp

    r206575 r207381  
    3636#include "JSDOMWindow.h"
    3737#include "JSEventTarget.h"
     38#include "JSMessagePort.h"
    3839#include "JSMessagePortCustom.h"
    3940#include "MessageEvent.h"
     
    113114    const String originArg = valueToUSVString(&state, state.argument(4));
    114115    const String lastEventIdArg = state.argument(5).toString(&state)->value(&state);
    115     DOMWindow* sourceArg = JSDOMWindow::toWrapped(state.argument(6));
     116    auto sourceArg = convert<IDLNullable<IDLUnion<IDLInterface<DOMWindow>, IDLInterface<MessagePort>>>>(state, state.argument(6));
    116117    std::unique_ptr<MessagePortArray> messagePorts;
    117118    std::unique_ptr<ArrayBufferArray> arrayBuffers;
     
    126127
    127128    MessageEvent& event = jsEvent->wrapped();
    128     event.initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg, originArg, lastEventIdArg, sourceArg, WTFMove(messagePorts));
     129    event.initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg, originArg, lastEventIdArg, WTFMove(sourceArg), WTFMove(messagePorts));
    129130    jsEvent->m_data.set(vm, jsEvent, dataArg.jsValue());
    130131    return jsUndefined();
  • trunk/Source/WebCore/bindings/scripts/IDLParser.pm

    r207378 r207381  
    19521952    my $next = $self->nextToken();
    19531953    if ($next->value() eq "(") {
    1954         return $self->parseUnionType();
     1954        my $unionType = $self->parseUnionType();
     1955        $unionType->isNullable($self->parseNull());
     1956        return $unionType;
    19551957    }
    19561958    if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) {
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r207378 r207381  
    567567    } else
    568568        result.nullableStringWithDefault = String();
     569    JSValue nullableUnionMemberValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "nullableUnionMember"));
     570    if (!nullableUnionMemberValue.isUndefined()) {
     571        result.nullableUnionMember = convert<IDLNullable<IDLUnion<IDLLong, IDLInterface<Node>>>>(state, nullableUnionMemberValue);
     572        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     573    } else
     574        result.nullableUnionMember = Nullopt;
    569575    JSValue restrictedDoubleValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "restrictedDouble"));
    570576    if (!restrictedDoubleValue.isUndefined()) {
     
    624630    if (!stringWithoutDefaultValue.isUndefined()) {
    625631        result.stringWithoutDefault = convert<IDLDOMString>(state, stringWithoutDefaultValue);
     632        RETURN_IF_EXCEPTION(throwScope, Nullopt);
     633    }
     634    JSValue unionMemberValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "unionMember"));
     635    if (!unionMemberValue.isUndefined()) {
     636        result.unionMember = convert<IDLUnion<IDLLong, IDLInterface<Node>>>(state, unionMemberValue);
    626637        RETURN_IF_EXCEPTION(throwScope, Nullopt);
    627638    }
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r207378 r207381  
    459459    AnyTypedef anyTypedefValue;
    460460    TestDictionaryThatShouldTolerateNull dictionaryMember;
     461    (long or Node) unionMember;
     462    (long or Node)? nullableUnionMember = null;
    461463};
    462464
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r206956 r207381  
    878878}
    879879
    880 void ContainerNode::append(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     880void ContainerNode::append(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    881881{
    882882    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
     
    887887}
    888888
    889 void ContainerNode::prepend(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     889void ContainerNode::prepend(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    890890{
    891891    RefPtr<Node> node = convertNodesOrStringsIntoNode(WTFMove(nodeOrStringVector), ec);
  • trunk/Source/WebCore/dom/ContainerNode.h

    r207013 r207381  
    101101    WEBCORE_EXPORT Element* lastElementChild() const;
    102102    WEBCORE_EXPORT unsigned childElementCount() const;
    103     void append(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    104     void prepend(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     103    void append(Vector<NodeOrString>&&, ExceptionCode&);
     104    void prepend(Vector<NodeOrString>&&, ExceptionCode&);
    105105
    106106    bool ensurePreInsertionValidity(Node& newChild, Node* refChild, ExceptionCode&);
  • trunk/Source/WebCore/dom/MessageEvent.cpp

    r207016 r207381  
    3030
    3131#include "Blob.h"
    32 #include "DOMWindow.h"
    3332#include "EventNames.h"
    3433#include <runtime/JSCInlines.h>
     
    3837using namespace JSC;
    3938
    40 static inline bool isValidSource(EventTarget* source)
    41 {
    42     return !source || source->toDOMWindow() || source->isMessagePort();
    43 }
    44 
    4539inline MessageEvent::MessageEvent()
    4640    : m_dataType(DataTypeScriptValue)
     
    4842}
    4943
    50 inline MessageEvent::MessageEvent(ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted)
     44inline MessageEvent::MessageEvent(ExecState& state, const AtomicString& type, Init& initializer, IsTrusted isTrusted)
    5145    : Event(type, initializer, isTrusted)
    5246    , m_dataType(DataTypeScriptValue)
     
    5448    , m_origin(initializer.origin)
    5549    , m_lastEventId(initializer.lastEventId)
    56     , m_source(isValidSource(initializer.source.get()) ? initializer.source : nullptr)
     50    , m_source(WTFMove(initializer.source))
    5751    , m_ports(std::make_unique<MessagePortArray>(initializer.ports))
    5852{
    5953}
    6054
    61 inline MessageEvent::MessageEvent(RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, EventTarget* source, std::unique_ptr<MessagePortArray> ports)
     55inline MessageEvent::MessageEvent(RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray> ports)
    6256    : Event(eventNames().messageEvent, false, false)
    6357    , m_dataType(DataTypeSerializedScriptValue)
     
    6559    , m_origin(origin)
    6660    , m_lastEventId(lastEventId)
    67     , m_source(source)
     61    , m_source(WTFMove(source))
    6862    , m_ports(WTFMove(ports))
    6963{
    70     ASSERT(isValidSource(source));
    7164}
    7265
     
    10497}
    10598
    106 Ref<MessageEvent> MessageEvent::create(std::unique_ptr<MessagePortArray> ports, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, EventTarget* source)
    107 {
    108     return adoptRef(*new MessageEvent(WTFMove(data), origin, lastEventId, source, WTFMove(ports)));
     99Ref<MessageEvent> MessageEvent::create(std::unique_ptr<MessagePortArray> ports, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source)
     100{
     101    return adoptRef(*new MessageEvent(WTFMove(data), origin, lastEventId, WTFMove(source), WTFMove(ports)));
    109102}
    110103
     
    134127}
    135128
    136 Ref<MessageEvent> MessageEvent::create(ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted)
     129Ref<MessageEvent> MessageEvent::create(ExecState& state, const AtomicString& type, Init& initializer, IsTrusted isTrusted)
    137130{
    138131    return adoptRef(*new MessageEvent(state, type, initializer, isTrusted));
     
    143136}
    144137
    145 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, std::unique_ptr<MessagePortArray> ports)
     138void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray> ports)
    146139{
    147140    if (dispatched())
     
    156149    m_origin = origin;
    157150    m_lastEventId = lastEventId;
    158     m_source = source;
     151    m_source = WTFMove(source);
    159152    m_ports = WTFMove(ports);
    160153}
    161154
    162 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, std::unique_ptr<MessagePortArray> ports)
     155void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray> ports)
    163156{
    164157    if (dispatched())
     
    171164    m_origin = origin;
    172165    m_lastEventId = lastEventId;
    173     m_source = source;
     166    m_source = WTFMove(source);
    174167    m_ports = WTFMove(ports);
    175168}
    176169   
     170EventTarget* MessageEvent::source() const
     171{
     172    if (!m_source)
     173        return nullptr;
     174
     175    auto visitor = WTF::makeVisitor(
     176        [](const RefPtr<DOMWindow>& window) -> EventTarget* { return const_cast<EventTarget*>(static_cast<const EventTarget*>(window.get())); },
     177        [](const RefPtr<MessagePort>& messagePort) -> EventTarget* { return const_cast<EventTarget*>(static_cast<const EventTarget*>(messagePort.get())); }
     178    );
     179
     180    return std::experimental::visit(visitor, m_source.value());
     181}
     182
    177183RefPtr<SerializedScriptValue> MessageEvent::trySerializeData(ExecState* exec)
    178184{
  • trunk/Source/WebCore/dom/MessageEvent.h

    r207016 r207381  
    2828#pragma once
    2929
     30#include "DOMWindow.h"
    3031#include "Event.h"
    3132#include "MessagePort.h"
    3233#include "SerializedScriptValue.h"
    3334#include <bindings/ScriptValue.h>
     35#include <wtf/Variant.h>
    3436
    3537namespace WebCore {
     
    3739class Blob;
    3840
     41using MessageEventSource = std::experimental::variant<RefPtr<DOMWindow>, RefPtr<MessagePort>>;
     42
    3943class MessageEvent final : public Event {
    4044public:
    41     static Ref<MessageEvent> create(std::unique_ptr<MessagePortArray>, RefPtr<SerializedScriptValue>&&, const String& origin = { }, const String& lastEventId = { }, EventTarget* source = nullptr);
     45    static Ref<MessageEvent> create(std::unique_ptr<MessagePortArray>, RefPtr<SerializedScriptValue>&&, const String& origin = { }, const String& lastEventId = { }, Optional<MessageEventSource>&& source = Nullopt);
    4246    static Ref<MessageEvent> create(const AtomicString& type, RefPtr<SerializedScriptValue>&&, const String& origin, const String& lastEventId);
    4347    static Ref<MessageEvent> create(const String& data, const String& origin = { });
     
    5054        String origin;
    5155        String lastEventId;
    52         RefPtr<EventTarget> source;
     56        Optional<MessageEventSource> source;
    5357        MessagePortArray ports;
    5458    };
    55     static Ref<MessageEvent> create(JSC::ExecState&, const AtomicString& type, const Init&, IsTrusted = IsTrusted::No);
     59    static Ref<MessageEvent> create(JSC::ExecState&, const AtomicString& type, Init&, IsTrusted = IsTrusted::No);
    5660
    5761    virtual ~MessageEvent();
    5862
    59     void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, std::unique_ptr<MessagePortArray>);
    60     void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, std::unique_ptr<MessagePortArray>);
     63    void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const Deprecated::ScriptValue& data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray>);
     64    void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray>);
    6165
    6266    const String& origin() const { return m_origin; }
    6367    const String& lastEventId() const { return m_lastEventId; }
    64     EventTarget* source() const { return m_source.get(); }
     68    EventTarget* source() const;
    6569    MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArray(); }
    6670
     
    8892private:
    8993    MessageEvent();
    90     MessageEvent(JSC::ExecState&, const AtomicString&, const Init&, IsTrusted);
    91     MessageEvent(RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, EventTarget* source, std::unique_ptr<MessagePortArray>);
     94    MessageEvent(JSC::ExecState&, const AtomicString&, Init&, IsTrusted);
     95    MessageEvent(RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId, Optional<MessageEventSource>&& source, std::unique_ptr<MessagePortArray>);
    9296    MessageEvent(const AtomicString& type, RefPtr<SerializedScriptValue>&& data, const String& origin, const String& lastEventId);
    9397    MessageEvent(const String& data, const String& origin);
     
    104108    String m_origin;
    105109    String m_lastEventId;
    106     RefPtr<EventTarget> m_source;
     110    Optional<MessageEventSource> m_source;
    107111    std::unique_ptr<MessagePortArray> m_ports;
    108112};
  • trunk/Source/WebCore/dom/MessageEvent.idl

    r207016 r207381  
    22 * Copyright (C) 2007 Henry Mason <hmason@mac.com>
    33 * Copyright (C) 2011 Google Inc. All rights reserved.
     4 * Copyright (C) 2016 Apple Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3334    readonly attribute USVString origin;
    3435    readonly attribute DOMString lastEventId;
    35     readonly attribute EventTarget? source; // May be a DOMWindow or a MessagePort.
     36    readonly attribute EventTarget? source;
    3637    [CachedAttribute, CustomGetter] readonly attribute any data;
    3738    readonly attribute FrozenArray<MessagePort> ports;
    3839
    3940    [Custom] void initMessageEvent(optional DOMString typeArg, optional boolean canBubbleArg, optional boolean cancelableArg,
    40         optional any dataArg, optional USVString originArg, optional DOMString lastEventIdArg, optional DOMWindow sourceArg,
     41        optional any dataArg, optional USVString originArg, optional DOMString lastEventIdArg, optional (DOMWindow or MessagePort)? sourceArg,
    4142        optional Array messagePorts);
    4243
    4344    [Custom] void webkitInitMessageEvent(optional DOMString typeArg, optional boolean canBubbleArg, optional boolean cancelableArg,
    44         optional any dataArg, optional USVString originArg, optional DOMString lastEventIdArg, optional DOMWindow sourceArg,
     45        optional any dataArg, optional USVString originArg, optional DOMString lastEventIdArg, optional (DOMWindow or MessagePort)? sourceArg,
    4546        optional Array transferables);
    4647};
     
    5051      USVString origin = "";
    5152      DOMString lastEventId = "";
    52       EventTarget? source = null;
     53      (DOMWindow or MessagePort)? source = null;
    5354      sequence<MessagePort> ports = [];
    5455};
  • trunk/Source/WebCore/dom/Node.cpp

    r207010 r207381  
    436436}
    437437
    438 static HashSet<RefPtr<Node>> nodeSetPreTransformedFromNodeOrStringVector(const Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>& vector)
     438static HashSet<RefPtr<Node>> nodeSetPreTransformedFromNodeOrStringVector(const Vector<NodeOrString>& vector)
    439439{
    440440    HashSet<RefPtr<Node>> nodeSet;
    441441
    442442    auto visitor = WTF::makeVisitor(
    443         [&](const std::reference_wrapper<Node>& node) { nodeSet.add(const_cast<Node*>(&node.get())); },
     443        [&](const RefPtr<Node>& node) { nodeSet.add(const_cast<Node*>(node.get())); },
    444444        [](const String&) { }
    445445    );
     
    469469}
    470470
    471 RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     471RefPtr<Node> Node::convertNodesOrStringsIntoNode(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    472472{
    473473    if (nodeOrStringVector.isEmpty())
     
    478478
    479479    auto visitor = WTF::makeVisitor(
    480         [&](std::reference_wrapper<Node>& node) { nodes.uncheckedAppend(node); },
     480        [&](RefPtr<Node>& node) { nodes.uncheckedAppend(*node.get()); },
    481481        [&](String& string) { nodes.uncheckedAppend(Text::create(document(), string)); }
    482482    );
     
    496496}
    497497
    498 void Node::before(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     498void Node::before(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    499499{
    500500    RefPtr<ContainerNode> parent = parentNode();
     
    517517}
    518518
    519 void Node::after(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     519void Node::after(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    520520{
    521521    RefPtr<ContainerNode> parent = parentNode();
     
    533533}
    534534
    535 void Node::replaceWith(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&& nodeOrStringVector, ExceptionCode& ec)
     535void Node::replaceWith(Vector<NodeOrString>&& nodeOrStringVector, ExceptionCode& ec)
    536536{
    537537    RefPtr<ContainerNode> parent = parentNode();
  • trunk/Source/WebCore/dom/Node.h

    r207013 r207381  
    6363
    6464const int nodeStyleChangeShift = 14;
     65
     66using NodeOrString = std::experimental::variant<RefPtr<Node>, String>;
    6567
    6668// SyntheticStyleChange means that we need to go through the entire style change logic even though
     
    203205
    204206    // From the ChildNode - https://dom.spec.whatwg.org/#childnode
    205     void before(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    206     void after(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
    207     void replaceWith(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     207    void before(Vector<NodeOrString>&&, ExceptionCode&);
     208    void after(Vector<NodeOrString>&&, ExceptionCode&);
     209    void replaceWith(Vector<NodeOrString>&&, ExceptionCode&);
    208210    WEBCORE_EXPORT void remove(ExceptionCode&);
    209211
     
    661663    void updateAncestorsForStyleRecalc();
    662664
    663     RefPtr<Node> convertNodesOrStringsIntoNode(Vector<std::experimental::variant<std::reference_wrapper<Node>, String>>&&, ExceptionCode&);
     665    RefPtr<Node> convertNodesOrStringsIntoNode(Vector<NodeOrString>&&, ExceptionCode&);
    664666
    665667private:
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r207040 r207381  
    161161    Ref<MessageEvent> event(ScriptExecutionContext& context)
    162162    {
    163         return MessageEvent::create(MessagePort::entanglePorts(context, WTFMove(m_channels)), WTFMove(m_message), m_origin, { }, m_source.ptr());
     163        return MessageEvent::create(MessagePort::entanglePorts(context, WTFMove(m_channels)), WTFMove(m_message), m_origin, { }, MessageEventSource(RefPtr<DOMWindow>(WTFMove(m_source))));
    164164    }
    165165
Note: See TracChangeset for help on using the changeset viewer.