Skip to content

Commit

Permalink
fix(fabric.Image): do not crash if image has no element (#6285)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Apr 22, 2020
1 parent 3aeb0ce commit 5cbbb2c
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,11 @@
},

_renderFill: function(ctx) {
var elementToDraw = this._element,
w = this.width, h = this.height,
var elementToDraw = this._element;
if (!elementToDraw) {
return;
}
var w = this.width, h = this.height,
sW = Math.min(elementToDraw.naturalWidth || elementToDraw.width, w * this._filterScalingX),
sH = Math.min(elementToDraw.naturalHeight || elementToDraw.height, h * this._filterScalingY),
x = -w / 2, y = -h / 2,
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@
*/
isNotVisible: function() {
return this.opacity === 0 ||
(this.width === 0 && this.height === 0 && this.strokeWidth === 0) ||
(!this.width && !this.height && this.strokeWidth === 0) ||
!this.visible;
},

Expand Down
1 change: 1 addition & 0 deletions test/node_test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var jsdom = require('jsdom');
class CustomResourceLoader extends jsdom.ResourceLoader {
fetch(url, options) {
return super.fetch(url, options).catch(e => {
console.log('JSDOM CATCHED FETCHING', url);
throw new Error('JSDOM FETCH CATCHED');
});
}
Expand Down
Loading

0 comments on commit 5cbbb2c

Please sign in to comment.