23
23
24
24
const {
25
25
ArrayBuffer,
26
+ ArrayPrototypeMap,
27
+ ArrayPrototypePush,
26
28
Error,
29
+ FunctionPrototypeBind,
27
30
MathMax,
28
31
NumberIsFinite,
29
32
NumberIsNaN,
@@ -33,7 +36,9 @@ const {
33
36
ObjectGetPrototypeOf,
34
37
ObjectKeys,
35
38
ObjectSetPrototypeOf,
39
+ ReflectApply,
36
40
Symbol,
41
+ TypedArrayPrototypeFill,
37
42
Uint32Array,
38
43
} = primordials ;
39
44
@@ -123,7 +128,7 @@ function zlibBufferOnData(chunk) {
123
128
if ( ! this . buffers )
124
129
this . buffers = [ chunk ] ;
125
130
else
126
- this . buffers . push ( chunk ) ;
131
+ ArrayPrototypePush ( this . buffers , chunk ) ;
127
132
this . nread += chunk . length ;
128
133
if ( this . nread > this . _maxOutputLength ) {
129
134
this . close ( ) ;
@@ -267,7 +272,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
267
272
}
268
273
}
269
274
270
- Transform . call ( this , { autoDestroy : true , ...opts } ) ;
275
+ ReflectApply ( Transform , this , [ { autoDestroy : true , ...opts } ] ) ;
271
276
this [ kError ] = null ;
272
277
this . bytesWritten = 0 ;
273
278
this . _handle = handle ;
@@ -452,7 +457,7 @@ function processChunkSync(self, chunk, flushFlag) {
452
457
if ( ! buffers )
453
458
buffers = [ out ] ;
454
459
else
455
- buffers . push ( out ) ;
460
+ ArrayPrototypePush ( buffers , out ) ;
456
461
nread += out . byteLength ;
457
462
458
463
if ( nread > self . _maxOutputLength ) {
@@ -665,7 +670,7 @@ function Zlib(opts, mode) {
665
670
processCallback ,
666
671
dictionary ) ;
667
672
668
- ZlibBase . call ( this , opts , mode , handle , zlibDefaultOpts ) ;
673
+ ReflectApply ( ZlibBase , this , [ opts , mode , handle , zlibDefaultOpts ] ) ;
669
674
670
675
this . _level = level ;
671
676
this . _strategy = strategy ;
@@ -693,7 +698,8 @@ Zlib.prototype.params = function params(level, strategy, callback) {
693
698
694
699
if ( this . _level !== level || this . _strategy !== strategy ) {
695
700
this . flush ( Z_SYNC_FLUSH ,
696
- paramsAfterFlushCallback . bind ( this , level , strategy , callback ) ) ;
701
+ FunctionPrototypeBind ( paramsAfterFlushCallback , this ,
702
+ level , strategy , callback ) ) ;
697
703
} else {
698
704
process . nextTick ( callback ) ;
699
705
}
@@ -704,31 +710,31 @@ Zlib.prototype.params = function params(level, strategy, callback) {
704
710
function Deflate ( opts ) {
705
711
if ( ! ( this instanceof Deflate ) )
706
712
return new Deflate ( opts ) ;
707
- Zlib . call ( this , opts , DEFLATE ) ;
713
+ ReflectApply ( Zlib , this , [ opts , DEFLATE ] ) ;
708
714
}
709
715
ObjectSetPrototypeOf ( Deflate . prototype , Zlib . prototype ) ;
710
716
ObjectSetPrototypeOf ( Deflate , Zlib ) ;
711
717
712
718
function Inflate ( opts ) {
713
719
if ( ! ( this instanceof Inflate ) )
714
720
return new Inflate ( opts ) ;
715
- Zlib . call ( this , opts , INFLATE ) ;
721
+ ReflectApply ( Zlib , this , [ opts , INFLATE ] ) ;
716
722
}
717
723
ObjectSetPrototypeOf ( Inflate . prototype , Zlib . prototype ) ;
718
724
ObjectSetPrototypeOf ( Inflate , Zlib ) ;
719
725
720
726
function Gzip ( opts ) {
721
727
if ( ! ( this instanceof Gzip ) )
722
728
return new Gzip ( opts ) ;
723
- Zlib . call ( this , opts , GZIP ) ;
729
+ ReflectApply ( Zlib , this , [ opts , GZIP ] ) ;
724
730
}
725
731
ObjectSetPrototypeOf ( Gzip . prototype , Zlib . prototype ) ;
726
732
ObjectSetPrototypeOf ( Gzip , Zlib ) ;
727
733
728
734
function Gunzip ( opts ) {
729
735
if ( ! ( this instanceof Gunzip ) )
730
736
return new Gunzip ( opts ) ;
731
- Zlib . call ( this , opts , GUNZIP ) ;
737
+ ReflectApply ( Zlib , this , [ opts , GUNZIP ] ) ;
732
738
}
733
739
ObjectSetPrototypeOf ( Gunzip . prototype , Zlib . prototype ) ;
734
740
ObjectSetPrototypeOf ( Gunzip , Zlib ) ;
@@ -737,23 +743,23 @@ function DeflateRaw(opts) {
737
743
if ( opts && opts . windowBits === 8 ) opts . windowBits = 9 ;
738
744
if ( ! ( this instanceof DeflateRaw ) )
739
745
return new DeflateRaw ( opts ) ;
740
- Zlib . call ( this , opts , DEFLATERAW ) ;
746
+ ReflectApply ( Zlib , this , [ opts , DEFLATERAW ] ) ;
741
747
}
742
748
ObjectSetPrototypeOf ( DeflateRaw . prototype , Zlib . prototype ) ;
743
749
ObjectSetPrototypeOf ( DeflateRaw , Zlib ) ;
744
750
745
751
function InflateRaw ( opts ) {
746
752
if ( ! ( this instanceof InflateRaw ) )
747
753
return new InflateRaw ( opts ) ;
748
- Zlib . call ( this , opts , INFLATERAW ) ;
754
+ ReflectApply ( Zlib , this , [ opts , INFLATERAW ] ) ;
749
755
}
750
756
ObjectSetPrototypeOf ( InflateRaw . prototype , Zlib . prototype ) ;
751
757
ObjectSetPrototypeOf ( InflateRaw , Zlib ) ;
752
758
753
759
function Unzip ( opts ) {
754
760
if ( ! ( this instanceof Unzip ) )
755
761
return new Unzip ( opts ) ;
756
- Zlib . call ( this , opts , UNZIP ) ;
762
+ ReflectApply ( Zlib , this , [ opts , UNZIP ] ) ;
757
763
}
758
764
ObjectSetPrototypeOf ( Unzip . prototype , Zlib . prototype ) ;
759
765
ObjectSetPrototypeOf ( Unzip , Zlib ) ;
@@ -773,9 +779,10 @@ function createConvenienceMethod(ctor, sync) {
773
779
} ;
774
780
}
775
781
776
- const kMaxBrotliParam = MathMax ( ...ObjectKeys ( constants ) . map ( ( key ) => {
777
- return key . startsWith ( 'BROTLI_PARAM_' ) ? constants [ key ] : 0 ;
778
- } ) ) ;
782
+ const kMaxBrotliParam = MathMax ( ...ArrayPrototypeMap (
783
+ ObjectKeys ( constants ) ,
784
+ ( key ) => ( key . startsWith ( 'BROTLI_PARAM_' ) ? constants [ key ] : 0 )
785
+ ) ) ;
779
786
780
787
const brotliInitParamsArray = new Uint32Array ( kMaxBrotliParam + 1 ) ;
781
788
@@ -787,7 +794,7 @@ const brotliDefaultOpts = {
787
794
function Brotli ( opts , mode ) {
788
795
assert ( mode === BROTLI_DECODE || mode === BROTLI_ENCODE ) ;
789
796
790
- brotliInitParamsArray . fill ( - 1 ) ;
797
+ TypedArrayPrototypeFill ( brotliInitParamsArray , - 1 ) ;
791
798
if ( opts && opts . params ) {
792
799
for ( const origKey of ObjectKeys ( opts . params ) ) {
793
800
const key = + origKey ;
@@ -818,23 +825,23 @@ function Brotli(opts, mode) {
818
825
throw new ERR_ZLIB_INITIALIZATION_FAILED ( ) ;
819
826
}
820
827
821
- ZlibBase . call ( this , opts , mode , handle , brotliDefaultOpts ) ;
828
+ ReflectApply ( ZlibBase , this , [ opts , mode , handle , brotliDefaultOpts ] ) ;
822
829
}
823
830
ObjectSetPrototypeOf ( Brotli . prototype , Zlib . prototype ) ;
824
831
ObjectSetPrototypeOf ( Brotli , Zlib ) ;
825
832
826
833
function BrotliCompress ( opts ) {
827
834
if ( ! ( this instanceof BrotliCompress ) )
828
835
return new BrotliCompress ( opts ) ;
829
- Brotli . call ( this , opts , BROTLI_ENCODE ) ;
836
+ ReflectApply ( Brotli , this , [ opts , BROTLI_ENCODE ] ) ;
830
837
}
831
838
ObjectSetPrototypeOf ( BrotliCompress . prototype , Brotli . prototype ) ;
832
839
ObjectSetPrototypeOf ( BrotliCompress , Brotli ) ;
833
840
834
841
function BrotliDecompress ( opts ) {
835
842
if ( ! ( this instanceof BrotliDecompress ) )
836
843
return new BrotliDecompress ( opts ) ;
837
- Brotli . call ( this , opts , BROTLI_DECODE ) ;
844
+ ReflectApply ( Brotli , this , [ opts , BROTLI_DECODE ] ) ;
838
845
}
839
846
ObjectSetPrototypeOf ( BrotliDecompress . prototype , Brotli . prototype ) ;
840
847
ObjectSetPrototypeOf ( BrotliDecompress , Brotli ) ;
0 commit comments