Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #379 from Costent/master

fix segfault when Image::onload and Image::onerror are not function
  • Loading branch information...
commit 488aab1c0d0c3c8bc5edc3c28ecf1080f1ea5415 2 parents f811e48 + 1256ce4
@kangax kangax authored
Showing with 15 additions and 3 deletions.
  1. +10 −2 src/Image.cc
  2. +5 −1 test/image.test.js
View
12 src/Image.cc
@@ -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();
+ }
}
/*
@@ -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();
+ }
}
/*
View
6 test/image.test.js
@@ -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;
@@ -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');
@@ -77,4 +81,4 @@ module.exports = {
assert.equal(1, n);
}
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.