GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: fix formatting of functions returned from getters · nodejs/node@10e2603

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/util
    • inspect.js
  • test/parallel
    • test-util-inspect.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
23042304
const tmp = FunctionPrototypeCall(desc.get, original);
23052305
if (tmp === null) {
23062306
str = `${s(`[${label}:`, sp)} ${s('null', 'null')}${s(']', sp)}`;
2307-
} else if (typeof tmp === 'object') {
2307+
} else if (typeof tmp === 'object' || typeof tmp === 'function') {
23082308
str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
23092309
} else {
23102310
const primitive = formatPrimitive(s, tmp, ctx);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,15 @@ assert.strictEqual(
25962596
"'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}");
25972597
}
25982598

2599+
// Getter returning a function.
2600+
// https://github.com/nodejs/node/issues/64838
2601+
{
2602+
const obj = { get foo() { return function bar() {}; } };
2603+
assert.strictEqual(
2604+
inspect(obj, { getters: true }),
2605+
'{ foo: [Getter] [Function: bar] }');
2606+
}
2607+
25992608
// Property getter throwing an error.
26002609
{
26012610
const error = new Error('Oops');
@@ -3524,16 +3533,14 @@ assert.strictEqual(
35243533
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
35253534
);
35263535

3527-
assert.match(
3536+
assert.strictEqual(
35283537
inspect(Object.getPrototypeOf(bar), { showHidden: true, getters: true }),
3529-
new RegExp('^' + RegExp.escape(
3530-
'<ref *1> Foo [Map] {\n' +
3531-
' [constructor]: [class Bar extends Foo] {\n' +
3538+
'<ref *2> Foo [Map] {\n' +
3539+
' [constructor]: <ref *1> [class Bar extends Foo] {\n' +
35323540
' [length]: 0,\n' +
35333541
" [name]: 'Bar',\n" +
3534-
' [prototype]: [Circular *1],\n' +
3535-
' [Symbol(Symbol.species)]: [Getter: <Inspection threw ' +
3536-
"(TypeError: Symbol.prototype.toString requires that 'this' be a Symbol") + '.*' + RegExp.escape(')>]\n' +
3542+
' [prototype]: [Circular *2],\n' +
3543+
' [Symbol(Symbol.species)]: [Getter] [Circular *1]\n' +
35373544
' },\n' +
35383545
" [xyz]: [Getter: 'YES!'],\n" +
35393546
' [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] {\n' +
@@ -3543,7 +3550,6 @@ assert.strictEqual(
35433550
' [abc]: [Getter: true],\n' +
35443551
' [def]: [Getter/Setter: false]\n' +
35453552
'}'
3546-
) + '$', 's')
35473553
);
35483554

35493555
assert.strictEqual(

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.