From 7b5bd93ced0967ed0d385e96926735bd09c0a817 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 5 May 2019 13:42:16 +0200 Subject: [PATCH] util: compatibility patch to backport d0667e8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure that https://github.com/nodejs/node/pull/27227 may be backported as semver-patch instead of semver-major. PR-URL: https://github.com/nodejs/node/pull/27570 Reviewed-By: Michaël Zasso --- lib/internal/util/inspect.js | 4 +--- test/parallel/test-assert.js | 4 ++-- test/parallel/test-console-table.js | 2 +- test/parallel/test-repl.js | 2 +- test/parallel/test-util-format.js | 6 +++--- test/parallel/test-util-inspect-proxy.js | 4 ++-- test/parallel/test-util-inspect.js | 24 ++++++++++++------------ 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 22dec67330cd31..7f189b5b7466ef 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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 += ']'; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 98f728acfa4ed0..003e67b380d88d 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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+ }'); @@ -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" + '- }' }); diff --git a/test/parallel/test-console-table.js b/test/parallel/test-console-table.js index 98c6dd8776fda2..3a4d6fefbbc8f1 100644 --- a/test/parallel/test-console-table.js +++ b/test/parallel/test-console-table.js @@ -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], ` ┌─────────┬────────┐ diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 05608bd5ee6ac3..c0869c84b30b71 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -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 { diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index fa0f66ecfc3fa1..6e5c50ab406b83 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -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 = {}; @@ -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'); diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index da0512eda1a8b2..c20af7450a426e 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -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); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 1bab0fe0a7dff7..f1d5680d650ee4 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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( @@ -454,7 +454,7 @@ assert.strictEqual( value.aprop = 42; assert.strictEqual( util.inspect(value), - '[Function (anonymous)] { aprop: 42 }' + '[Function] { aprop: 42 }' ); } @@ -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'); @@ -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]: ''", ' },', @@ -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 }'], @@ -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 }' );