Skip to content

Remove source support for node < 4 #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions lib/jpegstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
18 changes: 8 additions & 10 deletions lib/pdfstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
35 changes: 8 additions & 27 deletions lib/pngstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
31 changes: 0 additions & 31 deletions src/Canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand All @@ -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
}

/*
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 0 additions & 18 deletions src/ImageData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down