fix(_bsontype): only check bsontype if it is a prototype member. · mongodb/js-bson@dd8a349 · GitHub
Skip to content

Commit dd8a349

Browse files
authored
fix(_bsontype): only check bsontype if it is a prototype member.
1 parent 3142508 commit dd8a349

16 files changed

Lines changed: 233 additions & 65 deletions

lib/bson/binary.js

Lines changed: 5 additions & 2 deletions

lib/bson/code.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
*/
99
var Code = function Code(code, scope) {
1010
if (!(this instanceof Code)) return new Code(code, scope);
11-
this._bsontype = 'Code';
1211
this.code = code;
1312
this.scope = scope;
1413
};
1514

15+
Object.defineProperty(Code.prototype, '_bsontype', {
16+
value: 'Code',
17+
writable: false
18+
});
19+
1620
/**
1721
* @ignore
1822
*/

lib/bson/db_ref.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
function DBRef(namespace, oid, db) {
1111
if (!(this instanceof DBRef)) return new DBRef(namespace, oid, db);
1212

13-
this._bsontype = 'DBRef';
1413
this.namespace = namespace;
1514
this.oid = oid;
1615
this.db = db;
1716
}
1817

18+
Object.defineProperty(DBRef.prototype, '_bsontype', {
19+
value: 'DBRef',
20+
writable: false
21+
});
22+
1923
/**
2024
* @ignore
2125
* @api private

lib/bson/decimal128.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ var lessThan = function(left, right) {
181181
* @return {Double}
182182
*/
183183
var Decimal128 = function(bytes) {
184-
this._bsontype = 'Decimal128';
185184
this.bytes = bytes;
186185
};
187186

187+
Object.defineProperty(Decimal128.prototype, '_bsontype', {
188+
value: 'Decimal128',
189+
writable: false
190+
});
191+
188192
/**
189193
* Create a Decimal128 instance from a string representation
190194
*

lib/bson/double.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
function Double(value) {
99
if (!(this instanceof Double)) return new Double(value);
1010

11-
this._bsontype = 'Double';
1211
this.value = value;
1312
}
1413

14+
Object.defineProperty(Double.prototype, '_bsontype', {
15+
value: 'Double',
16+
writable: false
17+
});
18+
1519
/**
1620
* Access the number value.
1721
*

lib/bson/int_32.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
var Int32 = function(value) {
99
if (!(this instanceof Int32)) return new Int32(value);
1010

11-
this._bsontype = 'Int32';
1211
this.value = value;
1312
};
1413

14+
Object.defineProperty(Int32.prototype, '_bsontype', {
15+
value: 'Int32',
16+
writable: false
17+
});
18+
1519
/**
1620
* Access the number value.
1721
*

lib/bson/long.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
function Long(low, high) {
4444
if (!(this instanceof Long)) return new Long(low, high);
4545

46-
this._bsontype = 'Long';
4746
/**
4847
* @type {number}
4948
* @ignore
@@ -57,6 +56,11 @@ function Long(low, high) {
5756
this.high_ = high | 0; // force into 32 signed bits.
5857
}
5958

59+
Object.defineProperty(Long.prototype, '_bsontype', {
60+
value: 'Long',
61+
writable: false
62+
});
63+
6064
/**
6165
* Return the int value.
6266
*

lib/bson/max_key.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
*/
77
function MaxKey() {
88
if (!(this instanceof MaxKey)) return new MaxKey();
9-
10-
this._bsontype = 'MaxKey';
119
}
1210

11+
Object.defineProperty(MaxKey.prototype, '_bsontype', {
12+
value: 'MaxKey',
13+
writable: false
14+
});
15+
1316
module.exports = MaxKey;
1417
module.exports.MaxKey = MaxKey;

lib/bson/min_key.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
*/
77
function MinKey() {
88
if (!(this instanceof MinKey)) return new MinKey();
9-
10-
this._bsontype = 'MinKey';
119
}
1210

11+
Object.defineProperty(MinKey.prototype, '_bsontype', {
12+
value: 'MinKey',
13+
writable: false
14+
});
15+
1316
module.exports = MinKey;
1417
module.exports.MinKey = MinKey;

lib/bson/objectid.js

Lines changed: 5 additions & 2 deletions

0 commit comments

Comments
 (0)