Skip to content

Commit c93d44c

Browse files
authored
Remove vendored json3 shim and polyfillJSON (#1257)
1 parent ab21b12 commit c93d44c

File tree

16 files changed

+36
-1165
lines changed

16 files changed

+36
-1165
lines changed

index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,10 @@ declare namespace Rollbar {
221221
handler?: any,
222222
shim?: any,
223223
) => void;
224-
export type PolyfillJSONType = (JSON: any) => any;
225224

226225
export interface Components {
227226
telemeter?: TelemeterType;
228227
instrumenter?: InstrumenterType;
229-
polyfillJSON?: PolyfillJSONType;
230228
wrapGlobals?: WrapGlobalsType;
231229
scrub?: ScrubType;
232230
truncation?: TruncationType;

src/browser/core.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function Rollbar(options, client) {
2121
this.options._configuredOptions = options;
2222
const Telemeter = this.components.telemeter;
2323
const Instrumenter = this.components.instrumenter;
24-
const polyfillJSON = this.components.polyfillJSON;
2524
this.wrapGlobals = this.components.wrapGlobals;
2625
this.scrub = this.components.scrub;
2726
const truncation = this.components.truncation;
@@ -80,7 +79,6 @@ function Rollbar(options, client) {
8079
);
8180
this.instrumenter.instrument();
8281
}
83-
_.setupJSON(polyfillJSON);
8482

8583
// Used with rollbar-react for rollbar-react-native compatibility.
8684
this.rollbar = this;

src/browser/rollbar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Rollbar from './core.js';
22
import Telemeter from '../telemetry.js';
33
import Instrumenter from './telemetry.js';
4-
import polyfillJSON from '../utility/polyfillJSON.js';
54
import wrapGlobals from './wrapGlobals.js';
65
import scrub from '../scrub.js';
76
import truncation from '../truncation.js';
@@ -11,7 +10,6 @@ import Recorder from './replay/recorder.js';
1110
Rollbar.setComponents({
1211
telemeter: Telemeter,
1312
instrumenter: Instrumenter,
14-
polyfillJSON: polyfillJSON,
1513
wrapGlobals: wrapGlobals,
1614
scrub: scrub,
1715
truncation: truncation,

src/react-native/rollbar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as transforms from './transforms.js';
1313
import * as sharedTransforms from '../transforms.js';
1414
import * as sharedPredicates from '../predicates.js';
1515
import truncation from '../truncation.js';
16-
import polyfillJSON from '../../vendor/JSON-js/json3.js';
1716

1817
function Rollbar(options, client) {
1918
if (_.isType(options, 'string')) {
@@ -43,7 +42,6 @@ function Rollbar(options, client) {
4342
);
4443
addTransformsToNotifier(this.client.notifier);
4544
addPredicatesToQueue(this.client.queue);
46-
_.setupJSON(polyfillJSON);
4745
}
4846

4947
var _instance = null;

src/server/rollbar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import * as transforms from './transforms.js';
1818
import * as sharedTransforms from '../transforms.js';
1919
import * as sharedPredicates from '../predicates.js';
2020
import truncation from '../truncation.js';
21-
import polyfillJSON from '../../vendor/JSON-js/json3.js';
2221

2322
function Rollbar(options, client) {
2423
if (_.isType(options, 'string')) {
@@ -56,7 +55,6 @@ function Rollbar(options, client) {
5655
addTransformsToNotifier(this.client.notifier);
5756
addPredicatesToQueue(this.client.queue);
5857
this.setupUnhandledCapture();
59-
_.setupJSON(polyfillJSON);
6058
}
6159

6260
function initLocals(localsOptions, logger) {

src/utility.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
import merge from './merge.js';
22

3-
var RollbarJSON = {};
4-
function setupJSON(polyfillJSON) {
5-
if (isFunction(RollbarJSON.stringify) && isFunction(RollbarJSON.parse)) {
6-
return;
7-
}
8-
9-
if (isDefined(JSON)) {
10-
// If polyfill is provided, prefer it over existing non-native shims.
11-
if (polyfillJSON) {
12-
if (isNativeFunction(JSON.stringify)) {
13-
RollbarJSON.stringify = JSON.stringify;
14-
}
15-
if (isNativeFunction(JSON.parse)) {
16-
RollbarJSON.parse = JSON.parse;
17-
}
18-
} else {
19-
// else accept any interface that is present.
20-
if (isFunction(JSON.stringify)) {
21-
RollbarJSON.stringify = JSON.stringify;
22-
}
23-
if (isFunction(JSON.parse)) {
24-
RollbarJSON.parse = JSON.parse;
25-
}
26-
}
27-
}
28-
if (!isFunction(RollbarJSON.stringify) || !isFunction(RollbarJSON.parse)) {
29-
polyfillJSON && polyfillJSON(RollbarJSON);
30-
}
31-
}
32-
333
/*
344
* isType - Given a Javascript value and a string, returns true if the type of the value matches the
355
* given string.
@@ -327,7 +297,7 @@ function formatUrl(u, protocol) {
327297
function stringify(obj, backup) {
328298
var value, error;
329299
try {
330-
value = RollbarJSON.stringify(obj);
300+
value = JSON.stringify(obj);
331301
} catch (jsonError) {
332302
if (backup && isFunction(backup)) {
333303
try {
@@ -375,7 +345,7 @@ function maxByteSize(string) {
375345
function jsonParse(s) {
376346
var value, error;
377347
try {
378-
value = RollbarJSON.parse(s);
348+
value = JSON.parse(s);
379349
} catch (e) {
380350
error = e;
381351
}
@@ -853,10 +823,8 @@ export {
853823
merge,
854824
now,
855825
redact,
856-
RollbarJSON,
857826
sanitizeUrl,
858827
set,
859-
setupJSON,
860828
stringify,
861829
maxByteSize,
862830
typeName,

src/utility/polyfillJSON.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/utility/polyfillJSON.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/api.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
/* globals sinon */
55

66
import API from '../src/api.js';
7-
import * as utility from '../src/utility.js';
8-
utility.setupJSON();
97

108
function TestTransportGenerator() {
119
var TestTransport = function (callbackError, callbackResponse) {

test/apiUtility.test.js

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
/* globals sinon */
55

66
import * as u from '../src/apiUtility.js';
7-
import * as utility from '../src/utility.js';
8-
utility.setupJSON();
97

108
describe('buildPayload', function () {
119
it('should package up the input into a payload', function () {
@@ -18,10 +16,7 @@ describe('buildPayload', function () {
1816
it('should stringify context', function () {
1917
var token = 'abc123';
2018
var context = { a: 1, b: 'other' };
21-
var data = {
22-
context: context,
23-
other: 'stuff',
24-
};
19+
var data = { context: context, other: 'stuff' };
2520
var payload = u.buildPayload(data);
2621

2722
expect(payload.data.context).to.not.eql(context);
@@ -33,10 +28,7 @@ describe('buildPayload', function () {
3328
for (var i = 0; i < 35; i++) {
3429
context[i] = i;
3530
}
36-
var data = {
37-
context: context,
38-
other: 'stuff',
39-
};
31+
var data = { context: context, other: 'stuff' };
4032
var payload = u.buildPayload(data);
4133

4234
expect(payload.data.context).to.not.eql(context);
@@ -48,17 +40,10 @@ describe('getTransportFromOptions', function () {
4840
it('should use defaults with not endpoint', function () {
4941
var options = {
5042
not: 'endpoint',
51-
proxy: {
52-
host: 'whatver.com',
53-
port: 9090,
54-
},
43+
proxy: { host: 'whatver.com', port: 9090 },
5544
timeout: 3000,
5645
};
57-
var defaults = {
58-
hostname: 'api.com',
59-
protocol: 'https:',
60-
path: '/api/1',
61-
};
46+
var defaults = { hostname: 'api.com', protocol: 'https:', path: '/api/1' };
6247
var url = {
6348
parse: function () {
6449
expect(false).to.be.ok();
@@ -75,10 +60,7 @@ describe('getTransportFromOptions', function () {
7560
it('should parse the endpoint if given', function () {
7661
var options = {
7762
endpoint: 'http://whatever.com/api/42',
78-
proxy: {
79-
host: 'nope.com',
80-
port: 9090,
81-
},
63+
proxy: { host: 'nope.com', port: 9090 },
8264
};
8365
var defaults = {
8466
hostname: 'api.com',
@@ -161,11 +143,7 @@ describe('getTransportFromOptions', function () {
161143

162144
describe('transportOptions', function () {
163145
it('should use the given data if no proxy', function () {
164-
var transport = {
165-
hostname: 'a.com',
166-
path: '/api/v1/item/',
167-
port: 5000,
168-
};
146+
var transport = { hostname: 'a.com', path: '/api/v1/item/', port: 5000 };
169147
var method = 'GET';
170148

171149
var o = u.transportOptions(transport, method);
@@ -181,10 +159,7 @@ describe('transportOptions', function () {
181159
hostname: 'a.com',
182160
path: '/api/v1/item/',
183161
port: 5000,
184-
proxy: {
185-
host: 'b.com',
186-
port: 8080,
187-
},
162+
proxy: { host: 'b.com', port: 8080 },
188163
timeout: 3000,
189164
};
190165
var method = 'GET';

0 commit comments

Comments
 (0)