From 67630217ae8383c0f24d3653408bc41ad77e54fc Mon Sep 17 00:00:00 2001 From: Luke Bousfield Date: Sat, 15 Jul 2017 18:05:26 -0600 Subject: [PATCH] Fix context.inspect when called on the prototype (#1012) * Fix context.inspect when called on the prototype Fixes #837 * Add tests --- lib/context.js | 1 + test/context/inspect.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/context.js b/lib/context.js index 0cbf207..e7b10b8 100644 --- a/lib/context.js +++ b/lib/context.js @@ -25,6 +25,7 @@ const proto = module.exports = { */ inspect() { + if (this === proto) return this; return this.toJSON(); }, diff --git a/test/context/inspect.js b/test/context/inspect.js index 9aa0285..98edf96 100644 --- a/test/context/inspect.js +++ b/test/context/inspect.js @@ -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()); + }); });