|
25 | 25 | const common = require('../common');
|
26 | 26 | const assert = require('assert');
|
27 | 27 | const { internalBinding } = require('internal/test/binding');
|
28 |
| -const { JSStream } = internalBinding('js_stream'); |
| 28 | +const JSStream = process.binding('js_stream').JSStream; |
29 | 29 | const util = require('util');
|
30 | 30 | const vm = require('vm');
|
31 | 31 | const { previewEntries } = internalBinding('util');
|
@@ -261,15 +261,15 @@ assert.strictEqual(
|
261 | 261 | name: { value: 'Tim', enumerable: true },
|
262 | 262 | hidden: { value: 'secret' }
|
263 | 263 | }), { showHidden: true }),
|
264 |
| - "{ name: 'Tim', [hidden]: 'secret' }" |
| 264 | + "[Object: null prototype] { name: 'Tim', [hidden]: 'secret' }" |
265 | 265 | );
|
266 | 266 |
|
267 | 267 | assert.strictEqual(
|
268 | 268 | util.inspect(Object.create(null, {
|
269 | 269 | name: { value: 'Tim', enumerable: true },
|
270 | 270 | hidden: { value: 'secret' }
|
271 | 271 | })),
|
272 |
| - "{ name: 'Tim' }" |
| 272 | + "[Object: null prototype] { name: 'Tim' }" |
273 | 273 | );
|
274 | 274 |
|
275 | 275 | // Dynamic properties.
|
@@ -505,11 +505,17 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
|
505 | 505 | set: function() {}
|
506 | 506 | }
|
507 | 507 | });
|
508 |
| - assert.strictEqual(util.inspect(getter, true), '{ [a]: [Getter] }'); |
509 |
| - assert.strictEqual(util.inspect(setter, true), '{ [b]: [Setter] }'); |
| 508 | + assert.strictEqual( |
| 509 | + util.inspect(getter, true), |
| 510 | + '[Object: null prototype] { [a]: [Getter] }' |
| 511 | + ); |
| 512 | + assert.strictEqual( |
| 513 | + util.inspect(setter, true), |
| 514 | + '[Object: null prototype] { [b]: [Setter] }' |
| 515 | + ); |
510 | 516 | assert.strictEqual(
|
511 | 517 | util.inspect(getterAndSetter, true),
|
512 |
| - '{ [c]: [Getter/Setter] }' |
| 518 | + '[Object: null prototype] { [c]: [Getter/Setter] }' |
513 | 519 | );
|
514 | 520 | }
|
515 | 521 |
|
@@ -1084,7 +1090,7 @@ if (typeof Symbol !== 'undefined') {
|
1084 | 1090 |
|
1085 | 1091 | {
|
1086 | 1092 | const x = Object.create(null);
|
1087 |
| - assert.strictEqual(util.inspect(x), '{}'); |
| 1093 | + assert.strictEqual(util.inspect(x), '[Object: null prototype] {}'); |
1088 | 1094 | }
|
1089 | 1095 |
|
1090 | 1096 | {
|
@@ -1224,7 +1230,7 @@ util.inspect(process);
|
1224 | 1230 |
|
1225 | 1231 | assert.strictEqual(util.inspect(
|
1226 | 1232 | Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } })),
|
1227 |
| - '[foo] {}'); |
| 1233 | + '[Object: null prototype] [foo] {}'); |
1228 | 1234 |
|
1229 | 1235 | assert.strictEqual(util.inspect(new Foo()), "Foo [bar] { foo: 'bar' }");
|
1230 | 1236 |
|
@@ -1574,20 +1580,12 @@ assert.strictEqual(util.inspect('"\''), '`"\'`');
|
1574 | 1580 | // eslint-disable-next-line no-template-curly-in-string
|
1575 | 1581 | assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
|
1576 | 1582 |
|
1577 |
| -// Verify the output in case the value has no prototype. |
1578 |
| -// Sadly, these cases can not be fully inspected :( |
1579 |
| -[ |
1580 |
| - [/a/, '/undefined/undefined'], |
1581 |
| - [new DataView(new ArrayBuffer(2)), |
1582 |
| - 'DataView {\n byteLength: undefined,\n byteOffset: undefined,\n ' + |
1583 |
| - 'buffer: undefined }'], |
1584 |
| - [new SharedArrayBuffer(2), 'SharedArrayBuffer { byteLength: undefined }'] |
1585 |
| -].forEach(([value, expected]) => { |
| 1583 | +{ |
1586 | 1584 | assert.strictEqual(
|
1587 |
| - util.inspect(Object.setPrototypeOf(value, null)), |
1588 |
| - expected |
| 1585 | + util.inspect(Object.setPrototypeOf(/a/, null)), |
| 1586 | + '/undefined/undefined' |
1589 | 1587 | );
|
1590 |
| -}); |
| 1588 | +} |
1591 | 1589 |
|
1592 | 1590 | // Verify that throwing in valueOf and having no prototype still produces nice
|
1593 | 1591 | // results.
|
@@ -1623,6 +1621,39 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
|
1623 | 1621 | }
|
1624 | 1622 | });
|
1625 | 1623 | assert.strictEqual(util.inspect(value), expected);
|
| 1624 | + value.foo = 'bar'; |
| 1625 | + assert.notStrictEqual(util.inspect(value), expected); |
| 1626 | + delete value.foo; |
| 1627 | + value[Symbol('foo')] = 'yeah'; |
| 1628 | + assert.notStrictEqual(util.inspect(value), expected); |
| 1629 | +}); |
| 1630 | + |
| 1631 | +[ |
| 1632 | + [[1, 3, 4], '[Array: null prototype] [ 1, 3, 4 ]'], |
| 1633 | + [new Set([1, 2]), '[Set: null prototype] { 1, 2 }'], |
| 1634 | + [new Map([[1, 2]]), '[Map: null prototype] { 1 => 2 }'], |
| 1635 | + [new Promise((resolve) => setTimeout(resolve, 10)), |
| 1636 | + '[Promise: null prototype] { <pending> }'], |
| 1637 | + [new WeakSet(), '[WeakSet: null prototype] { <items unknown> }'], |
| 1638 | + [new WeakMap(), '[WeakMap: null prototype] { <items unknown> }'], |
| 1639 | + [new Uint8Array(2), '[Uint8Array: null prototype] [ 0, 0 ]'], |
| 1640 | + [new Uint16Array(2), '[Uint16Array: null prototype] [ 0, 0 ]'], |
| 1641 | + [new Uint32Array(2), '[Uint32Array: null prototype] [ 0, 0 ]'], |
| 1642 | + [new Int8Array(2), '[Int8Array: null prototype] [ 0, 0 ]'], |
| 1643 | + [new Int16Array(2), '[Int16Array: null prototype] [ 0, 0 ]'], |
| 1644 | + [new Int32Array(2), '[Int32Array: null prototype] [ 0, 0 ]'], |
| 1645 | + [new Float32Array(2), '[Float32Array: null prototype] [ 0, 0 ]'], |
| 1646 | + [new Float64Array(2), '[Float64Array: null prototype] [ 0, 0 ]'], |
| 1647 | + [new BigInt64Array(2), '[BigInt64Array: null prototype] [ 0n, 0n ]'], |
| 1648 | + [new BigUint64Array(2), '[BigUint64Array: null prototype] [ 0n, 0n ]'], |
| 1649 | + [new ArrayBuffer(16), '[ArrayBuffer: null prototype] ' + |
| 1650 | + '{ byteLength: undefined }'], |
| 1651 | + [new DataView(new ArrayBuffer(16)), |
| 1652 | + '[DataView: null prototype] {\n byteLength: undefined,\n ' + |
| 1653 | + 'byteOffset: undefined,\n buffer: undefined }'], |
| 1654 | + [new SharedArrayBuffer(2), '[SharedArrayBuffer: null prototype] ' + |
| 1655 | + '{ byteLength: undefined }'] |
| 1656 | +].forEach(([value, expected]) => { |
1626 | 1657 | assert.strictEqual(
|
1627 | 1658 | util.inspect(Object.setPrototypeOf(value, null)),
|
1628 | 1659 | expected
|
@@ -1706,3 +1737,30 @@ assert.strictEqual(
|
1706 | 1737 | '[ 3, 2, 1, [Symbol(a)]: false, [Symbol(b)]: true, a: 1, b: 2, c: 3 ]'
|
1707 | 1738 | );
|
1708 | 1739 | }
|
| 1740 | + |
| 1741 | +// Manipulate the prototype to one that we can not handle. |
| 1742 | +{ |
| 1743 | + let obj = { a: true }; |
| 1744 | + let value = (function() { return function() {}; })(); |
| 1745 | + Object.setPrototypeOf(value, null); |
| 1746 | + Object.setPrototypeOf(obj, value); |
| 1747 | + assert.strictEqual(util.inspect(obj), '{ a: true }'); |
| 1748 | + |
| 1749 | + obj = { a: true }; |
| 1750 | + value = []; |
| 1751 | + Object.setPrototypeOf(value, null); |
| 1752 | + Object.setPrototypeOf(obj, value); |
| 1753 | + assert.strictEqual(util.inspect(obj), '{ a: true }'); |
| 1754 | +} |
| 1755 | + |
| 1756 | +// Check that the fallback always works. |
| 1757 | +{ |
| 1758 | + const obj = new Set([1, 2]); |
| 1759 | + const iterator = obj[Symbol.iterator]; |
| 1760 | + Object.setPrototypeOf(obj, null); |
| 1761 | + Object.defineProperty(obj, Symbol.iterator, { |
| 1762 | + value: iterator, |
| 1763 | + configurable: true |
| 1764 | + }); |
| 1765 | + assert.strictEqual(util.inspect(obj), '[Set: null prototype] { 1, 2 }'); |
| 1766 | +} |
0 commit comments