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.
--- 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