Fix context.inspect when called on the prototype (#1012)
* Fix context.inspect when called on the prototype Fixes #837 * Add tests
This commit is contained in:
parent
9f2182dec7
commit
67630217ae
2 changed files with 7 additions and 0 deletions
|
@ -25,6 +25,7 @@ const proto = module.exports = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inspect() {
|
inspect() {
|
||||||
|
if (this === proto) return this;
|
||||||
return this.toJSON();
|
return this.toJSON();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const prototype = require('../../lib/context');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const context = require('../helpers/context');
|
const context = require('../helpers/context');
|
||||||
|
|
||||||
|
@ -11,4 +12,9 @@ describe('ctx.inspect()', () => {
|
||||||
|
|
||||||
assert.deepEqual(toJSON, 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());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue