mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-11 15:23:10 +00:00
Node.js Invoke loadImage callback if there is no data or a network error
This commit is contained in:
parent
7515fcedbe
commit
69d616ad23
2 changed files with 24 additions and 0 deletions
|
|
@ -50,6 +50,7 @@
|
|||
else {
|
||||
fabric.log(err.message);
|
||||
}
|
||||
callback(null);
|
||||
});
|
||||
|
||||
req.end();
|
||||
|
|
@ -77,6 +78,10 @@
|
|||
img._src = url;
|
||||
callback && callback.call(context, img);
|
||||
}
|
||||
else {
|
||||
img = null;
|
||||
callback && callback.call(context, null, true);
|
||||
}
|
||||
}
|
||||
var img = new Image();
|
||||
if (url && (url instanceof Buffer || url.indexOf('data') === 0)) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
? require("path").join(__dirname, '../fixtures/', 'very_large_image.jpg')
|
||||
: getAbsolutePath('../fixtures/very_large_image.jpg');
|
||||
|
||||
var IMG_URL_NON_EXISTING = 'http://www.google.com/non-existing';
|
||||
|
||||
test('fabric.util.toFixed', function(){
|
||||
ok(typeof fabric.util.toFixed == 'function');
|
||||
|
||||
|
|
@ -459,6 +461,23 @@
|
|||
}, 1000);
|
||||
});
|
||||
|
||||
|
||||
asyncTest('fabric.util.loadImage with url for a non exsiting image', function() {
|
||||
var callbackInvoked = false;
|
||||
var hadError = false;
|
||||
|
||||
fabric.util.loadImage(IMG_URL_NON_EXISTING, function(img, error) {
|
||||
callbackInvoked = true;
|
||||
hadError = error;
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
ok(callbackInvoked, 'callback should be invoked');
|
||||
equal(hadError, true, 'callback should be invoked with error set to true');
|
||||
start();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
var SVG_WITH_1_ELEMENT = '<?xml version="1.0"?>\
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\
|
||||
|
|
|
|||
Loading…
Reference in a new issue