diff --git a/src/Canvas.cc b/src/Canvas.cc index 8fafc63..c2983d1 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -30,16 +30,16 @@ void Canvas::Initialize(Handle target) { HandleScope scope; - Local t = FunctionTemplate::New(Canvas::New); - t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(String::NewSymbol("Canvas")); + constructor = Persistent::New(FunctionTemplate::New(Canvas::New)); + constructor->InstanceTemplate()->SetInternalFieldCount(1); + constructor->SetClassName(String::NewSymbol("Canvas")); - Local proto = t->PrototypeTemplate(); - NODE_SET_PROTOTYPE_METHOD(t, "toBuffer", ToBuffer); - NODE_SET_PROTOTYPE_METHOD(t, "streamPNGSync", StreamPNGSync); + Local proto = constructor->PrototypeTemplate(); + NODE_SET_PROTOTYPE_METHOD(constructor, "toBuffer", ToBuffer); + NODE_SET_PROTOTYPE_METHOD(constructor, "streamPNGSync", StreamPNGSync); proto->SetAccessor(String::NewSymbol("width"), GetWidth, SetWidth); proto->SetAccessor(String::NewSymbol("height"), GetHeight, SetHeight); - target->Set(String::NewSymbol("Canvas"), t->GetFunction()); + target->Set(String::NewSymbol("Canvas"), constructor->GetFunction()); } /* diff --git a/src/Canvas.h b/src/Canvas.h index 8f6b14e..5662a2a 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -65,6 +65,7 @@ class Canvas: public node::ObjectWrap { inline int stride(){ return cairo_image_surface_get_stride(_surface); } Canvas(int width, int height); void resurface(); + static Persistent constructor; private: ~Canvas();