зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1310967 - Update MessageEvent to the latest spec, r=smaug
This commit is contained in:
Родитель
b9e15ec151
Коммит
1a3cb83d92
|
@ -1081,7 +1081,8 @@ EventSource::DispatchAllMessageEvents()
|
|||
RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
|
||||
|
||||
event->InitMessageEvent(nullptr, message->mEventName, false, false, jsData,
|
||||
mOrigin, message->mLastEventID, nullptr, nullptr);
|
||||
mOrigin, message->mLastEventID, nullptr,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
|
||||
rv = DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr,
|
||||
|
|
|
@ -147,7 +147,8 @@ PostMessageEvent::Run()
|
|||
event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
|
||||
false /*non-bubbling */, false /*cancelable */,
|
||||
messageData, mCallerOrigin,
|
||||
EmptyString(), source, nullptr);
|
||||
EmptyString(), source,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
|
||||
nsTArray<RefPtr<MessagePort>> ports = TakeTransferredPorts();
|
||||
event->SetPorts(Move(ports));
|
||||
|
|
|
@ -2009,7 +2009,7 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
|
|||
|
||||
event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false,
|
||||
jsData, mImpl->mUTF16Origin, EmptyString(), nullptr,
|
||||
nullptr);
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
|
||||
return DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr,
|
||||
|
|
|
@ -417,7 +417,8 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
|
|||
RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
|
||||
|
||||
event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false,
|
||||
jsData, mOrigin, EmptyString(), nullptr, nullptr);
|
||||
jsData, mOrigin, EmptyString(), nullptr,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
|
||||
LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
|
||||
|
|
|
@ -106,7 +106,7 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
|
|||
RootedDictionary<MessageEventInit> init(cx);
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
init.mOrigin.Construct(mOrigin);
|
||||
init.mOrigin = mOrigin;
|
||||
init.mData = value;
|
||||
|
||||
ErrorResult rv;
|
||||
|
|
|
@ -46,7 +46,6 @@ MessageEvent::MessageEvent(EventTarget* aOwner,
|
|||
WidgetEvent* aEvent)
|
||||
: Event(aOwner, aPresContext, aEvent)
|
||||
, mData(JS::UndefinedValue())
|
||||
, mPortsSet(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -120,13 +119,8 @@ MessageEvent::Constructor(EventTarget* aEventTarget,
|
|||
|
||||
mozilla::HoldJSObjects(event.get());
|
||||
|
||||
if (aParam.mOrigin.WasPassed()) {
|
||||
event->mOrigin = aParam.mOrigin.Value();
|
||||
}
|
||||
|
||||
if (aParam.mLastEventId.WasPassed()) {
|
||||
event->mLastEventId = aParam.mLastEventId.Value();
|
||||
}
|
||||
event->mOrigin = aParam.mOrigin;
|
||||
event->mLastEventId = aParam.mLastEventId;
|
||||
|
||||
if (!aParam.mSource.IsNull()) {
|
||||
if (aParam.mSource.Value().IsWindow()) {
|
||||
|
@ -138,10 +132,7 @@ MessageEvent::Constructor(EventTarget* aEventTarget,
|
|||
MOZ_ASSERT(event->mWindowSource || event->mPortSource);
|
||||
}
|
||||
|
||||
if (aParam.mPorts.WasPassed() && !aParam.mPorts.Value().IsNull()) {
|
||||
event->mPorts.AppendElements(aParam.mPorts.Value().Value());
|
||||
event->mPortsSet = true;
|
||||
}
|
||||
event->mPorts.AppendElements(aParam.mPorts);
|
||||
|
||||
return event.forget();
|
||||
}
|
||||
|
@ -153,7 +144,7 @@ MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
|
|||
const nsAString& aOrigin,
|
||||
const nsAString& aLastEventId,
|
||||
const Nullable<WindowProxyOrMessagePort>& aSource,
|
||||
const Nullable<Sequence<OwningNonNull<MessagePort>>>& aPorts)
|
||||
const Sequence<OwningNonNull<MessagePort>>& aPorts)
|
||||
{
|
||||
Event::InitEvent(aType, aCanBubble, aCancelable);
|
||||
mData = aData;
|
||||
|
@ -174,33 +165,21 @@ MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
|
|||
}
|
||||
|
||||
mPorts.Clear();
|
||||
mPortsSet = false;
|
||||
|
||||
if (!aPorts.IsNull()) {
|
||||
mPorts.AppendElements(aPorts.Value());
|
||||
mPortsSet = true;
|
||||
}
|
||||
|
||||
mPorts.AppendElements(aPorts);
|
||||
MessageEventBinding::ClearCachedPortsValue(this);
|
||||
}
|
||||
|
||||
void
|
||||
MessageEvent::GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts)
|
||||
MessageEvent::GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts)
|
||||
{
|
||||
if (!mPortsSet) {
|
||||
aPorts.SetNull();
|
||||
return;
|
||||
}
|
||||
|
||||
aPorts.SetValue(mPorts);
|
||||
aPorts = mPorts;
|
||||
}
|
||||
|
||||
void
|
||||
MessageEvent::SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts)
|
||||
{
|
||||
MOZ_ASSERT(mPorts.IsEmpty() && !mPortsSet);
|
||||
MOZ_ASSERT(mPorts.IsEmpty());
|
||||
mPorts = Move(aPorts);
|
||||
mPortsSet = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void GetLastEventId(nsAString&) const;
|
||||
void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const;
|
||||
|
||||
void GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts);
|
||||
void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
|
||||
|
||||
void SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts);
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
|||
bool aCancelable, JS::Handle<JS::Value> aData,
|
||||
const nsAString& aOrigin, const nsAString& aLastEventId,
|
||||
const Nullable<WindowProxyOrMessagePort>& aSource,
|
||||
const Nullable<Sequence<OwningNonNull<MessagePort>>>& aPorts);
|
||||
const Sequence<OwningNonNull<MessagePort>>& aPorts);
|
||||
|
||||
protected:
|
||||
~MessageEvent();
|
||||
|
@ -88,7 +88,6 @@ private:
|
|||
RefPtr<MessagePort> mPortSource;
|
||||
|
||||
nsTArray<RefPtr<MessagePort>> mPorts;
|
||||
bool mPortsSet;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -17,7 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=848294
|
|||
ok(e, "MessageEvent created");
|
||||
is(e.type, 'message', 'MessageEvent.type is right');
|
||||
|
||||
is(e.data, 'data' in test ? test.data : undefined, 'MessageEvent.data is ok');
|
||||
is(e.data, 'data' in test ? test.data : null, 'MessageEvent.data is ok');
|
||||
is(e.origin, 'origin' in test ? test.origin : '', 'MessageEvent.origin is ok');
|
||||
is(e.lastEventId, 'lastEventId' in test ? test.lastEventId : '', 'MessageEvent.lastEventId is ok');
|
||||
is(e.source, 'source' in test ? test.source : null, 'MessageEvent.source is ok');
|
||||
|
@ -43,7 +43,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=848294
|
|||
{ data: window, source: window },
|
||||
{ data: window, source: channel.port1 },
|
||||
{ data: window, source: channel.port1, ports: [ channel.port1, channel.port2 ] },
|
||||
{ data: null, ports: null },
|
||||
{ data: null, ports: [] },
|
||||
];
|
||||
|
||||
while (tests.length) {
|
||||
|
@ -54,11 +54,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=848294
|
|||
|
||||
e = new MessageEvent('message');
|
||||
e.initMessageEvent('message', true, true,
|
||||
'data' in test ? test.data : undefined,
|
||||
'data' in test ? test.data : null,
|
||||
'origin' in test ? test.origin : '',
|
||||
'lastEventId' in test ? test.lastEventId : '',
|
||||
'source' in test ? test.source : null,
|
||||
'ports' in test ? test.ports : null);
|
||||
'ports' in test ? test.ports : []);
|
||||
testMessageEvent(e, test);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,6 @@ a.initMessageEvent("message", true, false, {}, window.location.href, "", null, [
|
|||
ok(Array.isArray(a.ports), "After InitMessageEvent() we have an array");
|
||||
is(a.ports.length, 1, "Length is 1");
|
||||
|
||||
a.initMessageEvent("message", true, false, {}, window.location.href, "", null, null);
|
||||
is(a.ports, null, "By default MessageEvent.ports is null");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -137,7 +137,8 @@ private:
|
|||
event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
|
||||
false /* non-bubbling */,
|
||||
false /* cancelable */, value, EmptyString(),
|
||||
EmptyString(), nullptr, nullptr);
|
||||
EmptyString(), nullptr,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
event->SetSource(mPort);
|
||||
|
||||
|
|
|
@ -580,7 +580,8 @@ PresentationConnection::DispatchMessageEvent(JS::Handle<JS::Value> aData)
|
|||
messageEvent->InitMessageEvent(nullptr,
|
||||
NS_LITERAL_STRING("message"),
|
||||
false, false, aData, origin,
|
||||
EmptyString(), nullptr, nullptr);
|
||||
EmptyString(), nullptr,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
messageEvent->SetTrusted(true);
|
||||
|
||||
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
||||
|
|
|
@ -41,18 +41,18 @@ interface MessageEvent : Event {
|
|||
* data, origin, source, and lastEventId attributes of this appropriately.
|
||||
*/
|
||||
[Pure, Cached, Frozen]
|
||||
readonly attribute sequence<MessagePort>? ports;
|
||||
readonly attribute sequence<MessagePort> ports;
|
||||
|
||||
void initMessageEvent(DOMString type, boolean bubbles, boolean cancelable,
|
||||
any data, DOMString origin, DOMString lastEventId,
|
||||
(WindowProxy or MessagePort)? source,
|
||||
sequence<MessagePort>? ports);
|
||||
sequence<MessagePort> ports);
|
||||
};
|
||||
|
||||
dictionary MessageEventInit : EventInit {
|
||||
any data;
|
||||
DOMString origin;
|
||||
DOMString lastEventId;
|
||||
any data = null;
|
||||
DOMString origin = "";
|
||||
DOMString lastEventId = "";
|
||||
(Window or MessagePort)? source = null;
|
||||
sequence<MessagePort>? ports;
|
||||
sequence<MessagePort> ports = [];
|
||||
};
|
||||
|
|
|
@ -723,7 +723,7 @@ public:
|
|||
EmptyString(),
|
||||
EmptyString(),
|
||||
nullptr,
|
||||
nullptr);
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetPorts(Move(ports));
|
||||
domEvent = do_QueryObject(event);
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ private:
|
|||
EmptyString(),
|
||||
EmptyString(),
|
||||
nullptr,
|
||||
nullptr);
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
|
||||
|
|
Загрузка…
Ссылка в новой задаче