From 7a39d892d6a257a9443c8e9bedad6d412359864b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 5 Dec 2020 09:50:03 -0800 Subject: [PATCH] test: check null proto-of-proto in util.inspect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test to check util.inspect()'s handling of a null prototype-of-an-iterable-prototype. This covers a previously uncovered code branch. Refs: https://coverage.nodejs.org/coverage-0fd121e00c9d5987/lib/internal/util/inspect.js.html#L597 PR-URL: https://github.com/nodejs/node/pull/36399 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Antoine du Hamel Reviewed-By: Daijiro Wachi Reviewed-By: James M Snell --- test/parallel/test-util-inspect.js | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 8961b6cef20..e51b96fffd6 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -3011,3 +3011,35 @@ assert.strictEqual( '}' ); } + +{ + // Confirm null prototype of generator prototype displays as expected. + + function getProtoOfProto() { + return Object.getPrototypeOf(Object.getPrototypeOf(function* () {})); + } + + function* generator() {} + + const generatorPrototype = Object.getPrototypeOf(generator); + const originalProtoOfProto = Object.getPrototypeOf(generatorPrototype); + assert.strictEqual(getProtoOfProto(), originalProtoOfProto); + Object.setPrototypeOf(generatorPrototype, null); + assert.notStrictEqual(getProtoOfProto, originalProtoOfProto); + + // This is the actual test. The other assertions in this block are about + // making sure the test is set up correctly and isn't polluting other tests. + assert.strictEqual( + util.inspect(generator, { showHidden: true }), + '[GeneratorFunction: generator] {\n' + + ' [length]: 0,\n' + + " [name]: 'generator',\n" + + " [prototype]: Object [Generator] { [Symbol(Symbol.toStringTag)]: 'Generator' },\n" + // eslint-disable-line max-len + " [Symbol(Symbol.toStringTag)]: 'GeneratorFunction'\n" + + '}' + ); + + // Reset so we don't pollute other tests + Object.setPrototypeOf(generatorPrototype, originalProtoOfProto); + assert.strictEqual(getProtoOfProto(), originalProtoOfProto); +}