Put constructors into separate ctor variables when handling dontLink parameters before creating objects.

This hopefully solves the mysterious issue #360 on Chrome.
This commit is contained in:
Jürg Lehni 2013-12-07 20:03:23 +01:00
parent acc0e80d78
commit 61f2f5c978
2 changed files with 21 additions and 20 deletions

View file

@ -237,8 +237,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* @bean
*/
getPoint: function(/* dontLink */) {
return new (arguments[0] ? Point : LinkedPoint)(
this.x, this.y, this, 'setPoint');
var ctor = arguments[0] ? Point : LinkedPoint;
return new ctor(this.x, this.y, this, 'setPoint');
},
setPoint: function(point) {
@ -255,8 +255,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* @bean
*/
getSize: function(/* dontLink */) {
return new (arguments[0] ? Size : LinkedSize)(
this.width, this.height, this, 'setSize');
var ctor = arguments[0] ? Size : LinkedSize;
return new ctor(this.width, this.height, this, 'setSize');
},
setSize: function(size) {
@ -401,8 +401,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* @bean
*/
getCenter: function(/* dontLink */) {
return new (arguments[0] ? Point : LinkedPoint)(
this.getCenterX(), this.getCenterY(), this, 'setCenter');
var ctor = arguments[0] ? Point : LinkedPoint;
return new ctor(this.getCenterX(), this.getCenterY(), this, 'setCenter');
},
setCenter: function(point) {
@ -809,8 +809,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
get = 'get' + part,
set = 'set' + part;
this[get] = function(/* dontLink */) {
return new (arguments[0] ? Point : LinkedPoint)(
this[getX](), this[getY](), this, set);
var ctor = arguments[0] ? Point : LinkedPoint;
return new ctor(this[getX](), this[getY](), this, set);
};
this[set] = function(point) {
point = Point.read(arguments);

View file

@ -759,7 +759,12 @@ var Item = Base.extend(Callback, /** @lends Item# */{
getPosition: function(/* dontLink */) {
// Cache position value.
// Pass true for dontLink in getCenter(), so receive back a normal point
var position = this._position;
var position = this._position,
ctor = arguments[0] ? Point : LinkedPoint;
// Do not cache LinkedPoints directly, since we would not be able to
// use them to calculate the difference in #setPosition, as when it is
// modified, it would hold new values already and only then cause the
// calling of #setPosition.
if (!position) {
// If a registration point is provided, use it to determine position
// base don the matrix. Otherwise use the center of the bounds.
@ -768,12 +773,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
? this._matrix._transformPoint(registration)
: this.getBounds().getCenter(true);
}
// Do not cache LinkedPoints directly, since we would not be able to
// use them to calculate the difference in #setPosition, as when it is
// modified, it would hold new values already and only then cause the
// calling of #setPosition.
return new (arguments[0] ? Point : LinkedPoint)(
position.x, position.y, this, 'setPosition');
return new ctor(position.x, position.y, this, 'setPosition');
},
setPosition: function(/* point */) {
@ -786,11 +786,12 @@ var Item = Base.extend(Callback, /** @lends Item# */{
_registration: null,
getRegistration: function(/* dontLink */) {
var registration = this._registration;
return registration
? new (arguments[0] ? Point : LinkedPoint)(
registration.x, registration.y, this, 'setRegistration')
: null;
var reg = this._registration;
if (reg) {
var ctor = arguments[0] ? Point : LinkedPoint;
reg = new ctor(reg.x, reg.y, this, 'setRegistration');
}
return reg;
},
setRegistration: function(/* point */) {