Skip to content

Commit

Permalink
Check presence of originalElement before taking src (#2878)
Browse files Browse the repository at this point in the history
* check presence of originalElement before taking src

* add test for image with null element

* Update image.js

* Update image.js
  • Loading branch information
asturur committed Apr 11, 2016
1 parent 8a845b9 commit c681589
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@
* @return {Object} Object representation of an instance
*/
toObject: function(propertiesToInclude) {
var filters = [ ];
var filters = [ ], element = this._originalElement;
this.filters.forEach(function(filterObj) {
if (filterObj) {
filters.push(filterObj.toObject());
}
});
var object = extend(this.callSuper('toObject', propertiesToInclude), {
src: this._originalElement.src || this._originalElement._src,
src: element ? element.src || element._src : '',
filters: filters,
crossOrigin: this.crossOrigin,
alignX: this.alignX,
Expand Down
17 changes: 17 additions & 0 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@
});
});

asyncTest('toObject with no element', function() {
createImageObject(function(image) {
image._originalElement = null;
ok(typeof image.toObject == 'function');
var toObject = image.toObject();
// workaround for node-canvas sometimes producing images with width/height and sometimes not
if (toObject.width === 0) {
toObject.width = IMG_WIDTH;
}
if (toObject.height === 0) {
toObject.height = IMG_HEIGHT;
}
deepEqual(toObject, fabric.util.object.extend(REFERENCE_IMG_OBJECT, {src: ''}));
start();
});
});

asyncTest('toObject with resize filter', function() {
createImageObject(function(image) {
ok(typeof image.toObject == 'function');
Expand Down

0 comments on commit c681589

Please sign in to comment.