| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6272f82 commit 68630c5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -351,7 +351,7 @@ function getEmptyFormatArray() { | |||
| 351 | 351 | return []; | |
| 352 | 352 | } | |
| 353 | 353 | ||
| 354 | - function getConstructorName(obj, ctx) { | ||
| 354 | + function getConstructorName(obj, ctx, recurseTimes) { | ||
| 355 | 355 | let firstProto; | |
| 356 | 356 | const tmp = obj; | |
| 357 | 357 | while (obj) { | |
@@ -372,10 +372,23 @@ function getConstructorName(obj, ctx) { | |||
| 372 | 372 | return null; | |
| 373 | 373 | } | |
| 374 | 374 | ||
| 375 | - return `${internalGetConstructorName(tmp)} <${inspect(firstProto, { | ||
| 376 | - ...ctx, | ||
| 377 | - customInspect: false | ||
| 378 | - })}>`; | ||
| 375 | + const res = internalGetConstructorName(tmp); | ||
| 376 | + | ||
| 377 | + if (recurseTimes > ctx.depth && ctx.depth !== null) { | ||
| 378 | + return `${res} <Complex prototype>`; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + const protoConstr = getConstructorName(firstProto, ctx, recurseTimes + 1); | ||
| 382 | + | ||
| 383 | + if (protoConstr === null) { | ||
| 384 | + return `${res} <${inspect(firstProto, { | ||
| 385 | + ...ctx, | ||
| 386 | + customInspect: false, | ||
| 387 | + depth: -1 | ||
| 388 | + })}>`; | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + return `${res} <${protoConstr}>`; | ||
| 379 | 392 | } | |
| 380 | 393 | ||
| 381 | 394 | function getPrefix(constructor, tag, fallback) { | |
@@ -570,7 +583,7 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | |||
| 570 | 583 | function formatRaw(ctx, value, recurseTimes, typedArray) { | |
| 571 | 584 | let keys; | |
| 572 | 585 | ||
| 573 | - const constructor = getConstructorName(value, ctx); | ||
| 586 | + const constructor = getConstructorName(value, ctx, recurseTimes); | ||
| 574 | 587 | let tag = value[Symbol.toStringTag]; | |
| 575 | 588 | // Only list the tag in case it's non-enumerable / not an own property. | |
| 576 | 589 | // Otherwise we'd print this twice. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2092,6 +2092,21 @@ assert.strictEqual( | |||
| 2092 | 2092 | inspect(obj), | |
| 2093 | 2093 | "Array <[Object: null prototype] {}> { '0': 1, '1': 2, '2': 3 }" | |
| 2094 | 2094 | ); | |
| 2095 | + | ||
| 2096 | + StorageObject.prototype = Object.create(null); | ||
| 2097 | + Object.setPrototypeOf(StorageObject.prototype, Object.create(null)); | ||
| 2098 | + Object.setPrototypeOf( | ||
| 2099 | + Object.getPrototypeOf(StorageObject.prototype), | ||
| 2100 | + Object.create(null) | ||
| 2101 | + ); | ||
| 2102 | + assert.strictEqual( | ||
| 2103 | + util.inspect(new StorageObject()), | ||
| 2104 | + 'StorageObject <Object <Object <[Object: null prototype] {}>>> {}' | ||
| 2105 | + ); | ||
| 2106 | + assert.strictEqual( | ||
| 2107 | + util.inspect(new StorageObject(), { depth: 1 }), | ||
| 2108 | + 'StorageObject <Object <Object <Complex prototype>>> {}' | ||
| 2109 | + ); | ||
| 2095 | 2110 | } | |
| 2096 | 2111 | ||
| 2097 | 2112 | // Check that the fallback always works. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments