| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,7 @@ function uncurryThis(func) { | |||
| 77 | 77 | const propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable); | |
| 78 | 78 | const regExpToString = uncurryThis(RegExp.prototype.toString); | |
| 79 | 79 | const dateToISOString = uncurryThis(Date.prototype.toISOString); | |
| 80 | + const dateToString = uncurryThis(Date.prototype.toString); | ||
| 80 | 81 | const errorToString = uncurryThis(Error.prototype.toString); | |
| 81 | 82 | ||
| 82 | 83 | const bigIntValueOf = uncurryThis(BigInt.prototype.valueOf); | |
@@ -646,12 +647,15 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { | |||
| 646 | 647 | return ctx.stylize(base, 'regexp'); | |
| 647 | 648 | } else if (isDate(value)) { | |
| 648 | 649 | // Make dates with properties first say the date | |
| 650 | + base = Number.isNaN(dateGetTime(value)) ? | ||
| 651 | + dateToString(value) : | ||
| 652 | + dateToISOString(value); | ||
| 653 | + const prefix = getPrefix(constructor, tag, 'Date'); | ||
| 654 | + if (prefix !== 'Date ') | ||
| 655 | + base = `${prefix}${base}`; | ||
| 649 | 656 | if (keys.length === 0) { | |
| 650 | - if (Number.isNaN(dateGetTime(value))) | ||
| 651 | - return ctx.stylize(String(value), 'date'); | ||
| 652 | - return ctx.stylize(dateToISOString(value), 'date'); | ||
| 657 | + return ctx.stylize(base, 'date'); | ||
| 653 | 658 | } | |
| 654 | - base = dateToISOString(value); | ||
| 655 | 659 | } else if (isError(value)) { | |
| 656 | 660 | // Make error with message first say the error. | |
| 657 | 661 | base = formatError(value); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -117,16 +117,16 @@ assert.throws( | |||
| 117 | 117 | { | |
| 118 | 118 | code: 'ERR_ASSERTION', | |
| 119 | 119 | message: `${defaultMsgStartFull}\n\n` + | |
| 120 | - '+ 2016-01-01T00:00:00.000Z\n- 2016-01-01T00:00:00.000Z {\n' + | ||
| 121 | - "- '0': '1'\n- }" | ||
| 120 | + '+ 2016-01-01T00:00:00.000Z\n- MyDate 2016-01-01T00:00:00.000Z' + | ||
| 121 | + " {\n- '0': '1'\n- }" | ||
| 122 | 122 | } | |
| 123 | 123 | ); | |
| 124 | 124 | assert.throws( | |
| 125 | 125 | () => assert.deepStrictEqual(date2, date), | |
| 126 | 126 | { | |
| 127 | 127 | code: 'ERR_ASSERTION', | |
| 128 | 128 | message: `${defaultMsgStartFull}\n\n` + | |
| 129 | - '+ 2016-01-01T00:00:00.000Z {\n' + | ||
| 129 | + '+ MyDate 2016-01-01T00:00:00.000Z {\n' + | ||
| 130 | 130 | "+ '0': '1'\n+ }\n- 2016-01-01T00:00:00.000Z" | |
| 131 | 131 | } | |
| 132 | 132 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1663,7 +1663,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1663 | 1663 | 'byteOffset: undefined,\n buffer: undefined }'], | |
| 1664 | 1664 | [new SharedArrayBuffer(2), '[SharedArrayBuffer: null prototype] ' + | |
| 1665 | 1665 | '{ [Uint8Contents]: <00 00>, byteLength: undefined }'], | |
| 1666 | - [/foobar/, '[RegExp: null prototype] /foobar/'] | ||
| 1666 | + [/foobar/, '[RegExp: null prototype] /foobar/'], | ||
| 1667 | + [new Date('Sun, 14 Feb 2010 11:48:40 GMT'), | ||
| 1668 | + '[Date: null prototype] 2010-02-14T11:48:40.000Z'] | ||
| 1667 | 1669 | ].forEach(([value, expected]) => { | |
| 1668 | 1670 | assert.strictEqual( | |
| 1669 | 1671 | util.inspect(Object.setPrototypeOf(value, null)), | |
@@ -1707,6 +1709,50 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1707 | 1709 | assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res); | |
| 1708 | 1710 | }); | |
| 1709 | 1711 | ||
| 1712 | + // Date null prototype checks | ||
| 1713 | + { | ||
| 1714 | + class CustomDate extends Date { | ||
| 1715 | + } | ||
| 1716 | + | ||
| 1717 | + const date = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); | ||
| 1718 | + assert.strictEqual(util.inspect(date), 'CustomDate 2010-02-14T11:48:40.000Z'); | ||
| 1719 | + | ||
| 1720 | + // add properties | ||
| 1721 | + date.foo = 'bar'; | ||
| 1722 | + assert.strictEqual(util.inspect(date), | ||
| 1723 | + '{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }'); | ||
| 1724 | + | ||
| 1725 | + // check for null prototype | ||
| 1726 | + Object.setPrototypeOf(date, null); | ||
| 1727 | + assert.strictEqual(util.inspect(date), | ||
| 1728 | + '{ [Date: null prototype] 2010-02-14T11:48:40.000Z' + | ||
| 1729 | + ' foo: \'bar\' }'); | ||
| 1730 | + | ||
| 1731 | + const anotherDate = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); | ||
| 1732 | + Object.setPrototypeOf(anotherDate, null); | ||
| 1733 | + assert.strictEqual(util.inspect(anotherDate), | ||
| 1734 | + '[Date: null prototype] 2010-02-14T11:48:40.000Z'); | ||
| 1735 | + } | ||
| 1736 | + | ||
| 1737 | + // Check for invalid dates and null prototype | ||
| 1738 | + { | ||
| 1739 | + class CustomDate extends Date { | ||
| 1740 | + } | ||
| 1741 | + | ||
| 1742 | + const date = new CustomDate('invalid_date'); | ||
| 1743 | + assert.strictEqual(util.inspect(date), 'CustomDate Invalid Date'); | ||
| 1744 | + | ||
| 1745 | + // add properties | ||
| 1746 | + date.foo = 'bar'; | ||
| 1747 | + assert.strictEqual(util.inspect(date), | ||
| 1748 | + '{ CustomDate Invalid Date foo: \'bar\' }'); | ||
| 1749 | + | ||
| 1750 | + // check for null prototype | ||
| 1751 | + Object.setPrototypeOf(date, null); | ||
| 1752 | + assert.strictEqual(util.inspect(date), | ||
| 1753 | + '{ [Date: null prototype] Invalid Date foo: \'bar\' }'); | ||
| 1754 | + } | ||
| 1755 | + | ||
| 1710 | 1756 | assert.strictEqual(inspect(1n), '1n'); | |
| 1711 | 1757 | assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]'); | |
| 1712 | 1758 | assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments