Skip to content

Commit

Permalink
Merge pull request #379 from Costent/master
Browse files Browse the repository at this point in the history
fix segfault when Image::onload and Image::onerror are not function
  • Loading branch information
kangax committed Feb 7, 2014
2 parents f811e48 + 1256ce4 commit 488aab1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Image.cc
Expand Up @@ -258,7 +258,11 @@ Image::readPNG(void *c, uint8_t *data, unsigned int len) {
NAN_GETTER(Image::GetOnload) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(img->onload->GetFunction());
if (img->onload) {
NanReturnValue(img->onload->GetFunction());
} else {
NanReturnNull();
}
}

/*
Expand All @@ -279,7 +283,11 @@ NAN_SETTER(Image::SetOnload) {
NAN_GETTER(Image::GetOnerror) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(img->onerror->GetFunction());
if (img->onerror) {
NanReturnValue(img->onerror->GetFunction());
} else {
NanReturnNull();
}
}

/*
Expand Down
6 changes: 5 additions & 1 deletion test/image.test.js
Expand Up @@ -18,6 +18,8 @@ module.exports = {
var img = new Image
, n = 0;

assert.strictEqual(null, img.onload);

assert.strictEqual(false, img.complete);
img.onload = function(){
++n;
Expand All @@ -39,6 +41,8 @@ module.exports = {
, error
, n = 0;

assert.strictEqual(null, img.onerror);

assert.strictEqual(false, img.complete);
img.onload = function(){
assert.fail('called onload');
Expand Down Expand Up @@ -77,4 +81,4 @@ module.exports = {

assert.equal(1, n);
}
};
};

0 comments on commit 488aab1

Please sign in to comment.