diff --git a/src/zlib.h b/src/zlib.h index 145849e..567f977 100644 --- a/src/zlib.h +++ b/src/zlib.h @@ -18,30 +18,22 @@ using namespace node; template class ZipLib : ObjectWrap { + private: + enum State { + Idle, + Destroyed, + Data, + Eos, + Error + }; + private: typedef typename Processor::Utils Utils; typedef typename Processor::Blob Blob; typedef ZipLib Self; + typedef StateTransition Transition; - public: - static void Initialize(v8::Handle target) - { - HandleScope scope; - - Local t = FunctionTemplate::New(New); - - t->Inherit(EventEmitter::constructor_template); - t->InstanceTemplate()->SetInternalFieldCount(1); - - NODE_SET_PROTOTYPE_METHOD(t, "write", Write); - NODE_SET_PROTOTYPE_METHOD(t, "close", Close); - NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy); - - target->Set(String::NewSymbol(Processor::Name), t->GetFunction()); - } - - private: struct Request { public: enum Kind { @@ -138,6 +130,23 @@ class ZipLib : ObjectWrap { int status_; }; + public: + static void Initialize(v8::Handle target) + { + HandleScope scope; + + Local t = FunctionTemplate::New(New); + + t->Inherit(EventEmitter::constructor_template); + t->InstanceTemplate()->SetInternalFieldCount(1); + + NODE_SET_PROTOTYPE_METHOD(t, "write", Write); + NODE_SET_PROTOTYPE_METHOD(t, "close", Close); + NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy); + + target->Set(String::NewSymbol(Processor::Name), t->GetFunction()); + } + public: static Handle New(const Arguments &args) { Self *result = new(std::nothrow) Self(); @@ -309,6 +318,24 @@ class ZipLib : ObjectWrap { DoHandleCallbacks(0); } + static void DoCallback(Persistent cb, int r, Blob &out) { + if (!cb.IsEmpty()) { + HandleScope scope; + + Local argv[2]; + argv[0] = Utils::GetException(r); + argv[1] = Encode(out.data(), out.length(), BINARY); + + TryCatch try_catch; + + cb->Call(Context::GetCurrent()->Global(), 2, argv); + + if (try_catch.HasCaught()) { + FatalException(try_catch); + } + } + } + private: static bool ReentrantPop(Queue &queue, pthread_mutex_t &mutex, Request*& request) { @@ -407,28 +434,7 @@ class ZipLib : ObjectWrap { } - public: - static Handle ReturnThisOrThrow(const Arguments &args, - int zipStatus) { - if (!Utils::IsError(zipStatus)) { - return args.This(); - } else { - return ThrowError(zipStatus); - } - } - - - static Handle ReturnOrThrow(HandleScope &scope, - const Local &value, - int zipStatus) { - if (!Utils::IsError(zipStatus)) { - return scope.Close(value); - } else { - return ThrowError(zipStatus); - } - } - - + private: static Handle ThrowError(int zipStatus) { assert(Utils::IsError(zipStatus)); @@ -449,34 +455,6 @@ class ZipLib : ObjectWrap { } - static void DoCallback(Persistent cb, int r, Blob &out) { - if (!cb.IsEmpty()) { - HandleScope scope; - - Local argv[2]; - argv[0] = Utils::GetException(r); - argv[1] = Encode(out.data(), out.length(), BINARY); - - TryCatch try_catch; - - cb->Call(Context::GetCurrent()->Global(), 2, argv); - - if (try_catch.HasCaught()) { - FatalException(try_catch); - } - } - } - - enum State { - Idle, - Destroyed, - Data, - Eos, - Error - }; - - typedef StateTransition Transition; - private: Processor processor_; State state_;