Skip to content

Commit 4f4f857

Browse files
authored
Merge pull request #918 from zbjornson/node4
Remove source support for node < 4
2 parents 82aedcd + e5c8308 commit 4f4f857

7 files changed

Lines changed: 24 additions & 115 deletions

File tree

lib/jpegstream.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ JPEGStream.prototype._read = function _read() {
6363
var bufsize = this.options.bufsize;
6464
var quality = this.options.quality;
6565
var progressive = this.options.progressive;
66-
process.nextTick(function(){
67-
self.canvas[method](bufsize, quality, progressive, function(err, chunk){
68-
if (err) {
69-
self.emit('error', err);
70-
} else if (chunk) {
71-
self.push(chunk);
72-
} else {
73-
self.push(null);
74-
}
75-
});
66+
self.canvas[method](bufsize, quality, progressive, function(err, chunk){
67+
if (err) {
68+
self.emit('error', err);
69+
} else if (chunk) {
70+
self.push(chunk);
71+
} else {
72+
self.push(null);
73+
}
7674
});
7775
};

lib/pdfstream.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ PDFStream.prototype._read = function _read() {
5656
// call canvas.streamPDFSync once and let it emit data at will.
5757
this._read = noop;
5858
var self = this;
59-
process.nextTick(function(){
60-
self.canvas[self.method](function(err, chunk, len){
61-
if (err) {
62-
self.emit('error', err);
63-
} else if (len) {
64-
self.push(chunk);
65-
} else {
66-
self.push(null);
67-
}
68-
});
59+
self.canvas[self.method](function(err, chunk, len){
60+
if (err) {
61+
self.emit('error', err);
62+
} else if (len) {
63+
self.push(chunk);
64+
} else {
65+
self.push(null);
66+
}
6967
});
7068
};

lib/pngstream.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,20 @@ var PNGStream = module.exports = function PNGStream(canvas, sync) {
5151

5252
util.inherits(PNGStream, Readable);
5353

54-
var PNGStream = module.exports = function PNGStream(canvas, sync) {
55-
Readable.call(this);
56-
57-
var self = this;
58-
var method = sync
59-
? 'streamPNGSync'
60-
: 'streamPNG';
61-
this.sync = sync;
62-
this.canvas = canvas;
63-
64-
// TODO: implement async
65-
if ('streamPNG' === method) method = 'streamPNGSync';
66-
this.method = method;
67-
};
68-
69-
util.inherits(PNGStream, Readable);
70-
7154
function noop() {}
7255

7356
PNGStream.prototype._read = function _read() {
7457
// For now we're not controlling the c++ code's data emission, so we only
7558
// call canvas.streamPNGSync once and let it emit data at will.
7659
this._read = noop;
7760
var self = this;
78-
process.nextTick(function(){
79-
self.canvas[self.method](function(err, chunk, len){
80-
if (err) {
81-
self.emit('error', err);
82-
} else if (len) {
83-
self.push(chunk);
84-
} else {
85-
self.push(null);
86-
}
87-
});
61+
self.canvas[self.method](function(err, chunk, len){
62+
if (err) {
63+
self.emit('error', err);
64+
} else if (len) {
65+
self.push(chunk);
66+
} else {
67+
self.push(null);
68+
}
8869
});
8970
};

src/Canvas.cc

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -180,47 +180,25 @@ NAN_SETTER(Canvas::SetHeight) {
180180
* EIO toBuffer callback.
181181
*/
182182

183-
#if NODE_VERSION_AT_LEAST(0, 6, 0)
184183
void
185184
Canvas::ToBufferAsync(uv_work_t *req) {
186-
#elif NODE_VERSION_AT_LEAST(0, 5, 4)
187-
void
188-
Canvas::EIO_ToBuffer(eio_req *req) {
189-
#else
190-
int
191-
Canvas::EIO_ToBuffer(eio_req *req) {
192-
#endif
193185
closure_t *closure = (closure_t *) req->data;
194186

195187
closure->status = canvas_write_to_png_stream(
196188
closure->canvas->surface()
197189
, toBuffer
198190
, closure);
199-
200-
#if !NODE_VERSION_AT_LEAST(0, 5, 4)
201-
return 0;
202-
#endif
203191
}
204192

205193
/*
206194
* EIO after toBuffer callback.
207195
*/
208196

209-
#if NODE_VERSION_AT_LEAST(0, 6, 0)
210197
void
211198
Canvas::ToBufferAsyncAfter(uv_work_t *req) {
212-
#else
213-
int
214-
Canvas::EIO_AfterToBuffer(eio_req *req) {
215-
#endif
216-
217199
Nan::HandleScope scope;
218200
closure_t *closure = (closure_t *) req->data;
219-
#if NODE_VERSION_AT_LEAST(0, 6, 0)
220201
delete req;
221-
#else
222-
ev_unref(EV_DEFAULT_UC);
223-
#endif
224202

225203
if (closure->status) {
226204
Local<Value> argv[1] = { Canvas::Error(closure->status) };
@@ -236,10 +214,6 @@ Canvas::EIO_AfterToBuffer(eio_req *req) {
236214
delete closure->pfn;
237215
closure_destroy(closure);
238216
free(closure);
239-
240-
#if !NODE_VERSION_AT_LEAST(0, 6, 0)
241-
return 0;
242-
#endif
243217
}
244218

245219
/*
@@ -328,14 +302,9 @@ NAN_METHOD(Canvas::ToBuffer) {
328302
canvas->Ref();
329303
closure->pfn = new Nan::Callback(info[0].As<Function>());
330304

331-
#if NODE_VERSION_AT_LEAST(0, 6, 0)
332305
uv_work_t* req = new uv_work_t;
333306
req->data = closure;
334307
uv_queue_work(uv_default_loop(), req, ToBufferAsync, (uv_after_work_cb)ToBufferAsyncAfter);
335-
#else
336-
eio_custom(EIO_ToBuffer, EIO_PRI_DEFAULT, EIO_AfterToBuffer, closure);
337-
ev_ref(EV_DEFAULT_UC);
338-
#endif
339308

340309
return;
341310
// Sync

src/Canvas.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,8 @@ class Canvas: public Nan::ObjectWrap {
6363
static NAN_METHOD(StreamJPEGSync);
6464
static NAN_METHOD(RegisterFont);
6565
static Local<Value> Error(cairo_status_t status);
66-
#if NODE_VERSION_AT_LEAST(0, 6, 0)
6766
static void ToBufferAsync(uv_work_t *req);
6867
static void ToBufferAsyncAfter(uv_work_t *req);
69-
#else
70-
static
71-
#if NODE_VERSION_AT_LEAST(0, 5, 4)
72-
void
73-
#else
74-
int
75-
#endif
76-
EIO_ToBuffer(eio_req *req);
77-
static int EIO_AfterToBuffer(eio_req *req);
78-
#endif
7968
static PangoWeight GetWeightFromCSSString(const char *weight);
8069
static PangoStyle GetStyleFromCSSString(const char *style);
8170
static PangoFontDescription *ResolveFontDescription(const PangoFontDescription *desc);

src/CanvasRenderingContext2d.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,16 +697,8 @@ NAN_METHOD(Context2d::GetImageData) {
697697

698698
uint8_t *src = canvas->data();
699699

700-
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
701-
Local<Object> global = Context::GetCurrent()->Global();
702-
703-
Local<Int32> sizeHandle = Nan::New(size);
704-
Local<Value> caargv[] = { sizeHandle };
705-
Local<Object> clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(1, caargv);
706-
#else
707700
Local<ArrayBuffer> buffer = ArrayBuffer::New(Isolate::GetCurrent(), size);
708701
Local<Uint8ClampedArray> clampedArray = Uint8ClampedArray::New(buffer, 0, size);
709-
#endif
710702

711703
Nan::TypedArrayContents<uint8_t> typedArrayContents(clampedArray);
712704
uint8_t* dst = *typedArrayContents;

src/ImageData.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ NAN_METHOD(ImageData::New) {
3939
return Nan::ThrowTypeError("Class constructors cannot be invoked without 'new'");
4040
}
4141

42-
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
43-
Local<v8::Object> clampedArray;
44-
Local<Object> global = Context::GetCurrent()->Global();
45-
#else
4642
Local<Uint8ClampedArray> clampedArray;
47-
#endif
48-
4943
uint32_t width;
5044
uint32_t height;
5145
int length;
@@ -63,23 +57,11 @@ NAN_METHOD(ImageData::New) {
6357
}
6458
length = width * height * 4;
6559

66-
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
67-
Local<Int32> sizeHandle = Nan::New(length);
68-
Local<Value> caargv[] = { sizeHandle };
69-
clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(1, caargv);
70-
#else
7160
clampedArray = Uint8ClampedArray::New(ArrayBuffer::New(Isolate::GetCurrent(), length), 0, length);
72-
#endif
7361

74-
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
75-
} else if (info[0]->ToObject()->GetIndexedPropertiesExternalArrayDataType() == kExternalPixelArray && info[1]->IsUint32()) {
76-
clampedArray = info[0]->ToObject();
77-
length = clampedArray->GetIndexedPropertiesExternalArrayDataLength();
78-
#else
7962
} else if (info[0]->IsUint8ClampedArray() && info[1]->IsUint32()) {
8063
clampedArray = info[0].As<Uint8ClampedArray>();
8164
length = clampedArray->Length();
82-
#endif
8365
if (length == 0) {
8466
Nan::ThrowRangeError("The input data has a zero byte length.");
8567
return;

0 commit comments

Comments
 (0)