Bug 1304178 - Return a promise from dispatchMessageAdd to support jsterm.execute callback for tests;r=linclark
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 04 Oct 2016 11:32:45 -0700
changeset 316468 8aee9efaa33dbf46887c0d1473ded3c174959e97
parent 316467 6c0108aa1d30d6b3bb48f94768f77d4868da15cc
child 316469 b95cb4a4e4f15ffae0c13ea645d3fa8089324acd
push id30773
push userkwierso@gmail.com
push dateWed, 05 Oct 2016 00:40:39 +0000
treeherdermozilla-central@ea104eeb14cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslinclark
bugs1304178
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1304178 - Return a promise from dispatchMessageAdd to support jsterm.execute callback for tests;r=linclark MozReview-Commit-ID: AeRsjFiyikv
devtools/client/webconsole/jsterm.js
devtools/client/webconsole/new-console-output/components/message-types/console-command.js
devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js
devtools/client/webconsole/new-console-output/components/message.js
devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
--- a/devtools/client/webconsole/jsterm.js
+++ b/devtools/client/webconsole/jsterm.js
@@ -371,18 +371,17 @@ JSTerm.prototype = {
     if (!errorMessage && result && typeof result == "object" &&
         result.type == "undefined" &&
         helperResult && !helperHasRawOutput) {
       callback && callback();
       return;
     }
 
     if (this.hud.NEW_CONSOLE_OUTPUT_ENABLED) {
-      this.hud.newConsoleOutput.dispatchMessageAdd(response);
-      callback && callback();
+      this.hud.newConsoleOutput.dispatchMessageAdd(response, true).then(callback);
       return;
     }
     let msg = new Messages.JavaScriptEvalOutput(response,
                                                 errorMessage, errorDocLink);
     this.hud.output.addMessage(msg);
 
     if (callback) {
       let oldFlushCallback = this.hud._flushCallback;
--- a/devtools/client/webconsole/new-console-output/components/message-types/console-command.js
+++ b/devtools/client/webconsole/new-console-output/components/message-types/console-command.js
@@ -26,20 +26,25 @@ ConsoleCommand.propTypes = {
 function ConsoleCommand(props) {
   const {
     source,
     type,
     level,
     messageText: messageBody,
   } = props.message;
 
+  const {
+    serviceContainer,
+  } = props;
+
   const childProps = {
     source,
     type,
     level,
     topLevelClasses: [],
     messageBody,
     scrollToMessage: props.autoscroll,
+    serviceContainer,
   };
   return Message(childProps);
 }
 
 module.exports = ConsoleCommand;
--- a/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js
+++ b/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js
@@ -16,22 +16,22 @@ const GripMessageBody = createFactory(re
 
 EvaluationResult.displayName = "EvaluationResult";
 
 EvaluationResult.propTypes = {
   message: PropTypes.object.isRequired,
 };
 
 function EvaluationResult(props) {
-  const { message } = props;
+  const { message, serviceContainer } = props;
   const {
     source,
     type,
     level,
-    serviceContainer,
+    id: messageId,
   } = message;
 
   let messageBody;
   if (message.messageText) {
     messageBody = message.messageText;
   } else {
     messageBody = GripMessageBody({grip: message.parameters});
   }
@@ -39,15 +39,16 @@ function EvaluationResult(props) {
   const topLevelClasses = ["cm-s-mozilla"];
 
   const childProps = {
     source,
     type,
     level,
     topLevelClasses,
     messageBody,
+    messageId,
     scrollToMessage: props.autoscroll,
     serviceContainer,
   };
   return Message(childProps);
 }
 
 module.exports = EvaluationResult;
--- a/devtools/client/webconsole/new-console-output/components/message.js
+++ b/devtools/client/webconsole/new-console-output/components/message.js
@@ -46,17 +46,17 @@ const Message = createClass({
   componentDidMount() {
     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.serviceContainer.emitNewMessage(this.messageNode, this.props.messageId);
       }
     }
   },
 
   render() {
     const {
       messageId,
       open,
--- a/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
+++ b/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
@@ -31,19 +31,20 @@ NewConsoleOutputWrapper.prototype = {
   init: function () {
     const attachRefToHud = (id, node) => {
       this.jsterm.hud[id] = node;
     };
 
     let childComponent = ConsoleOutput({
       serviceContainer: {
         attachRefToHud,
-        emitNewMessage: (node) => {
+        emitNewMessage: (node, messageId) => {
           this.jsterm.hud.emit("new-messages", new Set([{
-            node
+            node,
+            messageId,
           }]));
         },
         hudProxyClient: this.jsterm.hud.proxy.client,
         onViewSourceInDebugger: frame => this.toolbox.viewSourceInDebugger.call(
           this.toolbox,
           frame.url,
           frame.line
         ),
@@ -66,24 +67,44 @@ NewConsoleOutputWrapper.prototype = {
       React.DOM.div(
         {className: "webconsole-output-wrapper"},
         filterBar,
         childComponent
     ));
 
     this.body = ReactDOM.render(provider, this.parentNode);
   },
-  dispatchMessageAdd: (message) => {
-    batchedMessageAdd(actions.messageAdd(message));
+  dispatchMessageAdd: function(message, waitForResponse) {
+      let action = actions.messageAdd(message);
+      let messageId = action.message.get("id");
+      batchedMessageAdd(action);
+
+      // 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.
+      if (waitForResponse) {
+        return new Promise(resolve => {
+          let jsterm = this.jsterm;
+          jsterm.hud.on("new-messages", function onThisMessage(e, messages) {
+            for (let m of messages) {
+              if (m.messageId == messageId) {
+                resolve(m.node);
+                jsterm.hud.off("new-messages", onThisMessage);
+                return;
+              }
+            }
+          });
+        });
+      }
   },
-  dispatchMessagesAdd: (messages) => {
+  dispatchMessagesAdd: function(messages) {
     const batchedActions = messages.map(message => actions.messageAdd(message));
     store.dispatch(actions.batchActions(batchedActions));
   },
-  dispatchMessagesClear: () => {
+  dispatchMessagesClear: function() {
     store.dispatch(actions.messagesClear());
   },
 };
 
 function batchedMessageAdd(action) {
   queuedActions.push(action);
   if (!throttledDispatchTimeout) {
     throttledDispatchTimeout = setTimeout(() => {