Fix context.inspect when called on the prototype (#1012)

* Fix context.inspect when called on the prototype

Fixes #837

* Add tests
master
Luke Bousfield 2017-07-15 18:05:26 -06:00 committed by jongleberry
parent 9f2182dec7
commit 67630217ae
2 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ const proto = module.exports = {
*/
inspect() {
if (this === proto) return this;
return this.toJSON();
},

View File

@ -1,6 +1,7 @@
'use strict';
const prototype = require('../../lib/context');
const assert = require('assert');
const context = require('../helpers/context');
@ -11,4 +12,9 @@ describe('ctx.inspect()', () => {
assert.deepEqual(toJSON, ctx.inspect());
});
// console.log(require.cache) will call prototype.inspect()
it('should not crash when called on the prototype', () => {
assert.deepEqual(prototype, prototype.inspect());
});
});