| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ const { | |||
| 35 | 35 | NumberMIN_SAFE_INTEGER, | |
| 36 | 36 | ObjectDefineProperties, | |
| 37 | 37 | ObjectDefineProperty, | |
| 38 | + ObjectPrototypeHasOwnProperty, | ||
| 38 | 39 | ObjectSetPrototypeOf, | |
| 39 | 40 | RegExpPrototypeSymbolReplace, | |
| 40 | 41 | StringPrototypeCharCodeAt, | |
@@ -910,7 +911,14 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) { | |||
| 910 | 911 | }), 27, -2); | |
| 911 | 912 | } | |
| 912 | 913 | } | |
| 913 | - return `<${this.constructor.name} ${str}>`; | ||
| 914 | + let constructorName = 'Buffer'; | ||
| 915 | + try { | ||
| 916 | + const { constructor } = this; | ||
| 917 | + if (typeof constructor === 'function' && ObjectPrototypeHasOwnProperty(constructor, 'name')) { | ||
| 918 | + constructorName = constructor.name; | ||
| 919 | + } | ||
| 920 | + } catch { /* Ignore error and use default name */ } | ||
| 921 | + return `<${constructorName} ${str}>`; | ||
| 914 | 922 | }; | |
| 915 | 923 | Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol]; | |
| 916 | 924 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | Array, | |
| 5 | + ArrayBuffer, | ||
| 6 | + ArrayBufferPrototype, | ||
| 5 | 7 | ArrayIsArray, | |
| 8 | + ArrayPrototype, | ||
| 6 | 9 | ArrayPrototypeFilter, | |
| 7 | 10 | ArrayPrototypeForEach, | |
| 8 | 11 | ArrayPrototypeIncludes, | |
@@ -29,6 +32,8 @@ const { | |||
| 29 | 32 | FunctionPrototypeSymbolHasInstance, | |
| 30 | 33 | FunctionPrototypeToString, | |
| 31 | 34 | JSONStringify, | |
| 35 | + Map, | ||
| 36 | + MapPrototype, | ||
| 32 | 37 | MapPrototypeEntries, | |
| 33 | 38 | MapPrototypeGetSize, | |
| 34 | 39 | MathFloor, | |
@@ -68,6 +73,8 @@ const { | |||
| 68 | 73 | SafeMap, | |
| 69 | 74 | SafeSet, | |
| 70 | 75 | SafeStringIterator, | |
| 76 | + Set, | ||
| 77 | + SetPrototype, | ||
| 71 | 78 | SetPrototypeGetSize, | |
| 72 | 79 | SetPrototypeValues, | |
| 73 | 80 | String, | |
@@ -93,6 +100,8 @@ const { | |||
| 93 | 100 | SymbolPrototypeValueOf, | |
| 94 | 101 | SymbolToPrimitive, | |
| 95 | 102 | SymbolToStringTag, | |
| 103 | + TypedArray, | ||
| 104 | + TypedArrayPrototype, | ||
| 96 | 105 | TypedArrayPrototypeGetLength, | |
| 97 | 106 | TypedArrayPrototypeGetSymbolToStringTag, | |
| 98 | 107 | Uint8Array, | |
@@ -599,8 +608,13 @@ function isInstanceof(object, proto) { | |||
| 599 | 608 | ||
| 600 | 609 | // Special-case for some builtin prototypes in case their `constructor` property has been tampered. | |
| 601 | 610 | const wellKnownPrototypes = new SafeMap(); | |
| 602 | - wellKnownPrototypes.set(ObjectPrototype, { name: 'Object', constructor: Object }); | ||
| 611 | + wellKnownPrototypes.set(ArrayPrototype, { name: 'Array', constructor: Array }); | ||
| 612 | + wellKnownPrototypes.set(ArrayBufferPrototype, { name: 'ArrayBuffer', constructor: ArrayBuffer }); | ||
| 603 | 613 | wellKnownPrototypes.set(FunctionPrototype, { name: 'Function', constructor: Function }); | |
| 614 | + wellKnownPrototypes.set(MapPrototype, { name: 'Map', constructor: Map }); | ||
| 615 | + wellKnownPrototypes.set(ObjectPrototype, { name: 'Object', constructor: Object }); | ||
| 616 | + wellKnownPrototypes.set(SetPrototype, { name: 'Set', constructor: Set }); | ||
| 617 | + wellKnownPrototypes.set(TypedArrayPrototype, { name: 'TypedArray', constructor: TypedArray }); | ||
| 604 | 618 | ||
| 605 | 619 | function getConstructorName(obj, ctx, recurseTimes, protoProps) { | |
| 606 | 620 | let firstProto; | |
@@ -825,12 +839,12 @@ function formatValue(ctx, value, recurseTimes, typedArray) { | |||
| 825 | 839 | // Filter out the util module, its inspect function is special. | |
| 826 | 840 | maybeCustom !== inspect && | |
| 827 | 841 | // Also filter out any prototype objects using the circular check. | |
| 828 | - !(value.constructor && value.constructor.prototype === value)) { | ||
| 842 | + ObjectGetOwnPropertyDescriptor(value, 'constructor')?.value?.prototype !== value) { | ||
| 829 | 843 | // This makes sure the recurseTimes are reported as before while using | |
| 830 | 844 | // a counter internally. | |
| 831 | 845 | const depth = ctx.depth === null ? null : ctx.depth - recurseTimes; | |
| 832 | 846 | const isCrossContext = | |
| 833 | - proxy !== undefined || !(context instanceof Object); | ||
| 847 | + proxy !== undefined || !FunctionPrototypeSymbolHasInstance(Object, context); | ||
| 834 | 848 | const ret = FunctionPrototypeCall( | |
| 835 | 849 | maybeCustom, | |
| 836 | 850 | context, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3353,3 +3353,44 @@ assert.strictEqual( | |||
| 3353 | 3353 | ); | |
| 3354 | 3354 | Object.defineProperty(BuiltinPrototype, 'constructor', desc); | |
| 3355 | 3355 | } | |
| 3356 | + { | ||
| 3357 | + const prototypes = [ | ||
| 3358 | + Array.prototype, | ||
| 3359 | + ArrayBuffer.prototype, | ||
| 3360 | + Buffer.prototype, | ||
| 3361 | + Function.prototype, | ||
| 3362 | + Map.prototype, | ||
| 3363 | + Object.prototype, | ||
| 3364 | + Reflect.getPrototypeOf(Uint8Array.prototype), | ||
| 3365 | + Set.prototype, | ||
| 3366 | + Uint8Array.prototype, | ||
| 3367 | + ]; | ||
| 3368 | + const descriptors = new Map(); | ||
| 3369 | + const buffer = Buffer.from('Hello'); | ||
| 3370 | + const o = { | ||
| 3371 | + arrayBuffer: new ArrayBuffer(), buffer, typedArray: Uint8Array.from(buffer), | ||
| 3372 | + array: [], func() {}, set: new Set([1]), map: new Map(), | ||
| 3373 | + }; | ||
| 3374 | + for (const BuiltinPrototype of prototypes) { | ||
| 3375 | + descriptors.set(BuiltinPrototype, Reflect.getOwnPropertyDescriptor(BuiltinPrototype, 'constructor')); | ||
| 3376 | + Object.defineProperty(BuiltinPrototype, 'constructor', { | ||
| 3377 | + get: () => BuiltinPrototype, | ||
| 3378 | + configurable: true, | ||
| 3379 | + }); | ||
| 3380 | + } | ||
| 3381 | + assert.strictEqual( | ||
| 3382 | + util.inspect(o), | ||
| 3383 | + '{\n' + | ||
| 3384 | + ' arrayBuffer: ArrayBuffer { [Uint8Contents]: <>, byteLength: 0 },\n' + | ||
| 3385 | + ' buffer: <Buffer 48 65 6c 6c 6f>,\n' + | ||
| 3386 | + ' typedArray: TypedArray(5) [Uint8Array] [ 72, 101, 108, 108, 111 ],\n' + | ||
| 3387 | + ' array: [],\n' + | ||
| 3388 | + ' func: [Function: func],\n' + | ||
| 3389 | + ' set: Set(1) { 1 },\n' + | ||
| 3390 | + ' map: Map(0) {}\n' + | ||
| 3391 | + '}', | ||
| 3392 | + ); | ||
| 3393 | + for (const [BuiltinPrototype, desc] of descriptors) { | ||
| 3394 | + Object.defineProperty(BuiltinPrototype, 'constructor', desc); | ||
| 3395 | + } | ||
| 3396 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments