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
@@ -124,7 +129,7 @@ function zlibBufferOnData(chunk) {
124
129
if ( ! this . buffers )
125
130
this . buffers = [ chunk ] ;
126
131
else
127
- this . buffers . push ( chunk ) ;
132
+ ArrayPrototypePush ( this . buffers , chunk ) ;
128
133
this . nread += chunk . length ;
129
134
if ( this . nread > this . _maxOutputLength ) {
130
135
this . close ( ) ;
@@ -268,7 +273,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
268
273
}
269
274
}
270
275
271
- Transform . call ( this , { autoDestroy : true , ...opts } ) ;
276
+ ReflectApply ( Transform , this , [ { autoDestroy : true , ...opts } ] ) ;
272
277
this [ kError ] = null ;
273
278
this . bytesWritten = 0 ;
274
279
this . _handle = handle ;
@@ -458,7 +463,7 @@ function processChunkSync(self, chunk, flushFlag) {
458
463
if ( ! buffers )
459
464
buffers = [ out ] ;
460
465
else
461
- buffers . push ( out ) ;
466
+ ArrayPrototypePush ( buffers , out ) ;
462
467
nread += out . byteLength ;
463
468
464
469
if ( nread > self . _maxOutputLength ) {
@@ -671,7 +676,7 @@ function Zlib(opts, mode) {
671
676
processCallback ,
672
677
dictionary ) ;
673
678
674
- ZlibBase . call ( this , opts , mode , handle , zlibDefaultOpts ) ;
679
+ ReflectApply ( ZlibBase , this , [ opts , mode , handle , zlibDefaultOpts ] ) ;
675
680
676
681
this . _level = level ;
677
682
this . _strategy = strategy ;
@@ -699,7 +704,8 @@ Zlib.prototype.params = function params(level, strategy, callback) {
699
704
700
705
if ( this . _level !== level || this . _strategy !== strategy ) {
701
706
this . flush ( Z_SYNC_FLUSH ,
702
- paramsAfterFlushCallback . bind ( this , level , strategy , callback ) ) ;
707
+ FunctionPrototypeBind ( paramsAfterFlushCallback , this ,
708
+ level , strategy , callback ) ) ;
703
709
} else {
704
710
process . nextTick ( callback ) ;
705
711
}
@@ -710,31 +716,31 @@ Zlib.prototype.params = function params(level, strategy, callback) {
710
716
function Deflate ( opts ) {
711
717
if ( ! ( this instanceof Deflate ) )
712
718
return new Deflate ( opts ) ;
713
- Zlib . call ( this , opts , DEFLATE ) ;
719
+ ReflectApply ( Zlib , this , [ opts , DEFLATE ] ) ;
714
720
}
715
721
ObjectSetPrototypeOf ( Deflate . prototype , Zlib . prototype ) ;
716
722
ObjectSetPrototypeOf ( Deflate , Zlib ) ;
717
723
718
724
function Inflate ( opts ) {
719
725
if ( ! ( this instanceof Inflate ) )
720
726
return new Inflate ( opts ) ;
721
- Zlib . call ( this , opts , INFLATE ) ;
727
+ ReflectApply ( Zlib , this , [ opts , INFLATE ] ) ;
722
728
}
723
729
ObjectSetPrototypeOf ( Inflate . prototype , Zlib . prototype ) ;
724
730
ObjectSetPrototypeOf ( Inflate , Zlib ) ;
725
731
726
732
function Gzip ( opts ) {
727
733
if ( ! ( this instanceof Gzip ) )
728
734
return new Gzip ( opts ) ;
729
- Zlib . call ( this , opts , GZIP ) ;
735
+ ReflectApply ( Zlib , this , [ opts , GZIP ] ) ;
730
736
}
731
737
ObjectSetPrototypeOf ( Gzip . prototype , Zlib . prototype ) ;
732
738
ObjectSetPrototypeOf ( Gzip , Zlib ) ;
733
739
734
740
function Gunzip ( opts ) {
735
741
if ( ! ( this instanceof Gunzip ) )
736
742
return new Gunzip ( opts ) ;
737
- Zlib . call ( this , opts , GUNZIP ) ;
743
+ ReflectApply ( Zlib , this , [ opts , GUNZIP ] ) ;
738
744
}
739
745
ObjectSetPrototypeOf ( Gunzip . prototype , Zlib . prototype ) ;
740
746
ObjectSetPrototypeOf ( Gunzip , Zlib ) ;
@@ -743,23 +749,23 @@ function DeflateRaw(opts) {
743
749
if ( opts && opts . windowBits === 8 ) opts . windowBits = 9 ;
744
750
if ( ! ( this instanceof DeflateRaw ) )
745
751
return new DeflateRaw ( opts ) ;
746
- Zlib . call ( this , opts , DEFLATERAW ) ;
752
+ ReflectApply ( Zlib , this , [ opts , DEFLATERAW ] ) ;
747
753
}
748
754
ObjectSetPrototypeOf ( DeflateRaw . prototype , Zlib . prototype ) ;
749
755
ObjectSetPrototypeOf ( DeflateRaw , Zlib ) ;
750
756
751
757
function InflateRaw ( opts ) {
752
758
if ( ! ( this instanceof InflateRaw ) )
753
759
return new InflateRaw ( opts ) ;
754
- Zlib . call ( this , opts , INFLATERAW ) ;
760
+ ReflectApply ( Zlib , this , [ opts , INFLATERAW ] ) ;
755
761
}
756
762
ObjectSetPrototypeOf ( InflateRaw . prototype , Zlib . prototype ) ;
757
763
ObjectSetPrototypeOf ( InflateRaw , Zlib ) ;
758
764
759
765
function Unzip ( opts ) {
760
766
if ( ! ( this instanceof Unzip ) )
761
767
return new Unzip ( opts ) ;
762
- Zlib . call ( this , opts , UNZIP ) ;
768
+ ReflectApply ( Zlib , this , [ opts , UNZIP ] ) ;
763
769
}
764
770
ObjectSetPrototypeOf ( Unzip . prototype , Zlib . prototype ) ;
765
771
ObjectSetPrototypeOf ( Unzip , Zlib ) ;
@@ -779,9 +785,10 @@ function createConvenienceMethod(ctor, sync) {
779
785
} ;
780
786
}
781
787
782
- const kMaxBrotliParam = MathMax ( ...ObjectKeys ( constants ) . map ( ( key ) => {
783
- return key . startsWith ( 'BROTLI_PARAM_' ) ? constants [ key ] : 0 ;
784
- } ) ) ;
788
+ const kMaxBrotliParam = MathMax ( ...ArrayPrototypeMap (
789
+ ObjectKeys ( constants ) ,
790
+ ( key ) => ( key . startsWith ( 'BROTLI_PARAM_' ) ? constants [ key ] : 0 )
791
+ ) ) ;
785
792
786
793
const brotliInitParamsArray = new Uint32Array ( kMaxBrotliParam + 1 ) ;
787
794
@@ -793,7 +800,7 @@ const brotliDefaultOpts = {
793
800
function Brotli ( opts , mode ) {
794
801
assert ( mode === BROTLI_DECODE || mode === BROTLI_ENCODE ) ;
795
802
796
- brotliInitParamsArray . fill ( - 1 ) ;
803
+ TypedArrayPrototypeFill ( brotliInitParamsArray , - 1 ) ;
797
804
if ( opts && opts . params ) {
798
805
for ( const origKey of ObjectKeys ( opts . params ) ) {
799
806
const key = + origKey ;
@@ -824,23 +831,23 @@ function Brotli(opts, mode) {
824
831
throw new ERR_ZLIB_INITIALIZATION_FAILED ( ) ;
825
832
}
826
833
827
- ZlibBase . call ( this , opts , mode , handle , brotliDefaultOpts ) ;
834
+ ReflectApply ( ZlibBase , this , [ opts , mode , handle , brotliDefaultOpts ] ) ;
828
835
}
829
836
ObjectSetPrototypeOf ( Brotli . prototype , Zlib . prototype ) ;
830
837
ObjectSetPrototypeOf ( Brotli , Zlib ) ;
831
838
832
839
function BrotliCompress ( opts ) {
833
840
if ( ! ( this instanceof BrotliCompress ) )
834
841
return new BrotliCompress ( opts ) ;
835
- Brotli . call ( this , opts , BROTLI_ENCODE ) ;
842
+ ReflectApply ( Brotli , this , [ opts , BROTLI_ENCODE ] ) ;
836
843
}
837
844
ObjectSetPrototypeOf ( BrotliCompress . prototype , Brotli . prototype ) ;
838
845
ObjectSetPrototypeOf ( BrotliCompress , Brotli ) ;
839
846
840
847
function BrotliDecompress ( opts ) {
841
848
if ( ! ( this instanceof BrotliDecompress ) )
842
849
return new BrotliDecompress ( opts ) ;
843
- Brotli . call ( this , opts , BROTLI_DECODE ) ;
850
+ ReflectApply ( Brotli , this , [ opts , BROTLI_DECODE ] ) ;
844
851
}
845
852
ObjectSetPrototypeOf ( BrotliDecompress . prototype , Brotli . prototype ) ;
846
853
ObjectSetPrototypeOf ( BrotliDecompress , Brotli ) ;
0 commit comments