Skip to content

Commit fee0389

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 0e821ff commit fee0389

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
@@ -3021,3 +3021,35 @@ assert.strictEqual(
30213021
'}'
30223022
);
30233023
}
3024+
3025+
{
3026+
// Confirm null prototype of generator prototype displays as expected.
3027+
3028+
function getProtoOfProto() {
3029+
return Object.getPrototypeOf(Object.getPrototypeOf(function* () {}));
3030+
}
3031+
3032+
function* generator() {}
3033+
3034+
const generatorPrototype = Object.getPrototypeOf(generator);
3035+
const originalProtoOfProto = Object.getPrototypeOf(generatorPrototype);
3036+
assert.strictEqual(getProtoOfProto(), originalProtoOfProto);
3037+
Object.setPrototypeOf(generatorPrototype, null);
3038+
assert.notStrictEqual(getProtoOfProto, originalProtoOfProto);
3039+
3040+
// This is the actual test. The other assertions in this block are about
3041+
// making sure the test is set up correctly and isn't polluting other tests.
3042+
assert.strictEqual(
3043+
util.inspect(generator, { showHidden: true }),
3044+
'[GeneratorFunction: generator] {\n' +
3045+
' [length]: 0,\n' +
3046+
" [name]: 'generator',\n" +
3047+
" [prototype]: Object [Generator] { [Symbol(Symbol.toStringTag)]: 'Generator' },\n" + // eslint-disable-line max-len
3048+
" [Symbol(Symbol.toStringTag)]: 'GeneratorFunction'\n" +
3049+
'}'
3050+
);
3051+
3052+
// Reset so we don't pollute other tests
3053+
Object.setPrototypeOf(generatorPrototype, originalProtoOfProto);
3054+
assert.strictEqual(getProtoOfProto(), originalProtoOfProto);
3055+
}

0 commit comments

Comments
 (0)