@@ -418,16 +418,8 @@ class ZCtx : public AsyncWrap {
418
418
419
419
static void New (const FunctionCallbackInfo<Value>& args) {
420
420
Environment* env = Environment::GetCurrent (args);
421
-
422
- if (args.Length () < 1 || !args[0 ]->IsInt32 ()) {
423
- return env->ThrowTypeError (" Bad argument" );
424
- }
421
+ CHECK (args[0 ]->IsInt32 ());
425
422
node_zlib_mode mode = static_cast <node_zlib_mode>(args[0 ]->Int32Value ());
426
-
427
- if (mode < DEFLATE || mode > UNZIP) {
428
- return env->ThrowTypeError (" Bad argument" );
429
- }
430
-
431
423
new ZCtx (env, args.This (), mode);
432
424
}
433
425
@@ -476,9 +468,14 @@ class ZCtx : public AsyncWrap {
476
468
memcpy (dictionary, dictionary_, dictionary_len);
477
469
}
478
470
479
- Init (ctx, level, windowBits, memLevel, strategy, write_result,
480
- write_js_callback, dictionary, dictionary_len);
471
+ bool ret = Init (ctx, level, windowBits, memLevel, strategy, write_result,
472
+ write_js_callback, dictionary, dictionary_len);
473
+ if (!ret) goto end;
474
+
481
475
SetDictionary (ctx);
476
+
477
+ end:
478
+ return args.GetReturnValue ().Set (ret);
482
479
}
483
480
484
481
static void Params (const FunctionCallbackInfo<Value>& args) {
@@ -495,7 +492,7 @@ class ZCtx : public AsyncWrap {
495
492
SetDictionary (ctx);
496
493
}
497
494
498
- static void Init (ZCtx *ctx, int level, int windowBits, int memLevel,
495
+ static bool Init (ZCtx *ctx, int level, int windowBits, int memLevel,
499
496
int strategy, uint32_t * write_result,
500
497
Local<Function> write_js_callback, char * dictionary,
501
498
size_t dictionary_len) {
@@ -561,11 +558,12 @@ class ZCtx : public AsyncWrap {
561
558
ctx->dictionary_ = nullptr ;
562
559
}
563
560
ctx->mode_ = NONE;
564
- ctx-> env ()-> ThrowError ( " Init error " ) ;
561
+ return false ;
565
562
}
566
563
567
564
ctx->write_result_ = write_result;
568
565
ctx->write_js_callback_ .Reset (ctx->env ()->isolate (), write_js_callback);
566
+ return true ;
569
567
}
570
568
571
569
static void SetDictionary (ZCtx* ctx) {
0 commit comments