Permalink
Browse files

Merge pull request #918 from zbjornson/node4

Remove source support for node < 4
  • Loading branch information...
2 parents 82aedcd + e5c8308 commit 4f4f857821bdb70a0a6aadc4094cbc952dc59db7 @LinusU LinusU committed on GitHub Jun 24, 2017
Showing with 24 additions and 115 deletions.
  1. +8 −10 lib/jpegstream.js
  2. +8 −10 lib/pdfstream.js
  3. +8 −27 lib/pngstream.js
  4. +0 −31 src/Canvas.cc
  5. +0 −11 src/Canvas.h
  6. +0 −8 src/CanvasRenderingContext2d.cc
  7. +0 −18 src/ImageData.cc
View
@@ -63,15 +63,13 @@ JPEGStream.prototype._read = function _read() {
var bufsize = this.options.bufsize;
var quality = this.options.quality;
var progressive = this.options.progressive;
- process.nextTick(function(){
- self.canvas[method](bufsize, quality, progressive, function(err, chunk){
- if (err) {
- self.emit('error', err);
- } else if (chunk) {
- self.push(chunk);
- } else {
- self.push(null);
- }
- });
+ self.canvas[method](bufsize, quality, progressive, function(err, chunk){
+ if (err) {
+ self.emit('error', err);
+ } else if (chunk) {
+ self.push(chunk);
+ } else {
+ self.push(null);
+ }
});
};
View
@@ -56,15 +56,13 @@ PDFStream.prototype._read = function _read() {
// call canvas.streamPDFSync once and let it emit data at will.
this._read = noop;
var self = this;
- process.nextTick(function(){
- self.canvas[self.method](function(err, chunk, len){
- if (err) {
- self.emit('error', err);
- } else if (len) {
- self.push(chunk);
- } else {
- self.push(null);
- }
- });
+ self.canvas[self.method](function(err, chunk, len){
+ if (err) {
+ self.emit('error', err);
+ } else if (len) {
+ self.push(chunk);
+ } else {
+ self.push(null);
+ }
});
};
View
@@ -51,39 +51,20 @@ var PNGStream = module.exports = function PNGStream(canvas, sync) {
util.inherits(PNGStream, Readable);
-var PNGStream = module.exports = function PNGStream(canvas, sync) {
- Readable.call(this);
-
- var self = this;
- var method = sync
- ? 'streamPNGSync'
- : 'streamPNG';
- this.sync = sync;
- this.canvas = canvas;
-
- // TODO: implement async
- if ('streamPNG' === method) method = 'streamPNGSync';
- this.method = method;
-};
-
-util.inherits(PNGStream, Readable);
-
function noop() {}
PNGStream.prototype._read = function _read() {
// For now we're not controlling the c++ code's data emission, so we only
// call canvas.streamPNGSync once and let it emit data at will.
this._read = noop;
var self = this;
- process.nextTick(function(){
- self.canvas[self.method](function(err, chunk, len){
- if (err) {
- self.emit('error', err);
- } else if (len) {
- self.push(chunk);
- } else {
- self.push(null);
- }
- });
+ self.canvas[self.method](function(err, chunk, len){
+ if (err) {
+ self.emit('error', err);
+ } else if (len) {
+ self.push(chunk);
+ } else {
+ self.push(null);
+ }
});
};
View
@@ -180,47 +180,25 @@ NAN_SETTER(Canvas::SetHeight) {
* EIO toBuffer callback.
*/
-#if NODE_VERSION_AT_LEAST(0, 6, 0)
void
Canvas::ToBufferAsync(uv_work_t *req) {
-#elif NODE_VERSION_AT_LEAST(0, 5, 4)
-void
-Canvas::EIO_ToBuffer(eio_req *req) {
-#else
-int
-Canvas::EIO_ToBuffer(eio_req *req) {
-#endif
closure_t *closure = (closure_t *) req->data;
closure->status = canvas_write_to_png_stream(
closure->canvas->surface()
, toBuffer
, closure);
-
-#if !NODE_VERSION_AT_LEAST(0, 5, 4)
- return 0;
-#endif
}
/*
* EIO after toBuffer callback.
*/
-#if NODE_VERSION_AT_LEAST(0, 6, 0)
void
Canvas::ToBufferAsyncAfter(uv_work_t *req) {
-#else
-int
-Canvas::EIO_AfterToBuffer(eio_req *req) {
-#endif
-
Nan::HandleScope scope;
closure_t *closure = (closure_t *) req->data;
-#if NODE_VERSION_AT_LEAST(0, 6, 0)
delete req;
-#else
- ev_unref(EV_DEFAULT_UC);
-#endif
if (closure->status) {
Local<Value> argv[1] = { Canvas::Error(closure->status) };
@@ -236,10 +214,6 @@ Canvas::EIO_AfterToBuffer(eio_req *req) {
delete closure->pfn;
closure_destroy(closure);
free(closure);
-
-#if !NODE_VERSION_AT_LEAST(0, 6, 0)
- return 0;
-#endif
}
/*
@@ -328,14 +302,9 @@ NAN_METHOD(Canvas::ToBuffer) {
canvas->Ref();
closure->pfn = new Nan::Callback(info[0].As<Function>());
-#if NODE_VERSION_AT_LEAST(0, 6, 0)
uv_work_t* req = new uv_work_t;
req->data = closure;
uv_queue_work(uv_default_loop(), req, ToBufferAsync, (uv_after_work_cb)ToBufferAsyncAfter);
-#else
- eio_custom(EIO_ToBuffer, EIO_PRI_DEFAULT, EIO_AfterToBuffer, closure);
- ev_ref(EV_DEFAULT_UC);
-#endif
return;
// Sync
View
@@ -63,19 +63,8 @@ class Canvas: public Nan::ObjectWrap {
static NAN_METHOD(StreamJPEGSync);
static NAN_METHOD(RegisterFont);
static Local<Value> Error(cairo_status_t status);
-#if NODE_VERSION_AT_LEAST(0, 6, 0)
static void ToBufferAsync(uv_work_t *req);
static void ToBufferAsyncAfter(uv_work_t *req);
-#else
- static
-#if NODE_VERSION_AT_LEAST(0, 5, 4)
- void
-#else
- int
-#endif
- EIO_ToBuffer(eio_req *req);
- static int EIO_AfterToBuffer(eio_req *req);
-#endif
static PangoWeight GetWeightFromCSSString(const char *weight);
static PangoStyle GetStyleFromCSSString(const char *style);
static PangoFontDescription *ResolveFontDescription(const PangoFontDescription *desc);
@@ -697,16 +697,8 @@ NAN_METHOD(Context2d::GetImageData) {
uint8_t *src = canvas->data();
-#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
- Local<Object> global = Context::GetCurrent()->Global();
-
- Local<Int32> sizeHandle = Nan::New(size);
- Local<Value> caargv[] = { sizeHandle };
- Local<Object> clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(1, caargv);
-#else
Local<ArrayBuffer> buffer = ArrayBuffer::New(Isolate::GetCurrent(), size);
Local<Uint8ClampedArray> clampedArray = Uint8ClampedArray::New(buffer, 0, size);
-#endif
Nan::TypedArrayContents<uint8_t> typedArrayContents(clampedArray);
uint8_t* dst = *typedArrayContents;
View
@@ -39,13 +39,7 @@ NAN_METHOD(ImageData::New) {
return Nan::ThrowTypeError("Class constructors cannot be invoked without 'new'");
}
-#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
- Local<v8::Object> clampedArray;
- Local<Object> global = Context::GetCurrent()->Global();
-#else
Local<Uint8ClampedArray> clampedArray;
-#endif
-
uint32_t width;
uint32_t height;
int length;
@@ -63,23 +57,11 @@ NAN_METHOD(ImageData::New) {
}
length = width * height * 4;
-#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
- Local<Int32> sizeHandle = Nan::New(length);
- Local<Value> caargv[] = { sizeHandle };
- clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(1, caargv);
-#else
clampedArray = Uint8ClampedArray::New(ArrayBuffer::New(Isolate::GetCurrent(), length), 0, length);
-#endif
-#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
- } else if (info[0]->ToObject()->GetIndexedPropertiesExternalArrayDataType() == kExternalPixelArray && info[1]->IsUint32()) {
- clampedArray = info[0]->ToObject();
- length = clampedArray->GetIndexedPropertiesExternalArrayDataLength();
-#else
} else if (info[0]->IsUint8ClampedArray() && info[1]->IsUint32()) {
clampedArray = info[0].As<Uint8ClampedArray>();
length = clampedArray->Length();
-#endif
if (length == 0) {
Nan::ThrowRangeError("The input data has a zero byte length.");
return;

0 comments on commit 4f4f857

Please sign in to comment.