Skip to content

Commit 9726740

Browse files
committed
Merge pull request #525 from jstewmon/master
global leak protection
2 parents 63c9e10 + abf16c1 commit 9726740

File tree

19 files changed

+41
-1
lines changed

19 files changed

+41
-1
lines changed

lib/mongodb/admin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var Collection = require('./collection').Collection,
1313
* @return {Function} Constructor for Admin type.
1414
*/
1515
function Admin(db) {
16+
if(!(this instanceof Admin)) return new Admin(db);
17+
1618
this.db = db;
1719
};
1820

lib/mongodb/bson/binary.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ var bson = require('./bson');
2020
* @param {Number} [subType] the option binary type.
2121
* @return {Grid}
2222
*/
23-
function Binary(buffer, subType) {
23+
function Binary(buffer, subType) {
24+
if(!(this instanceof Binary)) return new Binary(buffer, subType);
25+
2426
this._bsontype = 'Binary';
2527

2628
if(buffer instanceof Number) {

lib/mongodb/bson/code.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @return {Code}
88
*/
99
function Code(code, scope) {
10+
if(!(this instanceof Code)) return new Code(code, scope);
11+
1012
this._bsontype = 'Code';
1113
this.code = code;
1214
this.scope = scope == null ? {} : scope;

lib/mongodb/bson/db_ref.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @return {DBRef}
99
*/
1010
function DBRef(namespace, oid, db) {
11+
if(!(this instanceof DBRef)) return new DBRef(namespace, oid, db);
12+
1113
this._bsontype = 'DBRef';
1214
this.namespace = namespace;
1315
this.oid = oid;

lib/mongodb/bson/double.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @return {Double}
77
*/
88
function Double(value) {
9+
if(!(this instanceof Double)) return new Double(value);
10+
911
this._bsontype = 'Double';
1012
this.value = value;
1113
}

lib/mongodb/bson/long.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
* @param {Number} high the high (signed) 32 bits of the Long.
4141
*/
4242
function Long(low, high) {
43+
if(!(this instanceof Long)) return new Long(low, high);
44+
4345
this._bsontype = 'Long';
4446
/**
4547
* @type {number}

lib/mongodb/bson/max_key.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @return {MaxKey}
66
*/
77
function MaxKey() {
8+
if(!(this instanceof MaxKey)) return new MaxKey();
9+
810
this._bsontype = 'MaxKey';
911
}
1012

lib/mongodb/bson/min_key.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @return {MinKey}
66
*/
77
function MinKey() {
8+
if(!(this instanceof MinKey)) return new MinKey();
9+
810
this._bsontype = 'MinKey';
911
}
1012

lib/mongodb/bson/objectid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
2525
* @return {Object} instance of ObjectID.
2626
*/
2727
function ObjectID(id) {
28+
if(!(this instanceof ObjectID)) return new ObjectID(id);
29+
2830
this._bsontype = 'ObjectID';
2931

3032
var self = this;

lib/mongodb/bson/symbol.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @return {Symbol}
77
*/
88
function Symbol(value) {
9+
if(!(this instanceof Symbol)) return new Symbol(value);
10+
911
this._bsontype = 'Symbol';
1012
this.value = value;
1113
}

0 commit comments

Comments
 (0)