| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 134ed0e commit a90c9aa
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -514,54 +514,53 @@ function makeTextDecoderJS() { | |||
| 514 | 514 | } | |
| 515 | 515 | ||
| 516 | 516 | // Mix in some shared properties. | |
| 517 | - { | ||
| 518 | - ObjectDefineProperties( | ||
| 519 | - TextDecoder.prototype, | ||
| 520 | - ObjectGetOwnPropertyDescriptors({ | ||
| 521 | - get encoding() { | ||
| 522 | - validateDecoder(this); | ||
| 523 | - return this[kEncoding]; | ||
| 524 | - }, | ||
| 525 | - | ||
| 526 | - get fatal() { | ||
| 527 | - validateDecoder(this); | ||
| 528 | - return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL; | ||
| 529 | - }, | ||
| 530 | - | ||
| 531 | - get ignoreBOM() { | ||
| 532 | - validateDecoder(this); | ||
| 533 | - return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) === | ||
| 534 | - CONVERTER_FLAGS_IGNORE_BOM; | ||
| 535 | - }, | ||
| 536 | - | ||
| 537 | - [inspect](depth, opts) { | ||
| 538 | - validateDecoder(this); | ||
| 539 | - if (typeof depth === 'number' && depth < 0) | ||
| 540 | - return this; | ||
| 541 | - const ctor = getConstructorOf(this); | ||
| 542 | - const obj = ObjectCreate({ | ||
| 543 | - constructor: ctor === null ? TextDecoder : ctor | ||
| 544 | - }); | ||
| 545 | - obj.encoding = this.encoding; | ||
| 546 | - obj.fatal = this.fatal; | ||
| 547 | - obj.ignoreBOM = this.ignoreBOM; | ||
| 548 | - if (opts.showHidden) { | ||
| 549 | - obj[kFlags] = this[kFlags]; | ||
| 550 | - obj[kHandle] = this[kHandle]; | ||
| 551 | - } | ||
| 552 | - // Lazy to avoid circular dependency | ||
| 553 | - return require('internal/util/inspect').inspect(obj, opts); | ||
| 517 | + ObjectDefineProperties( | ||
| 518 | + TextDecoder.prototype, | ||
| 519 | + ObjectGetOwnPropertyDescriptors({ | ||
| 520 | + get encoding() { | ||
| 521 | + validateDecoder(this); | ||
| 522 | + return this[kEncoding]; | ||
| 523 | + }, | ||
| 524 | + | ||
| 525 | + get fatal() { | ||
| 526 | + validateDecoder(this); | ||
| 527 | + return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL; | ||
| 528 | + }, | ||
| 529 | + | ||
| 530 | + get ignoreBOM() { | ||
| 531 | + validateDecoder(this); | ||
| 532 | + return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) === | ||
| 533 | + CONVERTER_FLAGS_IGNORE_BOM; | ||
| 534 | + }, | ||
| 535 | + | ||
| 536 | + [inspect](depth, opts) { | ||
| 537 | + validateDecoder(this); | ||
| 538 | + if (typeof depth === 'number' && depth < 0) | ||
| 539 | + return this; | ||
| 540 | + const constructor = getConstructorOf(this) || TextDecoder; | ||
| 541 | + const obj = ObjectCreate({ constructor }); | ||
| 542 | + obj.encoding = this.encoding; | ||
| 543 | + obj.fatal = this.fatal; | ||
| 544 | + obj.ignoreBOM = this.ignoreBOM; | ||
| 545 | + if (opts.showHidden) { | ||
| 546 | + obj[kFlags] = this[kFlags]; | ||
| 547 | + obj[kHandle] = this[kHandle]; | ||
| 554 | 548 | } | |
| 555 | - })); | ||
| 556 | - ObjectDefineProperties(TextDecoder.prototype, { | ||
| 557 | - decode: { enumerable: true }, | ||
| 558 | - [inspect]: { enumerable: false }, | ||
| 559 | - [SymbolToStringTag]: { | ||
| 560 | - configurable: true, | ||
| 561 | - value: 'TextDecoder' | ||
| 549 | + // Lazy to avoid circular dependency | ||
| 550 | + const { inspect } = require('internal/util/inspect'); | ||
| 551 | + return `${constructor.name} ${inspect(obj)}`; | ||
| 562 | 552 | } | |
| 563 | - }); | ||
| 564 | - } | ||
| 553 | + }) | ||
| 554 | + ); | ||
| 555 | + | ||
| 556 | + ObjectDefineProperties(TextDecoder.prototype, { | ||
| 557 | + decode: { enumerable: true }, | ||
| 558 | + [inspect]: { enumerable: false }, | ||
| 559 | + [SymbolToStringTag]: { | ||
| 560 | + configurable: true, | ||
| 561 | + value: 'TextDecoder' | ||
| 562 | + } | ||
| 563 | + }); | ||
| 565 | 564 | ||
| 566 | 565 | module.exports = { | |
| 567 | 566 | getEncodingFromLabel, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -358,11 +358,8 @@ class URL { | |||
| 358 | 358 | if (typeof depth === 'number' && depth < 0) | |
| 359 | 359 | return this; | |
| 360 | 360 | ||
| 361 | - const ctor = getConstructorOf(this); | ||
| 362 | - | ||
| 363 | - const obj = ObjectCreate({ | ||
| 364 | - constructor: ctor === null ? URL : ctor | ||
| 365 | - }); | ||
| 361 | + const constructor = getConstructorOf(this) || URL; | ||
| 362 | + const obj = ObjectCreate({ constructor }); | ||
| 366 | 363 | ||
| 367 | 364 | obj.href = this.href; | |
| 368 | 365 | obj.origin = this.origin; | |
@@ -383,7 +380,7 @@ class URL { | |||
| 383 | 380 | obj[context] = this[context]; | |
| 384 | 381 | } | |
| 385 | 382 | ||
| 386 | - return inspect(obj, opts); | ||
| 383 | + return `${constructor.name} ${inspect(obj, opts)}`; | ||
| 387 | 384 | } | |
| 388 | 385 | } | |
| 389 | 386 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -498,7 +498,8 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) { | |||
| 498 | 498 | const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor'); | |
| 499 | 499 | if (descriptor !== undefined && | |
| 500 | 500 | typeof descriptor.value === 'function' && | |
| 501 | - descriptor.value.name !== '') { | ||
| 501 | + descriptor.value.name !== '' && | ||
| 502 | + tmp instanceof descriptor.value) { | ||
| 502 | 503 | if (protoProps !== undefined && | |
| 503 | 504 | (firstProto !== obj || | |
| 504 | 505 | !builtInObjects.has(descriptor.value.name))) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ const { | |||
| 5 | 5 | ArrayIsArray, | |
| 6 | 6 | ObjectCreate, | |
| 7 | 7 | ObjectDefineProperty, | |
| 8 | + ObjectGetPrototypeOf, | ||
| 9 | + ObjectSetPrototypeOf, | ||
| 8 | 10 | SafePromise, | |
| 9 | 11 | Symbol, | |
| 10 | 12 | WeakMap, | |
@@ -223,17 +225,27 @@ class Module { | |||
| 223 | 225 | } | |
| 224 | 226 | ||
| 225 | 227 | [customInspectSymbol](depth, options) { | |
| 226 | - let ctor = getConstructorOf(this); | ||
| 227 | - ctor = ctor === null ? Module : ctor; | ||
| 228 | - | ||
| 228 | + if (this[kWrap] === undefined) { | ||
| 229 | + throw new ERR_VM_MODULE_NOT_MODULE(); | ||
| 230 | + } | ||
| 229 | 231 | if (typeof depth === 'number' && depth < 0) | |
| 230 | - return options.stylize(`[${ctor.name}]`, 'special'); | ||
| 232 | + return this; | ||
| 231 | 233 | ||
| 232 | - const o = ObjectCreate({ constructor: ctor }); | ||
| 234 | + const constructor = getConstructorOf(this) || Module; | ||
| 235 | + const o = ObjectCreate({ constructor }); | ||
| 233 | 236 | o.status = this.status; | |
| 234 | 237 | o.identifier = this.identifier; | |
| 235 | 238 | o.context = this.context; | |
| 236 | - return require('internal/util/inspect').inspect(o, options); | ||
| 239 | + | ||
| 240 | + ObjectSetPrototypeOf(o, ObjectGetPrototypeOf(this)); | ||
| 241 | + ObjectDefineProperty(o, Symbol.toStringTag, { | ||
| 242 | + value: constructor.name, | ||
| 243 | + configurable: true | ||
| 244 | + }); | ||
| 245 | + | ||
| 246 | + // Lazy to avoid circular dependency | ||
| 247 | + const { inspect } = require('internal/util/inspect'); | ||
| 248 | + return inspect(o, { ...options, customInspect: false }); | ||
| 237 | 249 | } | |
| 238 | 250 | } | |
| 239 | 251 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,7 +266,7 @@ assert.strictEqual( | |||
| 266 | 266 | ' func: <ref *1> [Function: func] {\n' + | |
| 267 | 267 | ' [length]: 0,\n' + | |
| 268 | 268 | ' [name]: \'func\',\n' + | |
| 269 | - ' [prototype]: func { [constructor]: [Circular *1] }\n' + | ||
| 269 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 270 | 270 | ' }\n' + | |
| 271 | 271 | '}'); | |
| 272 | 272 | assert.strictEqual( | |
@@ -279,7 +279,7 @@ assert.strictEqual( | |||
| 279 | 279 | ' a: <ref *1> [Function: a] {\n' + | |
| 280 | 280 | ' [length]: 0,\n' + | |
| 281 | 281 | ' [name]: \'a\',\n' + | |
| 282 | - ' [prototype]: a { [constructor]: [Circular *1] }\n' + | ||
| 282 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 283 | 283 | ' }\n' + | |
| 284 | 284 | ' },\n' + | |
| 285 | 285 | ' [length]: 1\n' + | |
@@ -294,7 +294,7 @@ assert.strictEqual( | |||
| 294 | 294 | ' func: <ref *1> [Function: func] {\n' + | |
| 295 | 295 | ' [length]: 0,\n' + | |
| 296 | 296 | ' [name]: \'func\',\n' + | |
| 297 | - ' [prototype]: func { [constructor]: [Circular *1] }\n' + | ||
| 297 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 298 | 298 | ' }\n' + | |
| 299 | 299 | ' }\n' + | |
| 300 | 300 | '}'); | |
@@ -306,15 +306,15 @@ assert.strictEqual( | |||
| 306 | 306 | ' func: <ref *1> [Function: func] {\n' + | |
| 307 | 307 | ' [length]: 0,\n' + | |
| 308 | 308 | ' [name]: \'func\',\n' + | |
| 309 | - ' [prototype]: func { [constructor]: [Circular *1] }\n' + | ||
| 309 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 310 | 310 | ' }\n' + | |
| 311 | 311 | '} {\n' + | |
| 312 | 312 | ' foo: \'bar\',\n' + | |
| 313 | 313 | ' foobar: 1,\n' + | |
| 314 | 314 | ' func: <ref *1> [Function: func] {\n' + | |
| 315 | 315 | ' [length]: 0,\n' + | |
| 316 | 316 | ' [name]: \'func\',\n' + | |
| 317 | - ' [prototype]: func { [constructor]: [Circular *1] }\n' + | ||
| 317 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 318 | 318 | ' }\n' + | |
| 319 | 319 | '}'); | |
| 320 | 320 | assert.strictEqual( | |
@@ -325,7 +325,7 @@ assert.strictEqual( | |||
| 325 | 325 | ' func: <ref *1> [Function: func] {\n' + | |
| 326 | 326 | ' [length]: 0,\n' + | |
| 327 | 327 | ' [name]: \'func\',\n' + | |
| 328 | - ' [prototype]: func { [constructor]: [Circular *1] }\n' + | ||
| 328 | + ' [prototype]: { [constructor]: [Circular *1] }\n' + | ||
| 329 | 329 | ' }\n' + | |
| 330 | 330 | '} %o'); | |
| 331 | 331 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2827,6 +2827,37 @@ assert.strictEqual( | |||
| 2827 | 2827 | '{ \x1B[2mabc: \x1B[33mtrue\x1B[39m\x1B[22m, ' + | |
| 2828 | 2828 | '\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }' | |
| 2829 | 2829 | ); | |
| 2830 | + | ||
| 2831 | + assert.strictEqual( | ||
| 2832 | + inspect(Object.getPrototypeOf(bar), { showHidden: true, getters: true }), | ||
| 2833 | + '<ref *1> Foo [Map] {\n' + | ||
| 2834 | + ' [constructor]: [class Bar extends Foo] {\n' + | ||
| 2835 | + ' [length]: 0,\n' + | ||
| 2836 | + ' [prototype]: [Circular *1],\n' + | ||
| 2837 | + " [name]: 'Bar',\n" + | ||
| 2838 | + ' [Symbol(Symbol.species)]: [Getter: <Inspection threw ' + | ||
| 2839 | + "(Symbol.prototype.toString requires that 'this' be a Symbol)>]\n" + | ||
| 2840 | + ' },\n' + | ||
| 2841 | + " [xyz]: [Getter: 'YES!'],\n" + | ||
| 2842 | + ' [Symbol(nodejs.util.inspect.custom)]: ' + | ||
| 2843 | + '[Function: [nodejs.util.inspect.custom]] {\n' + | ||
| 2844 | + ' [length]: 0,\n' + | ||
| 2845 | + " [name]: '[nodejs.util.inspect.custom]'\n" + | ||
| 2846 | + ' },\n' + | ||
| 2847 | + ' [abc]: [Getter: true],\n' + | ||
| 2848 | + ' [def]: [Getter/Setter: false]\n' + | ||
| 2849 | + ' }' | ||
| 2850 | + ); | ||
| 2851 | + | ||
| 2852 | + assert.strictEqual( | ||
| 2853 | + inspect(Object.getPrototypeOf(bar)), | ||
| 2854 | + 'Foo [Map] {}' | ||
| 2855 | + ); | ||
| 2856 | + | ||
| 2857 | + assert.strictEqual( | ||
| 2858 | + inspect(Object.getPrototypeOf(new Foo())), | ||
| 2859 | + 'Map {}' | ||
| 2860 | + ); | ||
| 2830 | 2861 | } | |
| 2831 | 2862 | ||
| 2832 | 2863 | // Test changing util.inspect.colors colors and aliases. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,9 +83,12 @@ const util = require('util'); | |||
| 83 | 83 | ||
| 84 | 84 | assert.strictEqual(util.inspect(m, { depth: -1 }), '[SourceTextModule]'); | |
| 85 | 85 | ||
| 86 | - assert.strictEqual( | ||
| 87 | - m[util.inspect.custom].call(Object.create(null)), | ||
| 88 | - 'Module { status: undefined, identifier: undefined, context: undefined }', | ||
| 86 | + assert.throws( | ||
| 87 | + () => m[util.inspect.custom].call(Object.create(null)), | ||
| 88 | + { | ||
| 89 | + code: 'ERR_VM_MODULE_NOT_MODULE', | ||
| 90 | + message: 'Provided module is not an instance of Module' | ||
| 91 | + }, | ||
| 89 | 92 | ); | |
| 90 | 93 | } | |
| 91 | 94 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,6 +85,7 @@ if (common.hasIntl) { | |||
| 85 | 85 | assert.strictEqual(dec.encoding, 'utf-8'); | |
| 86 | 86 | assert.strictEqual(dec.fatal, false); | |
| 87 | 87 | assert.strictEqual(dec.ignoreBOM, false); | |
| 88 | + assert.strictEqual(dec[Symbol.toStringTag], 'TextDecoder'); | ||
| 88 | 89 | } | |
| 89 | 90 | ||
| 90 | 91 | // Test TextDecoder, UTF-16le | |
@@ -125,10 +126,7 @@ if (common.hasIntl) { | |||
| 125 | 126 | ' [Symbol(flags)]: 4,\n' + | |
| 126 | 127 | ' [Symbol(handle)]: StringDecoder {\n' + | |
| 127 | 128 | " encoding: 'utf8',\n" + | |
| 128 | - ' [Symbol(kNativeDecoder)]: <Buffer 00 00 00 00 00 00 01>,\n' + | ||
| 129 | - ' lastChar: [Getter],\n' + | ||
| 130 | - ' lastNeed: [Getter],\n' + | ||
| 131 | - ' lastTotal: [Getter]\n' + | ||
| 129 | + ' [Symbol(kNativeDecoder)]: <Buffer 00 00 00 00 00 00 01>\n' + | ||
| 132 | 130 | ' }\n' + | |
| 133 | 131 | '}' | |
| 134 | 132 | ); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments