21
21
22
22
'use strict' ;
23
23
24
- const { Math, Object } = primordials ;
24
+ const { Object : { defineProperties, defineProperty, setPrototypeOf, create } } = primordials ;
25
+ const { Math : { floor, trunc, min } } = primordials ;
25
26
26
27
const {
27
28
byteLengthUtf8,
@@ -89,7 +90,7 @@ FastBuffer.prototype.constructor = Buffer;
89
90
Buffer . prototype = FastBuffer . prototype ;
90
91
addBufferPrototypeMethods ( Buffer . prototype ) ;
91
92
92
- const constants = Object . defineProperties ( { } , {
93
+ const constants = defineProperties ( { } , {
93
94
MAX_LENGTH : {
94
95
value : kMaxLength ,
95
96
writable : false ,
@@ -111,7 +112,7 @@ let poolSize, poolOffset, allocPool;
111
112
// do not own the ArrayBuffer allocator. Zero fill is always on in that case.
112
113
const zeroFill = bindingZeroFill || [ 0 ] ;
113
114
114
- const encodingsMap = Object . create ( null ) ;
115
+ const encodingsMap = create ( null ) ;
115
116
for ( let i = 0 ; i < encodings . length ; ++ i )
116
117
encodingsMap [ encodings [ i ] ] = i ;
117
118
@@ -168,7 +169,7 @@ function toInteger(n, defaultVal) {
168
169
if ( ! Number . isNaN ( n ) &&
169
170
n >= Number . MIN_SAFE_INTEGER &&
170
171
n <= Number . MAX_SAFE_INTEGER ) {
171
- return ( ( n % 1 ) === 0 ? n : Math . floor ( n ) ) ;
172
+ return ( ( n % 1 ) === 0 ? n : floor ( n ) ) ;
172
173
}
173
174
return defaultVal ;
174
175
}
@@ -253,7 +254,7 @@ function Buffer(arg, encodingOrOffset, length) {
253
254
return Buffer . from ( arg , encodingOrOffset , length ) ;
254
255
}
255
256
256
- Object . defineProperty ( Buffer , Symbol . species , {
257
+ defineProperty ( Buffer , Symbol . species , {
257
258
enumerable : false ,
258
259
configurable : true ,
259
260
get ( ) { return FastBuffer ; }
@@ -311,7 +312,7 @@ const of = (...items) => {
311
312
} ;
312
313
Buffer . of = of ;
313
314
314
- Object . setPrototypeOf ( Buffer , Uint8Array ) ;
315
+ setPrototypeOf ( Buffer , Uint8Array ) ;
315
316
316
317
// The 'assertSize' method will remove itself from the callstack when an error
317
318
// occurs. This is done simply to keep the internal details of the
@@ -364,8 +365,8 @@ function SlowBuffer(length) {
364
365
return createUnsafeBuffer ( length ) ;
365
366
}
366
367
367
- Object . setPrototypeOf ( SlowBuffer . prototype , Uint8Array . prototype ) ;
368
- Object . setPrototypeOf ( SlowBuffer , Uint8Array ) ;
368
+ setPrototypeOf ( SlowBuffer . prototype , Uint8Array . prototype ) ;
369
+ setPrototypeOf ( SlowBuffer , Uint8Array ) ;
369
370
370
371
function allocate ( size ) {
371
372
if ( size <= 0 ) {
@@ -712,15 +713,15 @@ function byteLength(string, encoding) {
712
713
Buffer . byteLength = byteLength ;
713
714
714
715
// For backwards compatibility.
715
- Object . defineProperty ( Buffer . prototype , 'parent' , {
716
+ defineProperty ( Buffer . prototype , 'parent' , {
716
717
enumerable : true ,
717
718
get ( ) {
718
719
if ( ! ( this instanceof Buffer ) )
719
720
return undefined ;
720
721
return this . buffer ;
721
722
}
722
723
} ) ;
723
- Object . defineProperty ( Buffer . prototype , 'offset' , {
724
+ defineProperty ( Buffer . prototype , 'offset' , {
724
725
enumerable : true ,
725
726
get ( ) {
726
727
if ( ! ( this instanceof Buffer ) )
@@ -789,7 +790,7 @@ let INSPECT_MAX_BYTES = 50;
789
790
// Override how buffers are presented by util.inspect().
790
791
Buffer . prototype [ customInspectSymbol ] = function inspect ( recurseTimes , ctx ) {
791
792
const max = INSPECT_MAX_BYTES ;
792
- const actualMax = Math . min ( max , this . length ) ;
793
+ const actualMax = min ( max , this . length ) ;
793
794
const remaining = this . length - max ;
794
795
let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
795
796
if ( remaining > 0 )
@@ -802,7 +803,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
802
803
extras = true ;
803
804
obj [ key ] = this [ key ] ;
804
805
return obj ;
805
- } , Object . create ( null ) ) ;
806
+ } , create ( null ) ) ;
806
807
if ( extras ) {
807
808
if ( this . length !== 0 )
808
809
str += ', ' ;
@@ -1042,7 +1043,7 @@ Buffer.prototype.toJSON = function toJSON() {
1042
1043
function adjustOffset ( offset , length ) {
1043
1044
// Use Math.trunc() to convert offset to an integer value that can be larger
1044
1045
// than an Int32. Hence, don't use offset | 0 or similar techniques.
1045
- offset = Math . trunc ( offset ) ;
1046
+ offset = trunc ( offset ) ;
1046
1047
if ( offset === 0 ) {
1047
1048
return 0 ;
1048
1049
}
@@ -1163,7 +1164,7 @@ module.exports = {
1163
1164
kStringMaxLength
1164
1165
} ;
1165
1166
1166
- Object . defineProperties ( module . exports , {
1167
+ defineProperties ( module . exports , {
1167
1168
constants : {
1168
1169
configurable : false ,
1169
1170
enumerable : true ,
0 commit comments