bug fix - when setting a custom attr that points to self, the setAttrs method no longer gets stuck in a recursive loop throwing a stack overflow error. Also, objects that were instantiated from a class (non-literal objects) are no longer serializable

This commit is contained in:
Eric Rowell
2012-05-26 18:31:13 -07:00
parent fd6bdb570c
commit 44ba6f7e5b
6 changed files with 87 additions and 30 deletions

View File

@@ -120,7 +120,7 @@ Kinetic.GlobalObject = {
}
},
/*
* utilities
* cherry-picked and modified utilities from underscore.js
*/
_isElement: function(obj) {
return !!(obj && obj.nodeType == 1);
@@ -138,6 +138,14 @@ Kinetic.GlobalObject = {
_isNumber: function(obj) {
return toString.call(obj) == '[object Number]';
},
_hasMethods: function(obj) {
var names = [];
for(var key in obj) {
if(this._isFunction(obj[key]))
names.push(key);
}
return names.length > 0;
},
/*
* The argument can be:
* - an integer (will be applied to both x and y)

View File

@@ -157,10 +157,10 @@ Kinetic.Node.prototype = {
}
/*
* if property is an object, then add an empty object
* if property is a pure object (no methods), then add an empty object
* to the node and then traverse
*/
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val)) {
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val) && !go._hasMethods(val)) {
if(obj[key] === undefined) {
obj[key] = {};
}

View File

@@ -182,17 +182,17 @@ Kinetic.Stage.prototype = {
function addNode(node) {
var obj = {};
var cleanAttrs = node.attrs;
// remove function, image, and DOM attrs
for (var key in cleanAttrs) {
var val = cleanAttrs[key];
if (go._isFunction(val) || go._isElement(val)) {
cleanAttrs[key] = undefined;
}
}
// remove function, image, DOM, and objects with methods
for(var key in cleanAttrs) {
var val = cleanAttrs[key];
if(go._isFunction(val) || go._isElement(val) || go._hasMethods(val)) {
cleanAttrs[key] = undefined;
}
}
obj.attrs = cleanAttrs;
obj.nodeType = node.nodeType;
@@ -394,7 +394,7 @@ Kinetic.Stage.prototype = {
// draw layer and append canvas to container
layer.draw();
this.content.appendChild(layer.canvas);
/*
* set layer last draw time to zero
* so that throttling doesn't take into account