, mode_(mode)
, strategy_(0)
, windowBits_(0)
- , write_in_progress_(false) {
+ , write_in_progress_(false)
+ , refs_(0) {
}
assert(!ctx->write_in_progress_ && "write already in progress");
ctx->write_in_progress_ = true;
- ctx->ClearWeak();
+ ctx->Ref();
assert(!args[0]->IsUndefined() && "must provide flush value");
Local<Value> args[2] = { avail_in, avail_out };
MakeCallback(env, handle, env->callback_string(), ARRAY_SIZE(args), args);
- ctx->MakeWeak();
+ ctx->Unref();
}
static void Error(ZCtx* ctx, const char* message) {
// no hope of rescue.
ctx->write_in_progress_ = false;
- ctx->MakeWeak();
+ ctx->Unref();
}
static void New(const FunctionCallbackInfo<Value>& args) {
}
private:
+ void Ref() {
+ if (++refs_ == 1) {
+ ClearWeak();
+ }
+ }
+
+ void Unref() {
+ assert(refs_ > 0);
+ if (--refs_ == 0) {
+ MakeWeak();
+ }
+ }
+
static const int kDeflateContextSize = 16384; // approximate
static const int kInflateContextSize = 10240; // approximate
int windowBits_;
uv_work_t work_req_;
bool write_in_progress_;
+ unsigned int refs_;
};