Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check presence of originalElement before taking src #2878

Merged
merged 4 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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