Bug 758448 - Make callback optional for runEmulatorCmd. r=jgriffin
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Fri, 25 May 2012 10:37:21 -0700
changeset 94974 190eab3e5ef0a6b96a63024a4e10e2096efadc9b
parent 94973 4566522a1bfd475316385c053df2721942398f8d
child 94975 c000fd454e7ae39a016f860d9fbf82a70a3c44ea
push id22770
push userryanvm@gmail.com
push dateSat, 26 May 2012 12:07:39 +0000
treeherdermozilla-central@cd62c4b8f500 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs758448
milestone15.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 758448 - Make callback optional for runEmulatorCmd. r=jgriffin
testing/marionette/marionette-actors.js
testing/marionette/marionette-listener.js
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1196,39 +1196,41 @@ MarionetteDriverActor.prototype = {
     this.messageManager.removeMessageListener("Marionette:goUrl", this);
     this.messageManager.removeMessageListener("Marionette:runEmulatorCmd", this);
     this.curBrowser = null;
   },
 
   _emu_cb_id: 0,
   _emu_cbs: null,
   runEmulatorCmd: function runEmulatorCmd(cmd, callback) {
-    if (typeof callback != "function") {
-      throw "Need to provide callback function!";
+    if (callback) {
+      if (!this._emu_cbs) {
+        this._emu_cbs = {};
+      }
+      this._emu_cbs[this._emu_cb_id] = callback;
     }
-    if (!this._emu_cbs) {
-      this._emu_cbs = {};
-    }
-    this._emu_cbs[this._emu_cb_id] = callback;
     this.sendToClient({emulator_cmd: cmd, id: this._emu_cb_id});
     this._emu_cb_id += 1;
   },
 
   emulatorCmdResult: function emulatorCmdResult(message) {
     if (this.context != "chrome") {
       this.sendAsync("emulatorCmdResult", message);
       return;
     }
 
-    if (!this._emu_cbs || !this._emu_cbs[message.id]) {
+    if (!this._emu_cbs) {
       return;
     }
 
     let cb = this._emu_cbs[message.id];
     delete this._emu_cbs[message.id];
+    if (!cb) {
+      return;
+    }
     try {
       cb(message.result);
     }
     catch(e) {
       this.sendError(e.message, e.num, e.stack);
       return;
     }
   },
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -696,31 +696,33 @@ function switchToFrame(msg) {
   sandbox = null;
 }
 
 // emulator callbacks
 let _emu_cb_id = 0;
 let _emu_cbs = {};
 
 function runEmulatorCmd(cmd, callback) {
-  if (typeof callback != "function") {
-    throw "Need to provide callback function!";
+  if (callback) {
+    _emu_cbs[_emu_cb_id] = callback;
   }
-  _emu_cbs[_emu_cb_id] = callback;
   sendAsyncMessage("Marionette:runEmulatorCmd", {emulator_cmd: cmd, id: _emu_cb_id});
   _emu_cb_id += 1;
 }
 
 function emulatorCmdResult(msg) {
   let message = msg.json;
-  if (!sandbox || !_emu_cbs[message.id]) {
+  if (!sandbox) {
     return;
   }
   let cb = _emu_cbs[message.id];
   delete _emu_cbs[message.id];
+  if (!cb) {
+    return;
+  }
   try {
     cb(message.result);
   }
   catch(e) {
     sendError(e.message, e.num, e.stack);
     return;
   }
 }