Skip to content

Commit f1e1575

Browse files
committed
FirefoxDriver.executeScript should not define enumerable properties on script
arguments or return values. Fixes issue 8128
1 parent 92bbf7f commit f1e1575

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

javascript/firefox-driver/js/firefoxDriver.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,21 @@ function injectAndExecuteScript(respond, parameters, isAsync, timer) {
257257
};
258258

259259
var runScript = function() {
260-
// Since Firefox 15 we have to populate __exposedProps__
261-
// when passing objects from chrome to content due to security reasons
262-
if (bot.userAgent.isProductVersion(4)) {
263-
for (var i = 0; i < converted.length; i++) {
264-
if (goog.typeOf(converted[i]) === "object") {
265-
var keys = Object.keys(converted[i]);
266-
for (var key in keys) {
267-
if (converted[i].__exposedProps__ == undefined) {
268-
converted[i].__exposedProps__ = {};
269-
}
270-
converted[i].__exposedProps__[keys[key]] = "rw";
271-
}
272-
}
260+
converted.forEach(function(value) {
261+
if (goog.typeOf(value) === 'object') {
262+
var props = {};
263+
Object.keys(value).forEach(function(key) {
264+
props[key] = 'rw';
265+
});
266+
267+
Object.defineProperty(value, '__exposedProps__', {
268+
enumerable: false,
269+
configurable: false,
270+
writable: false,
271+
value: props
272+
});
273273
}
274-
}
274+
});
275275

276276
unwrappedDoc['__webdriver_evaluate']['args'] = converted;
277277
unwrappedDoc['__webdriver_evaluate']['async'] = isAsync;

javascript/firefox-driver/js/moz.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fxdriver.moz.unwrap = function(thing) {
109109
}
110110

111111
if (thing['wrappedJSObject']) {
112-
thing.wrappedJSObject.__fxdriver_unwrapped = true;
112+
fxdriver.moz.markUnwrapped_(thing.wrappedJSObject);
113113
return thing.wrappedJSObject;
114114
}
115115

@@ -119,7 +119,7 @@ fxdriver.moz.unwrap = function(thing) {
119119
if (isWrapper) {
120120
var unwrapped = XPCNativeWrapper.unwrap(thing);
121121
var toReturn = !!unwrapped ? unwrapped : thing;
122-
toReturn.__fxdriver_unwrapped = true;
122+
fxdriver.moz.markUnwrapped_(toReturn);
123123
return toReturn;
124124
}
125125
} catch (e) {
@@ -130,6 +130,22 @@ fxdriver.moz.unwrap = function(thing) {
130130
return thing;
131131
};
132132

133+
134+
/**
135+
* Defines a property on the given object to signal it has been unwrapped.
136+
* @param {!Object} thing The object to mark.
137+
* @private
138+
*/
139+
fxdriver.moz.markUnwrapped_ = function(thing) {
140+
Object.defineProperty(thing, '__fxdriver_unwrapped', {
141+
enumerable: false,
142+
configurable: false,
143+
writable: false,
144+
value: true
145+
});
146+
};
147+
148+
133149
/**
134150
* For Firefox 4, some objects (like the Window) are wrapped to make them safe
135151
* to access from privileged code but this hides fields we need, like the

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
* Promise rejections are now always coerced to Error-like objects (an object
44
with a string `message` property). We do not guarantee `instanceof Error`
55
since the rejection value may come from another context.
6+
* FIXED: 8128: When the FirefoxDriver marshals an object to the page for
7+
`executeScript`, it defines additional properties (required by the driver's
8+
implementation). These properties will no longer be enumerable and should
9+
be omitted (i.e. they won't show up in JSON.stringify output).
610

711
## v2.44.0
812

javascript/node/selenium-webdriver/test/execute_script_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ test.suite(function(env) {
235235
assert(result[0].color).equalTo('red');
236236
});
237237
});
238+
239+
test.it('does not modify object literal parameters', function() {
240+
var input = {color: 'red'};
241+
execute('return arguments[0];', input).then(verifyJson(input));
242+
});
238243
});
239244
});
240245

0 commit comments

Comments
 (0)