Skip to content

Commit

Permalink
util: compatibility patch to backport d0667e8
Browse files Browse the repository at this point in the history
This makes sure that #27227 may
be backported as semver-patch instead of semver-major.

PR-URL: #27570
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
BridgeAR authored and targos committed May 6, 2019
1 parent 52d4f1f commit 7b5bd93
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
4 changes: 1 addition & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,7 @@ function getFunctionBase(value, constructor, tag) {
if (constructor === null) {
base += ' (null prototype)';
}
if (value.name === '') {
base += ' (anonymous)';
} else {
if (value.name !== '') {
base += `: ${value.name}`;
}
base += ']';
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ testAssertionMessage(undefined, 'undefined');
testAssertionMessage(-Infinity, '-Infinity');
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
testAssertionMessage(function f() {}, '[Function: f]');
testAssertionMessage(function() {}, '[Function (anonymous)]');
testAssertionMessage(function() {}, '[Function]');
testAssertionMessage(circular, '{\n+ x: [Circular],\n+ y: 1\n+ }');
testAssertionMessage({ a: undefined, b: null },
'{\n+ a: undefined,\n+ b: null\n+ }');
Expand Down Expand Up @@ -597,7 +597,7 @@ assert.throws(
'\n' +
'+ {}\n' +
'- {\n' +
'- [Symbol(nodejs.util.inspect.custom)]: [Function (anonymous)],\n' +
'- [Symbol(nodejs.util.inspect.custom)]: [Function],\n' +
"- loop: 'forever'\n" +
'- }'
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-console-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test(undefined, 'undefined\n');
test(false, 'false\n');
test('hi', 'hi\n');
test(Symbol(), 'Symbol()\n');
test(function() {}, '[Function (anonymous)]\n');
test(function() {}, '[Function]\n');

test([1, 2, 3], `
┌─────────┬────────┐
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const errorTests = [
// Functions should not evaluate twice (#2773)
{
send: 'var I = [1,2,3,function() {}]; I.pop()',
expect: '[Function (anonymous)]'
expect: '[Function]'
},
// Multiline object
{
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ assert.strictEqual(util.format('abc%', 1), 'abc% 1');

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

{
const o = {};
Expand Down Expand Up @@ -344,8 +344,8 @@ assert.strictEqual(util.format('1', '1'), '1 1');
assert.strictEqual(util.format(1, '1'), '1 1');
assert.strictEqual(util.format('1', 1), '1 1');
assert.strictEqual(util.format(1, -0), '1 -0');
assert.strictEqual(util.format('1', () => {}), '1 [Function (anonymous)]');
assert.strictEqual(util.format(1, () => {}), '1 [Function (anonymous)]');
assert.strictEqual(util.format('1', () => {}), '1 [Function]');
assert.strictEqual(util.format(1, () => {}), '1 [Function]');
assert.strictEqual(util.format('1', "'"), "1 '");
assert.strictEqual(util.format(1, "'"), "1 '");
assert.strictEqual(util.format('1', 'number'), '1 number');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const proxy11 = new Proxy(() => {}, {
return proxy11;
}
});
const expected10 = '[Function (anonymous)]';
const expected11 = '[Function (anonymous)]';
const expected10 = '[Function]';
const expected11 = '[Function]';
assert.strictEqual(util.inspect(proxy10), expected10);
assert.strictEqual(util.inspect(proxy11), expected11);
24 changes: 12 additions & 12 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ assert.strictEqual(util.inspect(false), 'false');
assert.strictEqual(util.inspect(''), "''");
assert.strictEqual(util.inspect('hello'), "'hello'");
assert.strictEqual(util.inspect(function abc() {}), '[Function: abc]');
assert.strictEqual(util.inspect(() => {}), '[Function (anonymous)]');
assert.strictEqual(util.inspect(() => {}), '[Function]');
assert.strictEqual(
util.inspect(async function() {}),
'[AsyncFunction (anonymous)]'
'[AsyncFunction]'
);
assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction (anonymous)]');
assert.strictEqual(util.inspect(async () => {}), '[AsyncFunction]');

// Special function inspection.
{
const fn = (() => function*() {})();
assert.strictEqual(
util.inspect(fn),
'[GeneratorFunction (anonymous)]'
'[GeneratorFunction]'
);
Object.setPrototypeOf(fn, Object.getPrototypeOf(async () => {}));
assert.strictEqual(
util.inspect(fn),
'[GeneratorFunction (anonymous)] AsyncFunction'
'[GeneratorFunction] AsyncFunction'
);
Object.defineProperty(fn, 'name', { value: 5, configurable: true });
assert.strictEqual(
Expand Down Expand Up @@ -454,7 +454,7 @@ assert.strictEqual(
value.aprop = 42;
assert.strictEqual(
util.inspect(value),
'[Function (anonymous)] { aprop: 42 }'
'[Function] { aprop: 42 }'
);
}

Expand Down Expand Up @@ -1485,7 +1485,7 @@ util.inspect(process);
out = util.inspect(o, { compact: false, breakLength: 3 });
expect = [
'{',
' a: [Function (anonymous)],',
' a: [Function],',
' b: [Number: 3]',
'}'
].join('\n');
Expand All @@ -1494,7 +1494,7 @@ util.inspect(process);
out = util.inspect(o, { compact: false, breakLength: 3, showHidden: true });
expect = [
'{',
' a: [Function (anonymous)] {',
' a: [Function] {',
' [length]: 0,',
" [name]: ''",
' },',
Expand Down Expand Up @@ -1811,8 +1811,8 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
[new Number(55), '[Number: 55]'],
[Object(BigInt(55)), '[BigInt: 55n]'],
[Object(Symbol('foo')), '[Symbol: Symbol(foo)]'],
[function() {}, '[Function (anonymous)]'],
[() => {}, '[Function (anonymous)]'],
[function() {}, '[Function]'],
[() => {}, '[Function]'],
[[1, 2], '[ 1, 2 ]'],
[[, , 5, , , , ], '[ <2 empty items>, 5, <3 empty items> ]'],
[{ a: 5 }, '{ a: 5 }'],
Expand Down Expand Up @@ -2003,11 +2003,11 @@ assert.strictEqual(
Object.setPrototypeOf(obj, value);
assert.strictEqual(
util.inspect(obj),
'<[Function (null prototype) (anonymous)]> { a: true }'
'<[Function (null prototype)]> { a: true }'
);
assert.strictEqual(
util.inspect(obj, { colors: true }),
'<\u001b[36m[Function (null prototype) (anonymous)]\u001b[39m> ' +
'<\u001b[36m[Function (null prototype)]\u001b[39m> ' +
'{ a: \u001b[33mtrue\u001b[39m }'
);

Expand Down

0 comments on commit 7b5bd93

Please sign in to comment.