21
21
22
22
'use strict' ;
23
23
24
- const { Math, Object } = primordials ;
24
+ const {
25
+ Object : {
26
+ defineProperties : ObjectDefineProperties ,
27
+ defineProperty : ObjectDefineProperty ,
28
+ setPrototypeOf : ObjectSetPrototypeOf ,
29
+ create : ObjectCreate
30
+ } ,
31
+ Math : {
32
+ floor : MathFloor ,
33
+ trunc : MathTrunc ,
34
+ min : MathMin
35
+ }
36
+ } = primordials ;
25
37
26
38
const {
27
39
byteLengthUtf8,
@@ -89,7 +101,7 @@ FastBuffer.prototype.constructor = Buffer;
89
101
Buffer . prototype = FastBuffer . prototype ;
90
102
addBufferPrototypeMethods ( Buffer . prototype ) ;
91
103
92
- const constants = Object . defineProperties ( { } , {
104
+ const constants = ObjectDefineProperties ( { } , {
93
105
MAX_LENGTH : {
94
106
value : kMaxLength ,
95
107
writable : false ,
@@ -111,7 +123,7 @@ let poolSize, poolOffset, allocPool;
111
123
// do not own the ArrayBuffer allocator. Zero fill is always on in that case.
112
124
const zeroFill = bindingZeroFill || [ 0 ] ;
113
125
114
- const encodingsMap = Object . create ( null ) ;
126
+ const encodingsMap = ObjectCreate ( null ) ;
115
127
for ( let i = 0 ; i < encodings . length ; ++ i )
116
128
encodingsMap [ encodings [ i ] ] = i ;
117
129
@@ -168,7 +180,7 @@ function toInteger(n, defaultVal) {
168
180
if ( ! Number . isNaN ( n ) &&
169
181
n >= Number . MIN_SAFE_INTEGER &&
170
182
n <= Number . MAX_SAFE_INTEGER ) {
171
- return ( ( n % 1 ) === 0 ? n : Math . floor ( n ) ) ;
183
+ return ( ( n % 1 ) === 0 ? n : MathFloor ( n ) ) ;
172
184
}
173
185
return defaultVal ;
174
186
}
@@ -253,7 +265,7 @@ function Buffer(arg, encodingOrOffset, length) {
253
265
return Buffer . from ( arg , encodingOrOffset , length ) ;
254
266
}
255
267
256
- Object . defineProperty ( Buffer , Symbol . species , {
268
+ ObjectDefineProperty ( Buffer , Symbol . species , {
257
269
enumerable : false ,
258
270
configurable : true ,
259
271
get ( ) { return FastBuffer ; }
@@ -311,7 +323,7 @@ const of = (...items) => {
311
323
} ;
312
324
Buffer . of = of ;
313
325
314
- Object . setPrototypeOf ( Buffer , Uint8Array ) ;
326
+ ObjectSetPrototypeOf ( Buffer , Uint8Array ) ;
315
327
316
328
// The 'assertSize' method will remove itself from the callstack when an error
317
329
// occurs. This is done simply to keep the internal details of the
@@ -364,8 +376,8 @@ function SlowBuffer(length) {
364
376
return createUnsafeBuffer ( length ) ;
365
377
}
366
378
367
- Object . setPrototypeOf ( SlowBuffer . prototype , Uint8Array . prototype ) ;
368
- Object . setPrototypeOf ( SlowBuffer , Uint8Array ) ;
379
+ ObjectSetPrototypeOf ( SlowBuffer . prototype , Uint8Array . prototype ) ;
380
+ ObjectSetPrototypeOf ( SlowBuffer , Uint8Array ) ;
369
381
370
382
function allocate ( size ) {
371
383
if ( size <= 0 ) {
@@ -712,15 +724,15 @@ function byteLength(string, encoding) {
712
724
Buffer . byteLength = byteLength ;
713
725
714
726
// For backwards compatibility.
715
- Object . defineProperty ( Buffer . prototype , 'parent' , {
727
+ ObjectDefineProperty ( Buffer . prototype , 'parent' , {
716
728
enumerable : true ,
717
729
get ( ) {
718
730
if ( ! ( this instanceof Buffer ) )
719
731
return undefined ;
720
732
return this . buffer ;
721
733
}
722
734
} ) ;
723
- Object . defineProperty ( Buffer . prototype , 'offset' , {
735
+ ObjectDefineProperty ( Buffer . prototype , 'offset' , {
724
736
enumerable : true ,
725
737
get ( ) {
726
738
if ( ! ( this instanceof Buffer ) )
@@ -789,7 +801,7 @@ let INSPECT_MAX_BYTES = 50;
789
801
// Override how buffers are presented by util.inspect().
790
802
Buffer . prototype [ customInspectSymbol ] = function inspect ( recurseTimes , ctx ) {
791
803
const max = INSPECT_MAX_BYTES ;
792
- const actualMax = Math . min ( max , this . length ) ;
804
+ const actualMax = MathMin ( max , this . length ) ;
793
805
const remaining = this . length - max ;
794
806
let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
795
807
if ( remaining > 0 )
@@ -802,7 +814,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
802
814
extras = true ;
803
815
obj [ key ] = this [ key ] ;
804
816
return obj ;
805
- } , Object . create ( null ) ) ;
817
+ } , ObjectCreate ( null ) ) ;
806
818
if ( extras ) {
807
819
if ( this . length !== 0 )
808
820
str += ', ' ;
@@ -1042,7 +1054,7 @@ Buffer.prototype.toJSON = function toJSON() {
1042
1054
function adjustOffset ( offset , length ) {
1043
1055
// Use Math.trunc() to convert offset to an integer value that can be larger
1044
1056
// than an Int32. Hence, don't use offset | 0 or similar techniques.
1045
- offset = Math . trunc ( offset ) ;
1057
+ offset = MathTrunc ( offset ) ;
1046
1058
if ( offset === 0 ) {
1047
1059
return 0 ;
1048
1060
}
@@ -1163,7 +1175,7 @@ module.exports = {
1163
1175
kStringMaxLength
1164
1176
} ;
1165
1177
1166
- Object . defineProperties ( module . exports , {
1178
+ ObjectDefineProperties ( module . exports , {
1167
1179
constants : {
1168
1180
configurable : false ,
1169
1181
enumerable : true ,
0 commit comments