Bug 1111268 - Fix redefinition of caps in setSessionCapabilities. r=dburns
authorAndreas Tolfsen <ato@mozilla.com>
Sat, 13 Dec 2014 22:22:47 +0000
changeset 220201 dd8d4b26a2a6de63fed42f5667de460888168abf
parent 220200 25af7d428a320ec8287ab56e78ac0ec7c634e221
child 220202 9e734bd31446d47764cf6bd31b450cb9103c6a39
push id10457
push userryanvm@gmail.com
push dateThu, 18 Dec 2014 01:54:25 +0000
treeherderfx-team@0e441ff66c5e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdburns
bugs1111268
milestone37.0a1
Bug 1111268 - Fix redefinition of caps in setSessionCapabilities. r=dburns The variable caps is redefined in the second for loop because it's defined in the function scope using the var declaration statement instead of let for the current scope. This patch also addresses the duplication of the code to copy the current set of capabilities.
testing/marionette/marionette-server.js
--- a/testing/marionette/marionette-server.js
+++ b/testing/marionette/marionette-server.js
@@ -668,37 +668,39 @@ MarionetteServerConnection.prototype = {
     if (appName == "B2G")
       this.sessionCapabilities.b2g = true;
 
     this.sendResponse(this.sessionCapabilities, this.command_id);
   },
 
   /**
    * Update the sessionCapabilities object with the keys that have been
-   * passed in when a new session is created
-   * This part of the WebDriver spec is currently in flux see
+   * passed in when a new session is created.
+   *
+   * This part of the WebDriver spec is currently in flux, see
    * http://lists.w3.org/Archives/Public/public-browser-tools-testing/2014OctDec/0000.html
    *
-   * This is not a public API, only available when a new Session is created
+   * This is not a public API, only available when a new session is
+   * created.
    *
-   * @param Object capabilities holds all the keys for capabilities
-   *
+   * @param Object newCaps key/value dictionary to overwrite
+   *   session's current capabilities
    */
-  setSessionCapabilities: function MDA_setSessionCapabilities (capabilities) {
-    this.command_id = this.getCommandId();
-    var tempCapabilities = {};
-    for (var caps in this.sessionCapabilities) {
-      tempCapabilities[caps] = this.sessionCapabilities[caps];
-    }
+  setSessionCapabilities: function(newCaps) {
+    const copy = (from, to={}) => {
+      for (let key in from) {
+        to[key] = from[key];
+      }
+      return to;
+    };
 
-    for (var caps in capabilities) {
-      tempCapabilities[caps] = capabilities[caps];
-    }
-
-    this.sessionCapabilities = tempCapabilities;
+    // Clone, overwrite, and set.
+    let caps = copy(this.sessionCapabilities);
+    caps = copy(newCaps, caps);
+    this.sessionCapabilities = caps;
   },
 
   /**
    * Log message. Accepts user defined log-level.
    *
    * @param object aRequest
    *        'value' member holds log message
    *        'level' member hold log level