X Tutup
The Wayback Machine - https://web.archive.org/web/20220420075513/https://github.com/nodejs/node/commit/fee0389c12
Skip to content
Permalink
Browse files
test: check null proto-of-proto in util.inspect()
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: #36399
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and targos committed May 1, 2021
1 parent 0e821ff commit fee0389c12d818ab32f2c88d5b0701b4ecfc9f69
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/parallel/test-util-inspect.js
@@ -3021,3 +3021,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);
}

0 comments on commit fee0389

Please sign in to comment.
X Tutup