@@ -49,6 +49,7 @@ using v8::Local;
4949using v8::Number;
5050using v8::Object;
5151using v8::String;
52+ using v8::Uint32;
5253using v8::Uint32Array;
5354using v8::Value;
5455
@@ -155,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
155156
156157 CHECK_EQ (false , args[0 ]->IsUndefined () && " must provide flush value" );
157158
158- unsigned int flush = args[0 ]->Uint32Value ();
159+ Environment* env = ctx->env ();
160+ Local<Context> context = env->context ();
161+
162+ unsigned int flush;
163+ if (!args[0 ]->Uint32Value (context).To (&flush)) return ;
159164
160165 if (flush != Z_NO_FLUSH &&
161166 flush != Z_PARTIAL_FLUSH &&
@@ -170,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
170175
171176 Bytef* in;
172177 Bytef* out;
173- size_t in_off, in_len, out_off, out_len;
174- Environment* env = ctx->env ();
178+ uint32_t in_off, in_len, out_off, out_len;
175179
176180 if (args[1 ]->IsNull ()) {
177181 // just a flush
@@ -181,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
181185 } else {
182186 CHECK (Buffer::HasInstance (args[1 ]));
183187 Local<Object> in_buf;
184- in_buf = args[1 ]->ToObject (env-> context () ).ToLocalChecked ();
185- in_off = args[2 ]->Uint32Value () ;
186- in_len = args[3 ]->Uint32Value () ;
188+ in_buf = args[1 ]->ToObject (context).ToLocalChecked ();
189+ if (! args[2 ]->Uint32Value (context). To (&in_off)) return ;
190+ if (! args[3 ]->Uint32Value (context). To (&in_len)) return ;
187191
188192 CHECK (Buffer::IsWithinBounds (in_off, in_len, Buffer::Length (in_buf)));
189193 in = reinterpret_cast <Bytef *>(Buffer::Data (in_buf) + in_off);
190194 }
191195
192196 CHECK (Buffer::HasInstance (args[4 ]));
193- Local<Object> out_buf = args[4 ]->ToObject (env-> context () ).ToLocalChecked ();
194- out_off = args[5 ]->Uint32Value () ;
195- out_len = args[6 ]->Uint32Value () ;
197+ Local<Object> out_buf = args[4 ]->ToObject (context).ToLocalChecked ();
198+ if (! args[5 ]->Uint32Value (context). To (&out_off)) return ;
199+ if (! args[6 ]->Uint32Value (context). To (&out_len)) return ;
196200 CHECK (Buffer::IsWithinBounds (out_off, out_len, Buffer::Length (out_buf)));
197201 out = reinterpret_cast <Bytef *>(Buffer::Data (out_buf) + out_off);
198202
@@ -438,32 +442,38 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
438442 ZCtx* ctx;
439443 ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Holder ());
440444
445+ Local<Context> context = args.GetIsolate ()->GetCurrentContext ();
446+
441447 // windowBits is special. On the compression side, 0 is an invalid value.
442448 // But on the decompression side, a value of 0 for windowBits tells zlib
443449 // to use the window size in the zlib header of the compressed stream.
444- int windowBits = args[0 ]->Uint32Value ();
450+ uint32_t windowBits;
451+ if (!args[0 ]->Uint32Value (context).To (&windowBits)) return ;
452+
445453 if (!((windowBits == 0 ) &&
446454 (ctx->mode_ == INFLATE ||
447455 ctx->mode_ == GUNZIP ||
448456 ctx->mode_ == UNZIP))) {
449- CHECK ((windowBits >= Z_MIN_WINDOWBITS &&
450- windowBits <= Z_MAX_WINDOWBITS) && " invalid windowBits" );
457+ CHECK (
458+ (windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) &&
459+ " invalid windowBits" );
451460 }
452461
453462 int level = args[1 ]->Int32Value ();
454463 CHECK ((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
455464 " invalid compression level" );
456465
457- int memLevel = args[2 ]->Uint32Value ();
466+ uint32_t memLevel;
467+ if (!args[2 ]->Uint32Value (context).To (&memLevel)) return ;
458468 CHECK ((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) &&
459- " invalid memlevel" );
460-
461- int strategy = args[ 3 ]-> Uint32Value () ;
462- CHECK (( strategy == Z_FILTERED ||
463- strategy == Z_HUFFMAN_ONLY ||
464- strategy == Z_RLE ||
465- strategy == Z_FIXED ||
466- strategy == Z_DEFAULT_STRATEGY) && " invalid strategy" );
469+ " invalid memlevel" );
470+
471+ uint32_t strategy;
472+ if (!args[ 3 ]-> Uint32Value (context). To (& strategy)) return ;
473+ CHECK ((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY ||
474+ strategy == Z_RLE || strategy == Z_FIXED ||
475+ strategy == Z_DEFAULT_STRATEGY) &&
476+ " invalid strategy" );
467477
468478 CHECK (args[4 ]->IsUint32Array ());
469479 Local<Uint32Array> array = args[4 ].As <Uint32Array>();
0 commit comments