diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-12-13 05:23:16 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-09 01:34:25 +0100 |
commit | aa07dd6248764006d1b201700a18173250b281de (patch) | |
tree | 953c4b286c4b14ef46a42c562775dc02e967e0f4 /test | |
parent | 8d893f213dfd73f960bbf9999cf973b05baad135 (diff) | |
download | android-node-v8-aa07dd6248764006d1b201700a18173250b281de.tar.gz android-node-v8-aa07dd6248764006d1b201700a18173250b281de.tar.bz2 android-node-v8-aa07dd6248764006d1b201700a18173250b281de.zip |
util: inspect ArrayBuffers contents as well
Inspecting an ArrayBuffer now also shows their binary contents.
PR-URL: https://github.com/nodejs/node/pull/25006
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-util-format-shared-arraybuffer.js | 6 | ||||
-rw-r--r-- | test/parallel/test-util-format.js | 5 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 55 |
3 files changed, 41 insertions, 25 deletions
diff --git a/test/parallel/test-util-format-shared-arraybuffer.js b/test/parallel/test-util-format-shared-arraybuffer.js deleted file mode 100644 index 27dfad3c91..0000000000 --- a/test/parallel/test-util-format-shared-arraybuffer.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; -require('../common'); -const assert = require('assert'); -const util = require('util'); -const sab = new SharedArrayBuffer(4); -assert.strictEqual(util.format(sab), 'SharedArrayBuffer { byteLength: 4 }'); diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index 9d6b43a52d..5dab017756 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -341,3 +341,8 @@ assert.strictEqual( '\u001b[1mnull\u001b[22m ' + 'foobar' ); + +assert.strictEqual( + util.format(new SharedArrayBuffer(4)), + 'SharedArrayBuffer { [Uint8Contents]: <00 00 00 00>, byteLength: 4 }' +); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index cf7f974268..e001273409 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -115,70 +115,86 @@ assert(!/Object/.test( util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true) )); -for (const showHidden of [true, false]) { - const ab = new ArrayBuffer(4); +{ + const showHidden = true; + const ab = new Uint8Array([1, 2, 3, 4]).buffer; const dv = new DataView(ab, 1, 2); assert.strictEqual( util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4 }' + 'ArrayBuffer { [Uint8Contents]: <01 02 03 04>, byteLength: 4 }' ); assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: ' + + '<01 02 03 04>, byteLength: 4 } }'); assert.strictEqual( util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4 }' + 'ArrayBuffer { [Uint8Contents]: <01 02 03 04>, byteLength: 4 }' ); assert.strictEqual(util.inspect(dv, showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: ' + + '<01 02 03 04>, byteLength: 4 } }'); ab.x = 42; dv.y = 1337; assert.strictEqual(util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4, x: 42 }'); + 'ArrayBuffer { [Uint8Contents]: <01 02 03 04>, ' + + 'byteLength: 4, x: 42 }'); assert.strictEqual(util.inspect(dv, showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4, x: 42 },\n' + + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: <01 02 03 04>, ' + + 'byteLength: 4, x: 42 },\n' + ' y: 1337 }'); } // Now do the same checks but from a different context. -for (const showHidden of [true, false]) { +{ + const showHidden = false; const ab = vm.runInNewContext('new ArrayBuffer(4)'); const dv = vm.runInNewContext('new DataView(ab, 1, 2)', { ab }); assert.strictEqual( util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4 }' + 'ArrayBuffer { [Uint8Contents]: <00 00 00 00>, byteLength: 4 }' ); assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: <00 00 00 00>, ' + + 'byteLength: 4 } }'); assert.strictEqual( util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4 }' + 'ArrayBuffer { [Uint8Contents]: <00 00 00 00>, byteLength: 4 }' ); assert.strictEqual(util.inspect(dv, showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: <00 00 00 00>, ' + + 'byteLength: 4 } }'); ab.x = 42; dv.y = 1337; assert.strictEqual(util.inspect(ab, showHidden), - 'ArrayBuffer { byteLength: 4, x: 42 }'); + 'ArrayBuffer { [Uint8Contents]: <00 00 00 00>, ' + + 'byteLength: 4, x: 42 }'); assert.strictEqual(util.inspect(dv, showHidden), 'DataView {\n' + ' byteLength: 2,\n' + ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4, x: 42 },\n' + + ' buffer:\n' + + ' ArrayBuffer { [Uint8Contents]: <00 00 00 00>,' + + ' byteLength: 4, x: 42 },\n' + ' y: 1337 }'); } @@ -1639,13 +1655,14 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); [new Float64Array(2), '[Float64Array: null prototype] [ 0, 0 ]'], [new BigInt64Array(2), '[BigInt64Array: null prototype] [ 0n, 0n ]'], [new BigUint64Array(2), '[BigUint64Array: null prototype] [ 0n, 0n ]'], - [new ArrayBuffer(16), '[ArrayBuffer: null prototype] ' + - '{ byteLength: undefined }'], + [new ArrayBuffer(16), '[ArrayBuffer: null prototype] {\n' + + ' [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,\n' + + ' byteLength: undefined }'], [new DataView(new ArrayBuffer(16)), '[DataView: null prototype] {\n byteLength: undefined,\n ' + - 'byteOffset: undefined,\n buffer: undefined }'], + 'byteOffset: undefined,\n buffer: undefined }'], [new SharedArrayBuffer(2), '[SharedArrayBuffer: null prototype] ' + - '{ byteLength: undefined }'], + '{ [Uint8Contents]: <00 00>, byteLength: undefined }'], [/foobar/, '[RegExp: null prototype] /foobar/'] ].forEach(([value, expected]) => { assert.strictEqual( |