From 61f2f5c978901e8ceb071598b64d6a381a6801a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 7 Dec 2013 20:03:23 +0100 Subject: [PATCH] Put constructors into separate ctor variables when handling dontLink parameters before creating objects. This hopefully solves the mysterious issue #360 on Chrome. --- src/basic/Rectangle.js | 16 ++++++++-------- src/item/Item.js | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 1176469a..2b7b61c6 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -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); diff --git a/src/item/Item.js b/src/item/Item.js index c477b92b..118b3b8d 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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 */) {