Skip to content

Commit 7b5bd93

Browse files
BridgeARtargos
authored andcommitted
util: compatibility patch to backport d0667e8
This makes sure that #27227 may be backported as semver-patch instead of semver-major. PR-URL: #27570 Reviewed-By: Michaël Zasso <[email protected]>
1 parent 52d4f1f commit 7b5bd93

7 files changed

+22
-24
lines changed

lib/internal/util/inspect.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,7 @@ function getFunctionBase(value, constructor, tag) {
842842
if (constructor === null) {
843843
base += ' (null prototype)';
844844
}
845-
if (value.name === '') {
846-
base += ' (anonymous)';
847-
} else {
845+
if (value.name !== '') {
848846
base += `: ${value.name}`;
849847
}
850848
base += ']';

test/parallel/test-assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ testAssertionMessage(undefined, 'undefined');
289289
testAssertionMessage(-Infinity, '-Infinity');
290290
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
291291
testAssertionMessage(function f() {}, '[Function: f]');
292-
testAssertionMessage(function() {}, '[Function (anonymous)]');
292+
testAssertionMessage(function() {}, '[Function]');
293293
testAssertionMessage(circular, '{\n+ x: [Circular],\n+ y: 1\n+ }');
294294
testAssertionMessage({ a: undefined, b: null },
295295
'{\n+ a: undefined,\n+ b: null\n+ }');
@@ -597,7 +597,7 @@ assert.throws(
597597
'\n' +
598598
'+ {}\n' +
599599
'- {\n' +
600-
'- [Symbol(nodejs.util.inspect.custom)]: [Function (anonymous)],\n' +
600+
'- [Symbol(nodejs.util.inspect.custom)]: [Function],\n' +
601601
"- loop: 'forever'\n" +
602602
'- }'
603603
});

test/parallel/test-console-table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test(undefined, 'undefined\n');
3232
test(false, 'false\n');
3333
test('hi', 'hi\n');
3434
test(Symbol(), 'Symbol()\n');
35-
test(function() {}, '[Function (anonymous)]\n');
35+
test(function() {}, '[Function]\n');
3636

3737
test([1, 2, 3], `
3838
┌─────────┬────────┐

test/parallel/test-repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const errorTests = [
308308
// Functions should not evaluate twice (#2773)
309309
{
310310
send: 'var I = [1,2,3,function() {}]; I.pop()',
311-
expect: '[Function (anonymous)]'
311+
expect: '[Function]'
312312
},
313313
// Multiline object
314314
{

test/parallel/test-util-format.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ assert.strictEqual(util.format('abc%', 1), 'abc% 1');
293293

294294
// Additional arguments after format specifiers
295295
assert.strictEqual(util.format('%i', 1, 'number'), '1 number');
296-
assert.strictEqual(util.format('%i', 1, () => {}), '1 [Function (anonymous)]');
296+
assert.strictEqual(util.format('%i', 1, () => {}), '1 [Function]');
297297

298298
{
299299
const o = {};
@@ -344,8 +344,8 @@ assert.strictEqual(util.format('1', '1'), '1 1');
344344
assert.strictEqual(util.format(1, '1'), '1 1');
345345
assert.strictEqual(util.format('1', 1), '1 1');
346346
assert.strictEqual(util.format(1, -0), '1 -0');
347-
assert.strictEqual(util.format('1', () => {}), '1 [Function (anonymous)]');
348-
assert.strictEqual(util.format(1, () => {}), '1 [Function (anonymous)]');
347+
assert.strictEqual(util.format('1', () => {}), '1 [Function]');
348+
assert.strictEqual(util.format(1, () => {}), '1 [Function]');
349349
assert.strictEqual(util.format('1', "'"), "1 '");
350350
assert.strictEqual(util.format(1, "'"), "1 '");
351351
assert.strictEqual(util.format('1', 'number'), '1 number');

test/parallel/test-util-inspect-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const proxy11 = new Proxy(() => {}, {
144144
return proxy11;
145145
}
146146
});
147-
const expected10 = '[Function (anonymous)]';
148-
const expected11 = '[Function (anonymous)]';
147+
const expected10 = '[Function]';
148+
const expected11 = '[Function]';
149149
assert.strictEqual(util.inspect(proxy10), expected10);
150150
assert.strictEqual(util.inspect(proxy11), expected11);

test/parallel/test-util-inspect.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ assert.strictEqual(util.inspect(false), 'false');
3434
assert.strictEqual(util.inspect(''), "''");
3535
assert.strictEqual(util.inspect('hello'), "'hello'");
3636
assert.strictEqual(util.inspect(function abc() {}), '[Function: abc]');
37-
assert.strictEqual(util.inspect(() => {}), '[Function (anonymous)]');
37+
assert.strictEqual(util.inspect(() => {}), '[Function]');
3838
assert.strictEqual(
3939
util.inspect(async function() {}),
40-
'[AsyncFunction (anonymous)]'
40+
'[AsyncFunction]'
4141
);
42-
assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction (anonymous)]');
42+
assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction]');
4343

4444
// Special function inspection.
4545
{
4646
const fn = (() => function*() {})();
4747
assert.strictEqual(
4848
util.inspect(fn),
49-
'[GeneratorFunction (anonymous)]'
49+
'[GeneratorFunction]'
5050
);
5151
Object.setPrototypeOf(fn, Object.getPrototypeOf(async () => {}));
5252
assert.strictEqual(
5353
util.inspect(fn),
54-
'[GeneratorFunction (anonymous)] AsyncFunction'
54+
'[GeneratorFunction] AsyncFunction'
5555
);
5656
Object.defineProperty(fn, 'name', { value: 5, configurable: true });
5757
assert.strictEqual(
@@ -454,7 +454,7 @@ assert.strictEqual(
454454
value.aprop = 42;
455455
assert.strictEqual(
456456
util.inspect(value),
457-
'[Function (anonymous)] { aprop: 42 }'
457+
'[Function] { aprop: 42 }'
458458
);
459459
}
460460

@@ -1485,7 +1485,7 @@ util.inspect(process);
14851485
out = util.inspect(o, { compact: false, breakLength: 3 });
14861486
expect = [
14871487
'{',
1488-
' a: [Function (anonymous)],',
1488+
' a: [Function],',
14891489
' b: [Number: 3]',
14901490
'}'
14911491
].join('\n');
@@ -1494,7 +1494,7 @@ util.inspect(process);
14941494
out = util.inspect(o, { compact: false, breakLength: 3, showHidden: true });
14951495
expect = [
14961496
'{',
1497-
' a: [Function (anonymous)] {',
1497+
' a: [Function] {',
14981498
' [length]: 0,',
14991499
" [name]: ''",
15001500
' },',
@@ -1811,8 +1811,8 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
18111811
[new Number(55), '[Number: 55]'],
18121812
[Object(BigInt(55)), '[BigInt: 55n]'],
18131813
[Object(Symbol('foo')), '[Symbol: Symbol(foo)]'],
1814-
[function() {}, '[Function (anonymous)]'],
1815-
[() => {}, '[Function (anonymous)]'],
1814+
[function() {}, '[Function]'],
1815+
[() => {}, '[Function]'],
18161816
[[1, 2], '[ 1, 2 ]'],
18171817
[[, , 5, , , , ], '[ <2 empty items>, 5, <3 empty items> ]'],
18181818
[{ a: 5 }, '{ a: 5 }'],
@@ -2003,11 +2003,11 @@ assert.strictEqual(
20032003
Object.setPrototypeOf(obj, value);
20042004
assert.strictEqual(
20052005
util.inspect(obj),
2006-
'<[Function (null prototype) (anonymous)]> { a: true }'
2006+
'<[Function (null prototype)]> { a: true }'
20072007
);
20082008
assert.strictEqual(
20092009
util.inspect(obj, { colors: true }),
2010-
'<\u001b[36m[Function (null prototype) (anonymous)]\u001b[39m> ' +
2010+
'<\u001b[36m[Function (null prototype)]\u001b[39m> ' +
20112011
'{ a: \u001b[33mtrue\u001b[39m }'
20122012
);
20132013

0 commit comments

Comments
 (0)