From 513f2a10984242acd20cf65dd38b5df311fc6f80 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 17 Nov 2010 09:44:30 -0800 Subject: [PATCH] Added PixelArray::constructor --- src/Canvas.cc | 5 ++++- src/Canvas.h | 2 +- src/CanvasGradient.cc | 3 +++ src/CanvasGradient.h | 2 +- src/CanvasRenderingContext2d.cc | 3 ++- src/CanvasRenderingContext2d.h | 2 +- src/Image.cc | 5 ++++- src/Image.h | 2 +- src/ImageData.cc | 4 +++- src/ImageData.h | 2 +- src/PixelArray.cc | 13 ++++++++----- src/PixelArray.h | 1 + 12 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index c2983d1..b6ef59a 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -30,10 +30,13 @@ void Canvas::Initialize(Handle target) { HandleScope scope; - constructor = Persistent::New(FunctionTemplate::New(Canvas::New)); + + // Constructor + constructor = Persistent::New(FunctionTemplate::New(Canvas::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("Canvas")); + // Prototype Local proto = constructor->PrototypeTemplate(); NODE_SET_PROTOTYPE_METHOD(constructor, "toBuffer", ToBuffer); NODE_SET_PROTOTYPE_METHOD(constructor, "streamPNGSync", StreamPNGSync); diff --git a/src/Canvas.h b/src/Canvas.h index 5662a2a..fcce9d9 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -51,6 +51,7 @@ class Canvas: public node::ObjectWrap { public: int width; int height; + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle ToBuffer(const Arguments &args); @@ -65,7 +66,6 @@ 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(); diff --git a/src/CanvasGradient.cc b/src/CanvasGradient.cc index ebebf8b..857ff15 100644 --- a/src/CanvasGradient.cc +++ b/src/CanvasGradient.cc @@ -15,10 +15,13 @@ void Gradient::Initialize(Handle target) { HandleScope scope; + + // Constructor constructor = Persistent::New(FunctionTemplate::New(Gradient::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("CanvasGradient")); + // Prototype NODE_SET_PROTOTYPE_METHOD(constructor, "addColorStopRGBA", AddColorStopRGBA); target->Set(String::NewSymbol("CanvasGradient"), constructor->GetFunction()); } diff --git a/src/CanvasGradient.h b/src/CanvasGradient.h index 8c0ca6e..adcf2bc 100644 --- a/src/CanvasGradient.h +++ b/src/CanvasGradient.h @@ -12,13 +12,13 @@ class Gradient: public node::ObjectWrap { public: + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle AddColorStopRGBA(const Arguments &args); Gradient(double x0, double y0, double x1, double y1); Gradient(double x0, double y0, double r0, double x1, double y1, double r1); inline cairo_pattern_t *pattern(){ return _pattern; } - static Persistent constructor; private: ~Gradient(); diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 85d5e9d..7261ac4 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -58,8 +58,9 @@ enum { void Context2d::Initialize(Handle target) { HandleScope scope; + // Constructor - constructor = Persistent::New(FunctionTemplate::New(Context2d::New)); + constructor = Persistent::New(FunctionTemplate::New(Context2d::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("CanvasRenderingContext2d")); diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 1dee53a..f4b127c 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -45,6 +45,7 @@ class Context2d: public node::ObjectWrap { short stateno; canvas_state_t *states[CANVAS_MAX_STATES]; canvas_state_t *state; + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle DrawImage(const Arguments &args); @@ -119,7 +120,6 @@ class Context2d: public node::ObjectWrap { void stroke(bool preserve = false); void save(); void restore(); - static Persistent constructor; protected: Context2d(Canvas *canvas); diff --git a/src/Image.cc b/src/Image.cc index 6b71116..d20befb 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -17,10 +17,13 @@ void Image::Initialize(Handle target) { HandleScope scope; - constructor = Persistent::New(FunctionTemplate::New(Image::New)); + + // Constructor + constructor = Persistent::New(FunctionTemplate::New(Image::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("Image")); + // Prototype Local proto = constructor->PrototypeTemplate(); proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc); proto->SetAccessor(String::NewSymbol("complete"), GetComplete); diff --git a/src/Image.h b/src/Image.h index 11ac495..e1b7c57 100644 --- a/src/Image.h +++ b/src/Image.h @@ -16,6 +16,7 @@ class Image: public node::ObjectWrap { int width, height; Persistent onload; Persistent onerror; + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle GetSrc(Local prop, const AccessorInfo &info); @@ -36,7 +37,6 @@ class Image: public node::ObjectWrap { void loaded(); void load(); Image(); - static Persistent constructor; enum { DEFAULT diff --git a/src/ImageData.cc b/src/ImageData.cc index 285c627..b5bb653 100644 --- a/src/ImageData.cc +++ b/src/ImageData.cc @@ -14,7 +14,9 @@ void ImageData::Initialize(Handle target) { HandleScope scope; - constructor = Persistent::New(FunctionTemplate::New(ImageData::New)); + + // Constructor + constructor = Persistent::New(FunctionTemplate::New(ImageData::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("ImageData")); diff --git a/src/ImageData.h b/src/ImageData.h index 35a6e10..2ec51c9 100644 --- a/src/ImageData.h +++ b/src/ImageData.h @@ -14,7 +14,7 @@ class ImageData: public node::ObjectWrap { public: - static Persistent constructor; + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle GetWidth(Local prop, const AccessorInfo &info); diff --git a/src/PixelArray.cc b/src/PixelArray.cc index b9374ac..b6250f0 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -16,13 +16,16 @@ void PixelArray::Initialize(Handle target) { HandleScope scope; - Local t = FunctionTemplate::New(PixelArray::New); - t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(String::NewSymbol("CanvasPixelArray")); - Local proto = t->InstanceTemplate(); + // Constructor + constructor = Persistent::New(FunctionTemplate::New(PixelArray::New)); + constructor->InstanceTemplate()->SetInternalFieldCount(1); + constructor->SetClassName(String::NewSymbol("CanvasPixelArray")); + + // Prototype + Local proto = constructor->InstanceTemplate(); proto->SetAccessor(String::NewSymbol("length"), GetLength); - target->Set(String::NewSymbol("CanvasPixelArray"), t->GetFunction()); + target->Set(String::NewSymbol("CanvasPixelArray"), constructor->GetFunction()); } /* diff --git a/src/PixelArray.h b/src/PixelArray.h index 21a899a..b03d2fd 100644 --- a/src/PixelArray.h +++ b/src/PixelArray.h @@ -12,6 +12,7 @@ class PixelArray: public node::ObjectWrap { public: + static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle GetLength(Local prop, const AccessorInfo &info);