Skip to content

Commit 023291b

Browse files
Trotttargos
authored andcommitted
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 <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d3d1f33 commit 023291b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/parallel/test-util-inspect.js

+32
Original file line numberDiff line numberDiff line change
@@ -3011,3 +3011,35 @@ assert.strictEqual(
30113011
'}'
30123012
);
30133013
}
3014+
3015+
{
3016+
// Confirm null prototype of generator prototype displays as expected.
3017+
3018+
function getProtoOfProto() {
3019+
return Object.getPrototypeOf(Object.getPrototypeOf(function* () {}));
3020+
}
3021+
3022+
function* generator() {}
3023+
3024+
const generatorPrototype = Object.getPrototypeOf(generator);
3025+
const originalProtoOfProto = Object.getPrototypeOf(generatorPrototype);
3026+
assert.strictEqual(getProtoOfProto(), originalProtoOfProto);
3027+
Object.setPrototypeOf(generatorPrototype, null);
3028+
assert.notStrictEqual(getProtoOfProto, originalProtoOfProto);
3029+
3030+
// This is the actual test. The other assertions in this block are about
3031+
// making sure the test is set up correctly and isn't polluting other tests.
3032+
assert.strictEqual(
3033+
util.inspect(generator, { showHidden: true }),
3034+
'[GeneratorFunction: generator] {\n' +
3035+
' [length]: 0,\n' +
3036+
" [name]: 'generator',\n" +
3037+
" [prototype]: Object [Generator] { [Symbol(Symbol.toStringTag)]: 'Generator' },\n" + // eslint-disable-line max-len
3038+
" [Symbol(Symbol.toStringTag)]: 'GeneratorFunction'\n" +
3039+
'}'
3040+
);
3041+
3042+
// Reset so we don't pollute other tests
3043+
Object.setPrototypeOf(generatorPrototype, originalProtoOfProto);
3044+
assert.strictEqual(getProtoOfProto(), originalProtoOfProto);
3045+
}

0 commit comments

Comments
 (0)