зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638248 - EventSource lastEventId is not consistent with spec. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D75537
This commit is contained in:
Родитель
bb16091e78
Коммит
15449ab52b
|
@ -248,7 +248,12 @@ class EventSourceImpl final : public nsIObserver,
|
|||
|
||||
struct Message {
|
||||
nsString mEventName;
|
||||
nsString mLastEventID;
|
||||
// We need to be able to distinguish between different states of id field:
|
||||
// 1) is not given at all
|
||||
// 2) is given but is empty
|
||||
// 3) is given and has a value
|
||||
// We can't check for the 1st state with a simple nsString.
|
||||
Maybe<nsString> mLastEventID;
|
||||
nsString mData;
|
||||
};
|
||||
|
||||
|
@ -1373,12 +1378,6 @@ nsresult EventSourceImpl::DispatchCurrentMessageEvent() {
|
|||
message->mEventName.AssignLiteral("message");
|
||||
}
|
||||
|
||||
if (message->mLastEventID.IsEmpty() && !mLastEventID.IsEmpty()) {
|
||||
message->mLastEventID.Assign(mLastEventID);
|
||||
}
|
||||
|
||||
mServiceNotifier->EventReceived(message->mEventName, message->mLastEventID,
|
||||
message->mData, mReconnectionTime, PR_Now());
|
||||
mMessagesToDispatch.Push(message.release());
|
||||
|
||||
if (!mGoingToDispatchAllMessages) {
|
||||
|
@ -1418,6 +1417,19 @@ void EventSourceImpl::DispatchAllMessageEvents() {
|
|||
while (mMessagesToDispatch.GetSize() > 0) {
|
||||
UniquePtr<Message> message(
|
||||
static_cast<Message*>(mMessagesToDispatch.PopFront()));
|
||||
|
||||
if (message->mLastEventID.isSome()) {
|
||||
mLastEventID.Assign(message->mLastEventID.value());
|
||||
}
|
||||
|
||||
if (message->mLastEventID.isNothing() && !mLastEventID.IsEmpty()) {
|
||||
message->mLastEventID = Some(mLastEventID);
|
||||
}
|
||||
|
||||
mServiceNotifier->EventReceived(message->mEventName, mLastEventID,
|
||||
message->mData, mReconnectionTime,
|
||||
PR_Now());
|
||||
|
||||
// Now we can turn our string into a jsval
|
||||
JS::Rooted<JS::Value> jsData(cx);
|
||||
{
|
||||
|
@ -1436,9 +1448,8 @@ void EventSourceImpl::DispatchAllMessageEvents() {
|
|||
new MessageEvent(mEventSource, nullptr, nullptr);
|
||||
|
||||
event->InitMessageEvent(nullptr, message->mEventName, CanBubble::eNo,
|
||||
Cancelable::eNo, jsData, mOrigin,
|
||||
message->mLastEventID, nullptr,
|
||||
Sequence<OwningNonNull<MessagePort>>());
|
||||
Cancelable::eNo, jsData, mOrigin, mLastEventID,
|
||||
nullptr, Sequence<OwningNonNull<MessagePort>>());
|
||||
event->SetTrusted(true);
|
||||
|
||||
IgnoredErrorResult err;
|
||||
|
@ -1448,7 +1459,6 @@ void EventSourceImpl::DispatchAllMessageEvents() {
|
|||
return;
|
||||
}
|
||||
|
||||
mLastEventID.Assign(message->mLastEventID);
|
||||
if (IsClosed() || IsFrozen()) {
|
||||
return;
|
||||
}
|
||||
|
@ -1495,7 +1505,7 @@ nsresult EventSourceImpl::SetFieldAndClear() {
|
|||
|
||||
case char16_t('i'):
|
||||
if (mLastFieldName.EqualsLiteral("id")) {
|
||||
mCurrentMessage->mLastEventID.Assign(mLastFieldValue);
|
||||
mCurrentMessage->mLastEventID = Some(mLastFieldValue);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче