Skip to content

Commit 16f5bf6

Browse files
committed
feat(bsontype): move all _bsontypes to non-enumerable properties
1 parent 545900d commit 16f5bf6

10 files changed

+13
-21
lines changed

Diff for: lib/binary.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class Binary {
3030
throw new Error('only String, Buffer, Uint8Array or Array accepted');
3131
}
3232

33-
this._bsontype = 'Binary';
34-
3533
if (buffer instanceof Number) {
3634
this.sub_type = buffer;
3735
this.position = 0;
@@ -375,7 +373,5 @@ Binary.SUBTYPE_MD5 = 5;
375373
**/
376374
Binary.SUBTYPE_USER_DEFINED = 128;
377375

378-
/**
379-
* Expose.
380-
*/
376+
Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
381377
module.exports = Binary;

Diff for: lib/code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class Code {
1212
* @return {Code}
1313
*/
1414
constructor(code, scope) {
15-
this._bsontype = 'Code';
1615
this.code = code;
1716
this.scope = scope;
1817
}
@@ -25,4 +24,5 @@ class Code {
2524
}
2625
}
2726

27+
Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
2828
module.exports = Code;

Diff for: lib/db_ref.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
/**
34
* A class representation of the BSON DBRef type.
45
*/
@@ -19,7 +20,6 @@ class DBRef {
1920
collection = parts.shift();
2021
}
2122

22-
this._bsontype = 'DBRef';
2323
this.collection = collection;
2424
this.oid = oid;
2525
this.db = db;
@@ -44,4 +44,5 @@ class DBRef {
4444
}
4545
}
4646

47+
Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' });
4748
module.exports = DBRef;

Diff for: lib/double.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class Double {
1010
* @return {Double}
1111
*/
1212
constructor(value) {
13-
this._bsontype = 'Double';
1413
this.value = value;
1514
}
1615

@@ -32,4 +31,5 @@ class Double {
3231
}
3332
}
3433

34+
Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
3535
module.exports = Double;

Diff for: lib/int_32.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class Int32 {
1010
* @return {Int32}
1111
*/
1212
constructor(value) {
13-
this._bsontype = 'Int32';
1413
this.value = value;
1514
}
1615

@@ -32,4 +31,5 @@ class Int32 {
3231
}
3332
}
3433

34+
Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
3535
module.exports = Int32;

Diff for: lib/max_key.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ class MaxKey {
88
*
99
* @return {MaxKey} A MaxKey instance
1010
*/
11-
constructor() {
12-
this._bsontype = 'MaxKey';
13-
}
11+
constructor() {}
1412
}
1513

14+
Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
1615
module.exports = MaxKey;

Diff for: lib/min_key.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ class MinKey {
88
*
99
* @return {MinKey} A MinKey instance
1010
*/
11-
constructor() {
12-
this._bsontype = 'MinKey';
13-
}
11+
constructor() {}
1412
}
1513

14+
Object.defineProperty(MinKey.prototype, '_bsontype', { value: 'MinKey' });
1615
module.exports = MinKey;

Diff for: lib/objectid.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class ObjectID {
5353
constructor(id) {
5454
// Duck-typing to support ObjectId from different npm packages
5555
if (id instanceof ObjectID) return id;
56-
this._bsontype = 'ObjectID';
5756

5857
// The most common usecase (blank id, new objectId instance)
5958
if (id == null || typeof id === 'number') {
@@ -381,7 +380,5 @@ ObjectID.prototype.inspect = ObjectID.prototype.toString;
381380
*/
382381
ObjectID.index = ~~(Math.random() * 0xffffff);
383382

384-
/**
385-
* Expose.
386-
*/
383+
Object.defineProperty(ObjectID.prototype, '_bsontype', { value: 'ObjectID' });
387384
module.exports = ObjectID;

Diff for: lib/regexp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class BSONRegExp {
1919
*/
2020
constructor(pattern, options) {
2121
// Execute
22-
this._bsontype = 'BSONRegExp';
2322
this.pattern = pattern || '';
2423
this.options = options ? alphabetize(options) : '';
2524

@@ -41,4 +40,5 @@ class BSONRegExp {
4140
}
4241
}
4342

43+
Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' });
4444
module.exports = BSONRegExp;

Diff for: lib/symbol.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Symbol {
99
* @param {string} value the string representing the symbol.
1010
*/
1111
constructor(value) {
12-
this._bsontype = 'Symbol';
1312
this.value = value;
1413
}
1514

@@ -45,4 +44,5 @@ class Symbol {
4544
}
4645
}
4746

47+
Object.defineProperty(Symbol.prototype, '_bsontype', { value: 'Symbol' });
4848
module.exports = Symbol;

0 commit comments

Comments
 (0)