Bug 1371721 - Resolve dispatchMessageAdd promise only when the related message is logged. r=nchevobbe
`timeStamp` was no longer passed with `new-messages` event.
MozReview-Commit-ID: 6yF9B6CSrPs
--- a/devtools/client/webconsole/new-console-output/components/message.js
+++ b/devtools/client/webconsole/new-console-output/components/message.js
@@ -73,17 +73,17 @@ const Message = createClass({
if (this.messageNode) {
if (this.props.scrollToMessage) {
this.messageNode.scrollIntoView();
}
// Event used in tests. Some message types don't pass it in because existing tests
// did not emit for them.
if (this.props.serviceContainer) {
this.props.serviceContainer.emitNewMessage(
- this.messageNode, this.props.messageId);
+ this.messageNode, this.props.messageId, this.props.timeStamp);
}
}
},
onLearnMoreClick: function () {
let {exceptionDocURL} = this.props;
this.props.serviceContainer.openLink(exceptionDocURL);
},
--- a/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
+++ b/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
@@ -70,20 +70,21 @@ NewConsoleOutputWrapper.prototype = {
return;
}
this.jsterm.focus();
});
const serviceContainer = {
attachRefToHud,
- emitNewMessage: (node, messageId) => {
+ emitNewMessage: (node, messageId, timeStamp) => {
this.jsterm.hud.emit("new-messages", new Set([{
node,
messageId,
+ timeStamp,
}]));
},
hudProxy: this.jsterm.hud.proxy,
openLink: url => {
this.jsterm.hud.owner.openLink(url);
},
createElement: nodename => {
return this.document.createElementNS("http://www.w3.org/1999/xhtml", nodename);
@@ -177,39 +178,42 @@ NewConsoleOutputWrapper.prototype = {
{className: "webconsole-output-wrapper"},
filterBar,
childComponent
));
this.body = ReactDOM.render(provider, this.parentNode);
this.jsterm.focus();
},
+
dispatchMessageAdd: function (message, waitForResponse) {
- this.batchedMessagesAdd(message);
// Wait for the message to render to resolve with the DOM node.
// This is just for backwards compatibility with old tests, and should
// be removed once it's not needed anymore.
// Can only wait for response if the action contains a valid message.
+ let promise;
if (waitForResponse) {
- let {timeStamp} = message;
- return new Promise(resolve => {
+ promise = new Promise(resolve => {
let jsterm = this.jsterm;
jsterm.hud.on("new-messages", function onThisMessage(e, messages) {
for (let m of messages) {
- if (m.timeStamp === timeStamp) {
+ if (m.timeStamp === message.timestamp) {
resolve(m.node);
jsterm.hud.off("new-messages", onThisMessage);
return;
}
}
});
});
+ } else {
+ promise = Promise.resolve();
}
- return Promise.resolve();
+ this.batchedMessagesAdd(message);
+ return promise;
},
dispatchMessagesAdd: function (messages) {
store.dispatch(actions.messagesAdd(messages));
},
dispatchMessagesClear: function () {
store.dispatch(actions.messagesClear());