| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4c207d9 commit 338f456
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -463,28 +463,22 @@ function clazzWithNullPrototype(clazz, name) { | |||
| 463 | 463 | function noPrototypeIterator(ctx, value, recurseTimes) { | |
| 464 | 464 | let newVal; | |
| 465 | 465 | if (isSet(value)) { | |
| 466 | - const clazz = Object.getPrototypeOf(value) || | ||
| 467 | - clazzWithNullPrototype(Set, 'Set'); | ||
| 466 | + const clazz = clazzWithNullPrototype(Set, 'Set'); | ||
| 468 | 467 | newVal = new clazz(setValues(value)); | |
| 469 | 468 | } else if (isMap(value)) { | |
| 470 | - const clazz = Object.getPrototypeOf(value) || | ||
| 471 | - clazzWithNullPrototype(Map, 'Map'); | ||
| 469 | + const clazz = clazzWithNullPrototype(Map, 'Map'); | ||
| 472 | 470 | newVal = new clazz(mapEntries(value)); | |
| 473 | 471 | } else if (Array.isArray(value)) { | |
| 474 | - const clazz = Object.getPrototypeOf(value) || | ||
| 475 | - clazzWithNullPrototype(Array, 'Array'); | ||
| 472 | + const clazz = clazzWithNullPrototype(Array, 'Array'); | ||
| 476 | 473 | newVal = new clazz(value.length); | |
| 477 | 474 | } else if (isTypedArray(value)) { | |
| 478 | - let clazz = Object.getPrototypeOf(value); | ||
| 479 | - if (!clazz) { | ||
| 480 | - const constructor = findTypedConstructor(value); | ||
| 481 | - clazz = clazzWithNullPrototype(constructor, constructor.name); | ||
| 482 | - } | ||
| 475 | + const constructor = findTypedConstructor(value); | ||
| 476 | + const clazz = clazzWithNullPrototype(constructor, constructor.name); | ||
| 483 | 477 | newVal = new clazz(value); | |
| 484 | 478 | } | |
| 485 | - if (newVal) { | ||
| 479 | + if (newVal !== undefined) { | ||
| 486 | 480 | Object.defineProperties(newVal, Object.getOwnPropertyDescriptors(value)); | |
| 487 | - return formatValue(ctx, newVal, recurseTimes); | ||
| 481 | + return formatRaw(ctx, newVal, recurseTimes); | ||
| 488 | 482 | } | |
| 489 | 483 | } | |
| 490 | 484 | ||
@@ -728,9 +722,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { | |||
| 728 | 722 | } else { | |
| 729 | 723 | // The input prototype got manipulated. Special handle these. We have to | |
| 730 | 724 | // rebuild the information so we are able to display everything. | |
| 731 | - const specialIterator = noPrototypeIterator(ctx, value, recurseTimes); | ||
| 732 | - if (specialIterator) { | ||
| 733 | - return specialIterator; | ||
| 725 | + if (constructor === null) { | ||
| 726 | + const specialIterator = noPrototypeIterator(ctx, value, recurseTimes); | ||
| 727 | + if (specialIterator) { | ||
| 728 | + return specialIterator; | ||
| 729 | + } | ||
| 734 | 730 | } | |
| 735 | 731 | if (isMapIterator(value)) { | |
| 736 | 732 | braces = [`[${tag || 'Map Iterator'}] {`, '}']; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1853,6 +1853,16 @@ assert.strictEqual( | |||
| 1853 | 1853 | util.inspect(new StorageObject()), | |
| 1854 | 1854 | '<[Object: null prototype] {}> {}' | |
| 1855 | 1855 | ); | |
| 1856 | + | ||
| 1857 | + obj = [1, 2, 3]; | ||
| 1858 | + Object.setPrototypeOf(obj, Number.prototype); | ||
| 1859 | + assert.strictEqual(inspect(obj), "Number { '0': 1, '1': 2, '2': 3 }"); | ||
| 1860 | + | ||
| 1861 | + Object.setPrototypeOf(obj, Object.create(null)); | ||
| 1862 | + assert.strictEqual( | ||
| 1863 | + inspect(obj), | ||
| 1864 | + "<[Object: null prototype] {}> { '0': 1, '1': 2, '2': 3 }" | ||
| 1865 | + ); | ||
| 1856 | 1866 | } | |
| 1857 | 1867 | ||
| 1858 | 1868 | // Check that the fallback always works. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments