| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 58af085 commit 73f3a1c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -634,9 +634,12 @@ function formatRaw(ctx, value, recurseTimes) { | |||
| 634 | 634 | base = `[${name}]`; | |
| 635 | 635 | } else if (isRegExp(value)) { | |
| 636 | 636 | // Make RegExps say that they are RegExps | |
| 637 | + base = regExpToString(constructor !== null ? value : new RegExp(value)); | ||
| 638 | + const prefix = getPrefix(constructor, tag, 'RegExp'); | ||
| 639 | + if (prefix !== 'RegExp ') | ||
| 640 | + base = `${prefix}${base}`; | ||
| 637 | 641 | if (keys.length === 0 || recurseTimes < 0) | |
| 638 | - return ctx.stylize(regExpToString(value), 'regexp'); | ||
| 639 | - base = `${regExpToString(value)}`; | ||
| 642 | + return ctx.stylize(base, 'regexp'); | ||
| 640 | 643 | } else if (isDate(value)) { | |
| 641 | 644 | // Make dates with properties first say the date | |
| 642 | 645 | if (keys.length === 0) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ assert.throws( | |||
| 149 | 149 | { | |
| 150 | 150 | code: 'ERR_ASSERTION', | |
| 151 | 151 | message: `${defaultMsgStartFull}\n\n` + | |
| 152 | - "+ /test/\n- /test/ {\n- '0': '1'\n- }" | ||
| 152 | + "+ /test/\n- MyRegExp /test/ {\n- '0': '1'\n- }" | ||
| 153 | 153 | } | |
| 154 | 154 | ); | |
| 155 | 155 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1580,15 +1580,7 @@ assert.strictEqual(util.inspect('"\''), '`"\'`'); | |||
| 1580 | 1580 | // eslint-disable-next-line no-template-curly-in-string | |
| 1581 | 1581 | assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |
| 1582 | 1582 | ||
| 1583 | - { | ||
| 1584 | - assert.strictEqual( | ||
| 1585 | - util.inspect(Object.setPrototypeOf(/a/, null)), | ||
| 1586 | - '/undefined/undefined' | ||
| 1587 | - ); | ||
| 1588 | - } | ||
| 1589 | - | ||
| 1590 | - // Verify that throwing in valueOf and having no prototype still produces nice | ||
| 1591 | - // results. | ||
| 1583 | + // Verify that throwing in valueOf and toString still produces nice results. | ||
| 1592 | 1584 | [ | |
| 1593 | 1585 | [new String(55), "[String: '55']"], | |
| 1594 | 1586 | [new Boolean(true), '[Boolean: true]'], | |
@@ -1609,6 +1601,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1609 | 1601 | [new Promise((resolve) => setTimeout(resolve, 10)), 'Promise { <pending> }'], | |
| 1610 | 1602 | [new WeakSet(), 'WeakSet { <items unknown> }'], | |
| 1611 | 1603 | [new WeakMap(), 'WeakMap { <items unknown> }'], | |
| 1604 | + [/foobar/g, '/foobar/g'] | ||
| 1612 | 1605 | ].forEach(([value, expected]) => { | |
| 1613 | 1606 | Object.defineProperty(value, 'valueOf', { | |
| 1614 | 1607 | get() { | |
@@ -1628,6 +1621,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1628 | 1621 | assert.notStrictEqual(util.inspect(value), expected); | |
| 1629 | 1622 | }); | |
| 1630 | 1623 | ||
| 1624 | + // Verify that having no prototype still produces nice results. | ||
| 1631 | 1625 | [ | |
| 1632 | 1626 | [[1, 3, 4], '[Array: null prototype] [ 1, 3, 4 ]'], | |
| 1633 | 1627 | [new Set([1, 2]), '[Set: null prototype] { 1, 2 }'], | |
@@ -1652,7 +1646,8 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1652 | 1646 | '[DataView: null prototype] {\n byteLength: undefined,\n ' + | |
| 1653 | 1647 | 'byteOffset: undefined,\n buffer: undefined }'], | |
| 1654 | 1648 | [new SharedArrayBuffer(2), '[SharedArrayBuffer: null prototype] ' + | |
| 1655 | - '{ byteLength: undefined }'] | ||
| 1649 | + '{ byteLength: undefined }'], | ||
| 1650 | + [/foobar/, '[RegExp: null prototype] /foobar/'] | ||
| 1656 | 1651 | ].forEach(([value, expected]) => { | |
| 1657 | 1652 | assert.strictEqual( | |
| 1658 | 1653 | util.inspect(Object.setPrototypeOf(value, null)), | |
@@ -1665,6 +1660,34 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); | |||
| 1665 | 1660 | assert.notStrictEqual(util.inspect(value), expected); | |
| 1666 | 1661 | }); | |
| 1667 | 1662 | ||
| 1663 | + // Verify that subclasses with and without prototype produce nice results. | ||
| 1664 | + [ | ||
| 1665 | + [RegExp, ['foobar', 'g'], '/foobar/g'] | ||
| 1666 | + ].forEach(([base, input, rawExpected]) => { | ||
| 1667 | + class Foo extends base {} | ||
| 1668 | + const value = new Foo(...input); | ||
| 1669 | + const symbol = value[Symbol.toStringTag]; | ||
| 1670 | + const expected = `Foo ${symbol ? `[${symbol}] ` : ''}${rawExpected}`; | ||
| 1671 | + const expectedWithoutProto = `[${base.name}: null prototype] ${rawExpected}`; | ||
| 1672 | + assert.strictEqual(util.inspect(value), expected); | ||
| 1673 | + value.foo = 'bar'; | ||
| 1674 | + assert.notStrictEqual(util.inspect(value), expected); | ||
| 1675 | + delete value.foo; | ||
| 1676 | + assert.strictEqual( | ||
| 1677 | + util.inspect(Object.setPrototypeOf(value, null)), | ||
| 1678 | + expectedWithoutProto | ||
| 1679 | + ); | ||
| 1680 | + value.foo = 'bar'; | ||
| 1681 | + let res = util.inspect(value); | ||
| 1682 | + assert.notStrictEqual(res, expectedWithoutProto); | ||
| 1683 | + assert(/foo: 'bar'/.test(res), res); | ||
| 1684 | + delete value.foo; | ||
| 1685 | + value[Symbol('foo')] = 'yeah'; | ||
| 1686 | + res = util.inspect(value); | ||
| 1687 | + assert.notStrictEqual(res, expectedWithoutProto); | ||
| 1688 | + assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res); | ||
| 1689 | + }); | ||
| 1690 | + | ||
| 1668 | 1691 | assert.strictEqual(inspect(1n), '1n'); | |
| 1669 | 1692 | assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]'); | |
| 1670 | 1693 | assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments