Browse Source

Merge pull request #379 from Costent/master

fix segfault when Image::onload and Image::onerror are not function
v1.x
Juriy Zaytsev 11 years ago
parent
commit
488aab1c0d
  1. 12
      src/Image.cc
  2. 6
      test/image.test.js

12
src/Image.cc

@ -258,7 +258,11 @@ Image::readPNG(void *c, uint8_t *data, unsigned int len) {
NAN_GETTER(Image::GetOnload) { NAN_GETTER(Image::GetOnload) {
NanScope(); NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This()); Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(img->onload->GetFunction()); if (img->onload) {
NanReturnValue(img->onload->GetFunction());
} else {
NanReturnNull();
}
} }
/* /*
@ -279,7 +283,11 @@ NAN_SETTER(Image::SetOnload) {
NAN_GETTER(Image::GetOnerror) { NAN_GETTER(Image::GetOnerror) {
NanScope(); NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This()); Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(img->onerror->GetFunction()); if (img->onerror) {
NanReturnValue(img->onerror->GetFunction());
} else {
NanReturnNull();
}
} }
/* /*

6
test/image.test.js

@ -18,6 +18,8 @@ module.exports = {
var img = new Image var img = new Image
, n = 0; , n = 0;
assert.strictEqual(null, img.onload);
assert.strictEqual(false, img.complete); assert.strictEqual(false, img.complete);
img.onload = function(){ img.onload = function(){
++n; ++n;
@ -39,6 +41,8 @@ module.exports = {
, error , error
, n = 0; , n = 0;
assert.strictEqual(null, img.onerror);
assert.strictEqual(false, img.complete); assert.strictEqual(false, img.complete);
img.onload = function(){ img.onload = function(){
assert.fail('called onload'); assert.fail('called onload');
@ -77,4 +81,4 @@ module.exports = {
assert.equal(1, n); assert.equal(1, n);
} }
}; };

Loading…
Cancel
Save