Skip to content

Commit 0dba31c

Browse files
committed
[js] Replace usages of goog.json with native JSON object.
Not touching atoms code since that still needs to support IE7. For node, set `goog.json.USE_NATIVE_JSON=true` in case `goog.json` is loaded transitively. Fixes #670
1 parent 48cd3fc commit 0dba31c

14 files changed

+20
-30
lines changed

Diff for: javascript/node/selenium-webdriver/_base.js

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function Context(opt_configureForTesting) {
108108
return true;
109109
},
110110
CLOSURE_NO_DEPS: !isDevMode(),
111+
CLOSURE_UNCOMPILED_DEFINES: {'goog.json.USE_NATIVE_JSON': true},
111112
goog: {}
112113
});
113114
closure.window = closure.top = closure;

Diff for: javascript/webdriver/firefoxdomexecutor.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
goog.provide('webdriver.FirefoxDomExecutor');
1919

2020
goog.require('bot.response');
21-
goog.require('goog.json');
2221
goog.require('goog.userAgent.product');
2322
goog.require('webdriver.Command');
2423
goog.require('webdriver.CommandExecutor');
@@ -117,7 +116,7 @@ webdriver.FirefoxDomExecutor.prototype.execute = function(command, callback) {
117116
command.getName() != webdriver.CommandName.SWITCH_TO_FRAME) {
118117
parameters['id'] = parameters['id']['ELEMENT'];
119118
}
120-
var json = goog.json.serialize({
119+
var json = JSON.stringify({
121120
'name': command.getName(),
122121
'sessionId': parameters['sessionId'],
123122
'parameters': parameters
@@ -156,7 +155,7 @@ webdriver.FirefoxDomExecutor.prototype.onResponse_ = function() {
156155

157156
try {
158157
var response = bot.response.checkResponse(
159-
/** @type {!bot.response.ResponseObject} */ (goog.json.parse(json)));
158+
/** @type {!bot.response.ResponseObject} */ (JSON.parse(json)));
160159
} catch (ex) {
161160
command.callback(ex);
162161
return;

Diff for: javascript/webdriver/http/corsclient.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
goog.provide('webdriver.http.CorsClient');
1919

20-
goog.require('goog.json');
2120
goog.require('webdriver.http.Client');
2221
goog.require('webdriver.http.Response');
2322

@@ -123,7 +122,7 @@ webdriver.http.CorsClient.prototype.send = function(request, callback) {
123122
// optimized away by the compiler, which leaves us where we were before.
124123
xhr.onprogress = xhr.ontimeout = function() {};
125124

126-
xhr.send(goog.json.serialize({
125+
xhr.send(JSON.stringify({
127126
'method': request.method,
128127
'path': request.path,
129128
'data': request.data

Diff for: javascript/webdriver/http/http.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ goog.provide('webdriver.http.Response');
2727

2828
goog.require('bot.ErrorCode');
2929
goog.require('goog.array');
30-
goog.require('goog.json');
3130
goog.require('webdriver.CommandExecutor');
3231
goog.require('webdriver.CommandName');
3332
goog.require('webdriver.logging');
@@ -189,7 +188,7 @@ webdriver.http.Executor.buildPath_ = function(path, parameters) {
189188
*/
190189
webdriver.http.Executor.parseHttpResponse_ = function(httpResponse) {
191190
try {
192-
return /** @type {!bot.response.ResponseObject} */ (goog.json.parse(
191+
return /** @type {!bot.response.ResponseObject} */ (JSON.parse(
193192
httpResponse.body));
194193
} catch (ex) {
195194
// Whoops, looks like the server sent us a malformed response. We'll need
@@ -436,7 +435,7 @@ webdriver.http.Request.prototype.toString = function() {
436435
this.method + ' ' + this.path + ' HTTP/1.1',
437436
webdriver.http.headersToString_(this.headers),
438437
'',
439-
goog.json.serialize(this.data)
438+
JSON.stringify(this.data)
440439
].join('\n');
441440
};
442441

Diff for: javascript/webdriver/http/xhrclient.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
goog.provide('webdriver.http.XhrClient');
2121

22-
goog.require('goog.json');
2322
goog.require('goog.net.XmlHttp');
2423
goog.require('webdriver.http.Client');
2524
goog.require('webdriver.http.Response');
@@ -61,7 +60,7 @@ webdriver.http.XhrClient.prototype.send = function(request, callback) {
6160
xhr.setRequestHeader(header, request.headers[header] + '');
6261
}
6362

64-
xhr.send(goog.json.serialize(request.data));
63+
xhr.send(JSON.stringify(request.data));
6564
} catch (ex) {
6665
callback(ex);
6766
}

Diff for: javascript/webdriver/test/http/corsclient_test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
goog.require('goog.json');
1918
goog.require('goog.testing.MockControl');
2019
goog.require('goog.testing.PropertyReplacer');
2120
goog.require('goog.testing.jsunit');
@@ -68,7 +67,7 @@ function setXdr(opt_value) {
6867

6968
function expectRequest(mockXhr) {
7069
mockXhr.open('POST', URL + '/xdrpc', true);
71-
return mockXhr.send(goog.json.serialize({
70+
return mockXhr.send(JSON.stringify({
7271
'method': REQUEST.method,
7372
'path': REQUEST.path,
7473
'data': REQUEST.data

Diff for: javascript/webdriver/test/http/http_test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
goog.require('bot.ErrorCode');
1919
goog.require('goog.Uri');
20-
goog.require('goog.json');
2120
goog.require('goog.testing.MockControl');
2221
goog.require('goog.testing.jsunit');
2322
goog.require('webdriver.Command');
@@ -62,7 +61,7 @@ function headersToString(headers) {
6261

6362
function expectRequest(method, path, data, headers) {
6463
var description = method + ' ' + path + '\n' + headersToString(headers) +
65-
'\n' + goog.json.serialize(data);
64+
'\n' + JSON.stringify(data);
6665

6766
return mockClient.send(new goog.testing.mockmatchers.ArgumentMatcher(
6867
function(request) {
@@ -230,7 +229,7 @@ function testExecute_returnsParsedJsonResponse() {
230229
'Accept': 'application/json; charset=utf-8'
231230
}).$does(respondsWith(null,
232231
response(200, {'Content-Type': 'application/json'},
233-
goog.json.serialize(responseObj))));
232+
JSON.stringify(responseObj))));
234233
control.$replayAll();
235234

236235
assertSendsSuccessfully(command, function(response) {
@@ -323,7 +322,7 @@ function testExecute_attemptsToParseBodyWhenNoContentTypeSpecified() {
323322
expectRequest('GET', '/session/s123/url', {}, {
324323
'Accept': 'application/json; charset=utf-8'
325324
}).$does(respondsWith(null,
326-
response(200, {}, goog.json.serialize(responseObj))));
325+
response(200, {}, JSON.stringify(responseObj))));
327326
control.$replayAll();
328327

329328
assertSendsSuccessfully(command, function(response) {

Diff for: javascript/webdriver/test/http/xhrclient_test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
goog.require('goog.json');
1918
goog.require('goog.testing.MockControl');
2019
goog.require('goog.testing.PropertyReplacer');
2120
goog.require('goog.testing.jsunit');
@@ -64,7 +63,7 @@ function expectRequest(mockXhr) {
6463
for (var header in REQUEST.headers) {
6564
mockXhr.setRequestHeader(header, REQUEST.headers[header]);
6665
}
67-
return mockXhr.send(goog.json.serialize(REQUEST.data));
66+
return mockXhr.send(JSON.stringify(REQUEST.data));
6867
}
6968

7069
function testXhrClient_whenUnableToSendARequest() {

Diff for: javascript/webdriver/test/locators_test.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
goog.require('goog.json');
1918
goog.require('goog.testing.jsunit');
2019
goog.require('webdriver.By');
2120
goog.require('webdriver.Locator');

Diff for: javascript/webdriver/test/stacktrace_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function testGetStacktraceFromFile() {
7676
}
7777

7878
var stacktrace = webdriver.test.testutil.getStackTrace();
79-
assertFrame(stacktrace[0], 'testutil.js', 51);
79+
assertFrame(stacktrace[0], 'testutil.js', 50);
8080
assertFrame(stacktrace[1], 'stacktrace_test.js', 78);
8181
}
8282

Diff for: javascript/webdriver/test/testing/client_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function tearDown() {
5050

5151
function expectToSendEvent(type, data) {
5252
mockXhr.open('POST', '/testevent', true);
53-
mockXhr.send(goog.json.serialize({
53+
mockXhr.send(JSON.stringify({
5454
'id': '/foo/bar/baz',
5555
'type': type,
5656
'data': data

Diff for: javascript/webdriver/test/testutil.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ goog.provide('webdriver.test.testutil.StubError');
2020

2121
goog.require('goog.array');
2222
goog.require('goog.debug.Error');
23-
goog.require('goog.json');
2423
goog.require('goog.string');
2524
goog.require('goog.testing.recordFunction');
2625
goog.require('webdriver.stacktrace');
@@ -204,7 +203,7 @@ webdriver.test.testutil.callbackPair = function(opt_callback, opt_errback) {
204203

205204
webdriver.test.testutil.assertObjectEquals = function(expected, actual) {
206205
assertObjectEquals(
207-
'Expected: ' + goog.json.serialize(expected) + '\n' +
208-
'Actual: ' + goog.json.serialize(actual),
206+
'Expected: ' + JSON.stringify(expected) + '\n' +
207+
'Actual: ' + JSON.stringify(actual),
209208
expected, actual);
210209
};

Diff for: javascript/webdriver/test/webdriver_test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
goog.require('bot.ErrorCode');
1919
goog.require('goog.Promise');
2020
goog.require('goog.functions');
21-
goog.require('goog.json');
2221
goog.require('goog.testing.PropertyReplacer');
2322
goog.require('goog.testing.MockControl');
2423
goog.require('goog.testing.jsunit');
@@ -139,11 +138,11 @@ function createCommandMatcher(commandName, parameters) {
139138
parameters, actual.getParameters());
140139
assertNull(
141140
'Wrong parameters for "' + commandName + '"' +
142-
'\n Expected: ' + goog.json.serialize(parameters) +
143-
'\n Actual: ' + goog.json.serialize(actual.getParameters()),
141+
'\n Expected: ' + JSON.stringify(parameters) +
142+
'\n Actual: ' + JSON.stringify(actual.getParameters()),
144143
differences);
145144
return true;
146-
}, commandName + '(' + goog.json.serialize(parameters) + ')');
145+
}, commandName + '(' + JSON.stringify(parameters) + ')');
147146
}
148147

149148

Diff for: javascript/webdriver/testing/client.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
goog.provide('webdriver.testing.Client');
1919

20-
goog.require('goog.json');
2120
goog.require('goog.net.XmlHttp');
2221

2322

@@ -166,7 +165,7 @@ webdriver.testing.Client.prototype.sendScreenshotEvent = function(data,
166165
* @private
167166
*/
168167
webdriver.testing.Client.prototype.sendEvent_ = function(type, opt_data) {
169-
var payload = goog.json.serialize({
168+
var payload = JSON.stringify({
170169
'id': this.id_,
171170
'type': type,
172171
'data': opt_data || {}

0 commit comments

Comments
 (0)