Skip to content

Commit

Permalink
fix(bson): fix custom inspect property
Browse files Browse the repository at this point in the history
The currently used custom inspect way is deprecated and was removed
in Node.js 11.0.0-pre. This should fix that.
  • Loading branch information
BridgeAR authored and mbroadst committed Jun 6, 2018
1 parent 26b05b5 commit 080323b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/bson/objectid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Custom inspect property name / symbol.
var inspect = 'inspect';

/**
* Machine id.
*
Expand All @@ -13,7 +16,10 @@ var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');

// Check if buffer exists
try {
if (Buffer && Buffer.from) var hasBufferType = true;
if (Buffer && Buffer.from) {
var hasBufferType = true;
inspect = require('util').inspect.custom || 'inspect';
}
} catch (err) {
hasBufferType = false;
}
Expand Down Expand Up @@ -196,7 +202,7 @@ ObjectID.prototype.toString = function(format) {
* @return {String} return the 24 byte hex string representation.
* @ignore
*/
ObjectID.prototype.inspect = ObjectID.prototype.toString;
ObjectID.prototype[inspect] = ObjectID.prototype.toString;

/**
* Converts to its JSON representation.
Expand Down
5 changes: 4 additions & 1 deletion lib/bson/symbol.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Custom inspect property name / symbol.
var inspect = Buffer ? require('util').inspect.custom || 'inspect' : 'inspect';

/**
* A class representation of the BSON Symbol type.
*
Expand Down Expand Up @@ -32,7 +35,7 @@ Symbol.prototype.toString = function() {
/**
* @ignore
*/
Symbol.prototype.inspect = function() {
Symbol.prototype[inspect] = function() {
return this.value;
};

Expand Down

0 comments on commit 080323b

Please sign in to comment.