Skip to content

Commit 7cee7e4

Browse files
committed
Revert "support for bigint (#80)"
This reverts commit 5130a71.
1 parent 026a445 commit 7cee7e4

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

index.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var randomBytes = require('randombytes');
1111
// Generate an internal UID to make the regexp pattern harder to guess.
1212
var UID_LENGTH = 16;
1313
var UID = generateUID();
14-
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I|B)-' + UID + '-(\\d+)__@"', 'g');
14+
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I)-' + UID + '-(\\d+)__@"', 'g');
1515

1616
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
1717
var IS_PURE_FUNCTION = /function.*?\(/;
@@ -70,7 +70,6 @@ module.exports = function serialize(obj, options) {
7070
var sets = [];
7171
var undefs = [];
7272
var infinities= [];
73-
var bigInts = [];
7473

7574
// Returns placeholders for functions and regexps (identified by index)
7675
// which are later replaced by their string representation.
@@ -120,10 +119,6 @@ module.exports = function serialize(obj, options) {
120119
return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
121120
}
122121

123-
if (type === 'bigint') {
124-
return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
125-
}
126-
127122
return value;
128123
}
129124

@@ -197,7 +192,7 @@ module.exports = function serialize(obj, options) {
197192
str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
198193
}
199194

200-
if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0) {
195+
if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0 && infinities.length === 0) {
201196
return str;
202197
}
203198

@@ -236,10 +231,6 @@ module.exports = function serialize(obj, options) {
236231
return infinities[valueIndex];
237232
}
238233

239-
if (type === 'B') {
240-
return "BigInt(\"" + bigInts[valueIndex] + "\")";
241-
}
242-
243234
var fn = functions[valueIndex];
244235

245236
return serializeFunc(fn);

test/unit/serialize.js

-18
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,6 @@ describe('serialize( obj )', function () {
414414
});
415415
});
416416

417-
describe('BigInt', function () {
418-
it('should serialize BigInt', function () {
419-
var b = BigInt(9999);
420-
expect(serialize(b)).to.equal('BigInt("9999")');
421-
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("9999")]}');
422-
});
423-
424-
it('should deserialize BigInt', function () {
425-
var d = eval(serialize(BigInt(9999)));
426-
expect(d).to.be.a('BigInt');
427-
expect(d.toString()).to.equal('9999');
428-
});
429-
430-
it('should throw error for invalid bigint', function () {
431-
expect(() => serialize(BigInt('abc'))).to.throw(Error);
432-
});
433-
});
434-
435417
describe('XSS', function () {
436418
it('should encode unsafe HTML chars to Unicode', function () {
437419
expect(serialize('</script>')).to.equal('"\\u003C\\u002Fscript\\u003E"');

0 commit comments

Comments
 (0)