| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,24 +45,26 @@ assert.equal(util.inspect(Object.create({}, | |||
| 45 | 45 | // the following ways this hash is displayed. | |
| 46 | 46 | // See http://codereview.chromium.org/9124004/ | |
| 47 | 47 | ||
| 48 | - var out = util.inspect(Object.create({}, | ||
| 49 | - {visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true); | ||
| 50 | - if (out !== '{ [hidden]: 2, visible: 1 }' && | ||
| 51 | - out !== '{ visible: 1, [hidden]: 2 }') { | ||
| 52 | - assert.ok(false); | ||
| 48 | + { | ||
| 49 | + const out = util.inspect(Object.create({}, | ||
| 50 | + {visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true); | ||
| 51 | + if (out !== '{ [hidden]: 2, visible: 1 }' && | ||
| 52 | + out !== '{ visible: 1, [hidden]: 2 }') { | ||
| 53 | + assert.ok(false); | ||
| 54 | + } | ||
| 53 | 55 | } | |
| 54 | 56 | ||
| 55 | - | ||
| 56 | 57 | // Objects without prototype | |
| 57 | - var out = util.inspect(Object.create(null, | ||
| 58 | - { name: {value: 'Tim', enumerable: true}, | ||
| 59 | - hidden: {value: 'secret'}}), true); | ||
| 60 | - if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && | ||
| 61 | - out !== "{ name: 'Tim', [hidden]: 'secret' }") { | ||
| 62 | - assert(false); | ||
| 58 | + { | ||
| 59 | + const out = util.inspect(Object.create(null, | ||
| 60 | + { name: {value: 'Tim', enumerable: true}, | ||
| 61 | + hidden: {value: 'secret'}}), true); | ||
| 62 | + if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && | ||
| 63 | + out !== "{ name: 'Tim', [hidden]: 'secret' }") { | ||
| 64 | + assert(false); | ||
| 65 | + } | ||
| 63 | 66 | } | |
| 64 | 67 | ||
| 65 | - | ||
| 66 | 68 | assert.equal( | |
| 67 | 69 | util.inspect(Object.create(null, | |
| 68 | 70 | {name: {value: 'Tim', enumerable: true}, | |
@@ -129,17 +131,19 @@ assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]'); | |||
| 129 | 131 | assert.equal(util.inspect(new Array(5)), '[ , , , , ]'); | |
| 130 | 132 | ||
| 131 | 133 | // test for Array constructor in different context | |
| 132 | - const Debug = require('vm').runInDebugContext('Debug'); | ||
| 133 | - var map = new Map(); | ||
| 134 | - map.set(1, 2); | ||
| 135 | - var mirror = Debug.MakeMirror(map.entries(), true); | ||
| 136 | - var vals = mirror.preview(); | ||
| 137 | - var valsOutput = []; | ||
| 138 | - for (const o of vals) { | ||
| 139 | - valsOutput.push(o); | ||
| 140 | - } | ||
| 134 | + { | ||
| 135 | + const Debug = require('vm').runInDebugContext('Debug'); | ||
| 136 | + const map = new Map(); | ||
| 137 | + map.set(1, 2); | ||
| 138 | + const mirror = Debug.MakeMirror(map.entries(), true); | ||
| 139 | + const vals = mirror.preview(); | ||
| 140 | + const valsOutput = []; | ||
| 141 | + for (const o of vals) { | ||
| 142 | + valsOutput.push(o); | ||
| 143 | + } | ||
| 141 | 144 | ||
| 142 | - assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); | ||
| 145 | + assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); | ||
| 146 | + } | ||
| 143 | 147 | ||
| 144 | 148 | // test for other constructors in different context | |
| 145 | 149 | var obj = require('vm').runInNewContext('(function(){return {}})()', {}); | |
@@ -212,8 +216,10 @@ assert.doesNotThrow(function() { | |||
| 212 | 216 | }); | |
| 213 | 217 | ||
| 214 | 218 | // GH-2225 | |
| 215 | - var x = { inspect: util.inspect }; | ||
| 216 | - assert.ok(util.inspect(x).indexOf('inspect') != -1); | ||
| 219 | + { | ||
| 220 | + const x = { inspect: util.inspect }; | ||
| 221 | + assert.ok(util.inspect(x).indexOf('inspect') != -1); | ||
| 222 | + } | ||
| 217 | 223 | ||
| 218 | 224 | // util.inspect should not display the escaped value of a key. | |
| 219 | 225 | var w = { | |
@@ -261,39 +267,41 @@ assert.doesNotThrow(function() { | |||
| 261 | 267 | }); | |
| 262 | 268 | ||
| 263 | 269 | // new API, accepts an "options" object | |
| 264 | - var subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } }; | ||
| 265 | - Object.defineProperty(subject, 'hidden', { enumerable: false, value: null }); | ||
| 266 | - | ||
| 267 | - assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1); | ||
| 268 | - assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1); | ||
| 269 | - assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1); | ||
| 270 | - assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1); | ||
| 271 | - assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1); | ||
| 272 | - assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1); | ||
| 273 | - assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1); | ||
| 274 | - | ||
| 275 | - // "customInspect" option can enable/disable calling inspect() on objects | ||
| 276 | - subject = { inspect: function() { return 123; } }; | ||
| 277 | - | ||
| 278 | - assert(util.inspect(subject, | ||
| 279 | - { customInspect: true }).indexOf('123') !== -1); | ||
| 280 | - assert(util.inspect(subject, | ||
| 281 | - { customInspect: true }).indexOf('inspect') === -1); | ||
| 282 | - assert(util.inspect(subject, | ||
| 283 | - { customInspect: false }).indexOf('123') === -1); | ||
| 284 | - assert(util.inspect(subject, | ||
| 285 | - { customInspect: false }).indexOf('inspect') !== -1); | ||
| 286 | - | ||
| 287 | - // custom inspect() functions should be able to return other Objects | ||
| 288 | - subject.inspect = function() { return { foo: 'bar' }; }; | ||
| 289 | - | ||
| 290 | - assert.equal(util.inspect(subject), '{ foo: \'bar\' }'); | ||
| 291 | - | ||
| 292 | - subject.inspect = function(depth, opts) { | ||
| 293 | - assert.strictEqual(opts.customInspectOptions, true); | ||
| 294 | - }; | ||
| 270 | + { | ||
| 271 | + let subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } }; | ||
| 272 | + Object.defineProperty(subject, 'hidden', { enumerable: false, value: null }); | ||
| 273 | + | ||
| 274 | + assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1); | ||
| 275 | + assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1); | ||
| 276 | + assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1); | ||
| 277 | + assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1); | ||
| 278 | + assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1); | ||
| 279 | + assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1); | ||
| 280 | + assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1); | ||
| 281 | + | ||
| 282 | + // "customInspect" option can enable/disable calling inspect() on objects | ||
| 283 | + subject = { inspect: function() { return 123; } }; | ||
| 284 | + | ||
| 285 | + assert(util.inspect(subject, | ||
| 286 | + { customInspect: true }).indexOf('123') !== -1); | ||
| 287 | + assert(util.inspect(subject, | ||
| 288 | + { customInspect: true }).indexOf('inspect') === -1); | ||
| 289 | + assert(util.inspect(subject, | ||
| 290 | + { customInspect: false }).indexOf('123') === -1); | ||
| 291 | + assert(util.inspect(subject, | ||
| 292 | + { customInspect: false }).indexOf('inspect') !== -1); | ||
| 293 | + | ||
| 294 | + // custom inspect() functions should be able to return other Objects | ||
| 295 | + subject.inspect = function() { return { foo: 'bar' }; }; | ||
| 296 | + | ||
| 297 | + assert.equal(util.inspect(subject), '{ foo: \'bar\' }'); | ||
| 298 | + | ||
| 299 | + subject.inspect = function(depth, opts) { | ||
| 300 | + assert.strictEqual(opts.customInspectOptions, true); | ||
| 301 | + }; | ||
| 295 | 302 | ||
| 296 | - util.inspect(subject, { customInspectOptions: true }); | ||
| 303 | + util.inspect(subject, { customInspectOptions: true }); | ||
| 304 | + } | ||
| 297 | 305 | ||
| 298 | 306 | // util.inspect with "colors" option should produce as many lines as without it | |
| 299 | 307 | function test_lines(input) { | |
@@ -353,8 +361,8 @@ if (typeof Symbol !== 'undefined') { | |||
| 353 | 361 | assert.equal(util.inspect([Symbol()]), '[ Symbol() ]'); | |
| 354 | 362 | assert.equal(util.inspect({ foo: Symbol() }), '{ foo: Symbol() }'); | |
| 355 | 363 | ||
| 356 | - var options = { showHidden: true }; | ||
| 357 | - var subject = {}; | ||
| 364 | + const options = { showHidden: true }; | ||
| 365 | + let subject = {}; | ||
| 358 | 366 | ||
| 359 | 367 | subject[Symbol('symbol')] = 42; | |
| 360 | 368 | ||
@@ -367,7 +375,6 @@ if (typeof Symbol !== 'undefined') { | |||
| 367 | 375 | assert.equal(util.inspect(subject), '[ 1, 2, 3 ]'); | |
| 368 | 376 | assert.equal(util.inspect(subject, options), | |
| 369 | 377 | '[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]'); | |
| 370 | - | ||
| 371 | 378 | } | |
| 372 | 379 | ||
| 373 | 380 | // test Set | |
@@ -378,13 +385,15 @@ set.bar = 42; | |||
| 378 | 385 | assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }'); | |
| 379 | 386 | ||
| 380 | 387 | // test Map | |
| 381 | - assert.equal(util.inspect(new Map()), 'Map {}'); | ||
| 382 | - assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), | ||
| 383 | - 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }'); | ||
| 384 | - var map = new Map([['foo', null]]); | ||
| 385 | - map.bar = 42; | ||
| 386 | - assert.equal(util.inspect(map, true), | ||
| 387 | - 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); | ||
| 388 | + { | ||
| 389 | + assert.equal(util.inspect(new Map()), 'Map {}'); | ||
| 390 | + assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), | ||
| 391 | + 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }'); | ||
| 392 | + const map = new Map([['foo', null]]); | ||
| 393 | + map.bar = 42; | ||
| 394 | + assert.equal(util.inspect(map, true), | ||
| 395 | + 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); | ||
| 396 | + } | ||
| 388 | 397 | ||
| 389 | 398 | // test Promise | |
| 390 | 399 | assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }'); | |
@@ -457,41 +466,50 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; }))); | |||
| 457 | 466 | ||
| 458 | 467 | ||
| 459 | 468 | // Test display of constructors | |
| 460 | - | ||
| 461 | - class ObjectSubclass {} | ||
| 462 | - class ArraySubclass extends Array {} | ||
| 463 | - class SetSubclass extends Set {} | ||
| 464 | - class MapSubclass extends Map {} | ||
| 465 | - class PromiseSubclass extends Promise {} | ||
| 466 | - | ||
| 467 | - var x = new ObjectSubclass(); | ||
| 468 | - x.foo = 42; | ||
| 469 | - assert.equal(util.inspect(x), | ||
| 470 | - 'ObjectSubclass { foo: 42 }'); | ||
| 471 | - assert.equal(util.inspect(new ArraySubclass(1, 2, 3)), | ||
| 472 | - 'ArraySubclass [ 1, 2, 3 ]'); | ||
| 473 | - assert.equal(util.inspect(new SetSubclass([1, 2, 3])), | ||
| 474 | - 'SetSubclass { 1, 2, 3 }'); | ||
| 475 | - assert.equal(util.inspect(new MapSubclass([['foo', 42]])), | ||
| 476 | - 'MapSubclass { \'foo\' => 42 }'); | ||
| 477 | - assert.equal(util.inspect(new PromiseSubclass(function() {})), | ||
| 478 | - 'PromiseSubclass { <pending> }'); | ||
| 469 | + { | ||
| 470 | + class ObjectSubclass {} | ||
| 471 | + class ArraySubclass extends Array {} | ||
| 472 | + class SetSubclass extends Set {} | ||
| 473 | + class MapSubclass extends Map {} | ||
| 474 | + class PromiseSubclass extends Promise {} | ||
| 475 | + | ||
| 476 | + const x = new ObjectSubclass(); | ||
| 477 | + x.foo = 42; | ||
| 478 | + assert.equal(util.inspect(x), | ||
| 479 | + 'ObjectSubclass { foo: 42 }'); | ||
| 480 | + assert.equal(util.inspect(new ArraySubclass(1, 2, 3)), | ||
| 481 | + 'ArraySubclass [ 1, 2, 3 ]'); | ||
| 482 | + assert.equal(util.inspect(new SetSubclass([1, 2, 3])), | ||
| 483 | + 'SetSubclass { 1, 2, 3 }'); | ||
| 484 | + assert.equal(util.inspect(new MapSubclass([['foo', 42]])), | ||
| 485 | + 'MapSubclass { \'foo\' => 42 }'); | ||
| 486 | + assert.equal(util.inspect(new PromiseSubclass(function() {})), | ||
| 487 | + 'PromiseSubclass { <pending> }'); | ||
| 488 | + } | ||
| 479 | 489 | ||
| 480 | 490 | // Corner cases. | |
| 481 | - var x = { constructor: 42 }; | ||
| 482 | - assert.equal(util.inspect(x), '{ constructor: 42 }'); | ||
| 483 | - | ||
| 484 | - var x = {}; | ||
| 485 | - Object.defineProperty(x, 'constructor', { | ||
| 486 | - get: function() { | ||
| 487 | - throw new Error('should not access constructor'); | ||
| 488 | - }, | ||
| 489 | - enumerable: true | ||
| 490 | - }); | ||
| 491 | - assert.equal(util.inspect(x), '{ constructor: [Getter] }'); | ||
| 491 | + { | ||
| 492 | + const x = { constructor: 42 }; | ||
| 493 | + assert.equal(util.inspect(x), '{ constructor: 42 }'); | ||
| 494 | + } | ||
| 492 | 495 | ||
| 493 | - var x = new (function() {}); | ||
| 494 | - assert.equal(util.inspect(x), '{}'); | ||
| 496 | + { | ||
| 497 | + const x = {}; | ||
| 498 | + Object.defineProperty(x, 'constructor', { | ||
| 499 | + get: function() { | ||
| 500 | + throw new Error('should not access constructor'); | ||
| 501 | + }, | ||
| 502 | + enumerable: true | ||
| 503 | + }); | ||
| 504 | + assert.equal(util.inspect(x), '{ constructor: [Getter] }'); | ||
| 505 | + } | ||
| 495 | 506 | ||
| 496 | - var x = Object.create(null); | ||
| 497 | - assert.equal(util.inspect(x), '{}'); | ||
| 507 | + { | ||
| 508 | + const x = new (function() {}); | ||
| 509 | + assert.equal(util.inspect(x), '{}'); | ||
| 510 | + } | ||
| 511 | + | ||
| 512 | + { | ||
| 513 | + const x = Object.create(null); | ||
| 514 | + assert.equal(util.inspect(x), '{}'); | ||
| 515 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments