| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67e9e71 commit ec5b06e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const { | |||
| 5 | 5 | ArrayIsArray, | |
| 6 | 6 | ArrayPrototypeFilter, | |
| 7 | 7 | ArrayPrototypeForEach, | |
| 8 | + ArrayPrototypePop, | ||
| 8 | 9 | ArrayPrototypePush, | |
| 9 | 10 | ArrayPrototypePushApply, | |
| 10 | 11 | ArrayPrototypeSort, | |
@@ -620,6 +621,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) { | |||
| 620 | 621 | } | |
| 621 | 622 | // Get all own property names and symbols. | |
| 622 | 623 | keys = ReflectOwnKeys(obj); | |
| 624 | + ArrayPrototypePush(ctx.seen, main); | ||
| 623 | 625 | for (const key of keys) { | |
| 624 | 626 | // Ignore the `constructor` property and keys that exist on layers above. | |
| 625 | 627 | if (key === 'constructor' || | |
@@ -640,6 +642,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) { | |||
| 640 | 642 | ArrayPrototypePush(output, value); | |
| 641 | 643 | } | |
| 642 | 644 | } | |
| 645 | + ArrayPrototypePop(ctx.seen); | ||
| 643 | 646 | // Limit the inspection to up to three prototype layers. Using `recurseTimes` | |
| 644 | 647 | // is not a good choice here, because it's as if the properties are declared | |
| 645 | 648 | // on the current object from the users perspective. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,24 +7,61 @@ require('../common'); | |||
| 7 | 7 | ||
| 8 | 8 | const assert = require('assert'); | |
| 9 | 9 | ||
| 10 | - const util = require('util'); | ||
| 10 | + const { inspect } = require('util'); | ||
| 11 | 11 | ||
| 12 | - class X { | ||
| 13 | - constructor() { | ||
| 14 | - this._y = 123; | ||
| 15 | - } | ||
| 12 | + { | ||
| 13 | + class X { | ||
| 14 | + constructor() { | ||
| 15 | + this._y = 123; | ||
| 16 | + } | ||
| 16 | 17 | ||
| 17 | - get y() { | ||
| 18 | - return this._y; | ||
| 18 | + get y() { | ||
| 19 | + return this._y; | ||
| 20 | + } | ||
| 19 | 21 | } | |
| 22 | + | ||
| 23 | + const result = inspect(new X(), { | ||
| 24 | + getters: true, | ||
| 25 | + showHidden: true | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + assert.strictEqual( | ||
| 29 | + result, | ||
| 30 | + 'X { _y: 123, [y]: [Getter: 123] }' | ||
| 31 | + ); | ||
| 20 | 32 | } | |
| 21 | 33 | ||
| 22 | - const result = util.inspect(new X(), { | ||
| 23 | - getters: true, | ||
| 24 | - showHidden: true | ||
| 25 | - }); | ||
| 34 | + // Regression test for https://github.com/nodejs/node/issues/37054 | ||
| 35 | + { | ||
| 36 | + class A { | ||
| 37 | + constructor(B) { | ||
| 38 | + this.B = B; | ||
| 39 | + } | ||
| 40 | + get b() { | ||
| 41 | + return this.B; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + class B { | ||
| 46 | + constructor() { | ||
| 47 | + this.A = new A(this); | ||
| 48 | + } | ||
| 49 | + get a() { | ||
| 50 | + return this.A; | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + const result = inspect(new B(), { | ||
| 55 | + depth: 1, | ||
| 56 | + getters: true, | ||
| 57 | + showHidden: true | ||
| 58 | + }); | ||
| 26 | 59 | ||
| 27 | - assert.strictEqual( | ||
| 28 | - result, | ||
| 29 | - 'X { _y: 123, [y]: [Getter: 123] }' | ||
| 30 | - ); | ||
| 60 | + assert.strictEqual( | ||
| 61 | + result, | ||
| 62 | + '<ref *1> B {\n' + | ||
| 63 | + ' A: A { B: [Circular *1], [b]: [Getter] [Circular *1] },\n' + | ||
| 64 | + ' [a]: [Getter] A { B: [Circular *1], [b]: [Getter] [Circular *1] }\n' + | ||
| 65 | + '}', | ||
| 66 | + ); | ||
| 67 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments