From 93db417105d45d3841ace5a932429d5e57005e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 7 Feb 2017 10:41:49 +0100 Subject: [PATCH 1/2] tools: enable ES2017 syntax support in ESLint This allows us to use async functions. --- .eslintrc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 4f691caefd3a78..b48cccee5ac123 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -3,7 +3,7 @@ env: es6: true parserOptions: - ecmaVersion: 2016 + ecmaVersion: 2017 rules: # Possible Errors From c2fac57b6bc43d2f561b91f7a02ccb2af690bd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 7 Feb 2017 10:46:12 +0100 Subject: [PATCH 2/2] util: improve inspect for (Async|Generator)Function Use the constructor name in the output, if present. --- lib/util.js | 13 ++++++++----- test/parallel/test-util-inspect.js | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/util.js b/lib/util.js index 46cde4d85bf28b..003b5e5b54073b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -400,11 +400,14 @@ function formatValue(ctx, value, recurseTimes) { }); } + var constructor = getConstructorOf(value); + // Some type of object without properties can be shortcutted. if (keys.length === 0) { if (typeof value === 'function') { - return ctx.stylize(`[Function${value.name ? `: ${value.name}` : ''}]`, - 'special'); + const ctorName = constructor ? constructor.name : 'Function'; + return ctx.stylize( + `[${ctorName}${value.name ? `: ${value.name}` : ''}]`, 'special'); } if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); @@ -440,12 +443,11 @@ function formatValue(ctx, value, recurseTimes) { // Can't do the same for DataView because it has a non-primitive // .buffer property that we need to recurse for. if (binding.isArrayBuffer(value) || binding.isSharedArrayBuffer(value)) { - return `${getConstructorOf(value).name}` + + return `${constructor.name}` + ` { byteLength: ${formatNumber(ctx, value.byteLength)} }`; } } - var constructor = getConstructorOf(value); var base = '', empty = false, braces; var formatter = formatObject; @@ -536,7 +538,8 @@ function formatValue(ctx, value, recurseTimes) { // Make functions say that they are functions if (typeof value === 'function') { - base = ` [Function${value.name ? `: ${value.name}` : ''}]`; + const ctorName = constructor ? constructor.name : 'Function'; + base = ` [${ctorName}${value.name ? `: ${value.name}` : ''}]`; } // Make RegExps say that they are RegExps diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index d1fa12902e4076..53f7e3014b389e 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -9,6 +9,8 @@ assert.strictEqual(util.inspect(false), 'false'); assert.strictEqual(util.inspect(''), "''"); assert.strictEqual(util.inspect('hello'), "'hello'"); assert.strictEqual(util.inspect(function() {}), '[Function]'); +assert.strictEqual(util.inspect(async function() {}), '[AsyncFunction]'); +assert.strictEqual(util.inspect(function*() {}), '[GeneratorFunction]'); assert.strictEqual(util.inspect(undefined), 'undefined'); assert.strictEqual(util.inspect(null), 'null'); assert.strictEqual(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi'); @@ -28,6 +30,10 @@ assert.strictEqual(util.inspect([1, [2, 3]]), '[ 1, [ 2, 3 ] ]'); assert.strictEqual(util.inspect({}), '{}'); assert.strictEqual(util.inspect({a: 1}), '{ a: 1 }'); assert.strictEqual(util.inspect({a: function() {}}), '{ a: [Function: a] }'); +assert.strictEqual(util.inspect({a: async function() {}}), + '{ a: [AsyncFunction: a] }'); +assert.strictEqual(util.inspect({a: function*() {}}), + '{ a: [GeneratorFunction: a] }'); assert.strictEqual(util.inspect({a: 1, b: 2}), '{ a: 1, b: 2 }'); assert.strictEqual(util.inspect({'a': {}}), '{ a: {} }'); assert.strictEqual(util.inspect({'a': {'b': 2}}), '{ a: { b: 2 } }');