mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
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:
parent
acc0e80d78
commit
61f2f5c978
2 changed files with 21 additions and 20 deletions
|
@ -237,8 +237,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getPoint: function(/* dontLink */) {
|
getPoint: function(/* dontLink */) {
|
||||||
return new (arguments[0] ? Point : LinkedPoint)(
|
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||||
this.x, this.y, this, 'setPoint');
|
return new ctor(this.x, this.y, this, 'setPoint');
|
||||||
},
|
},
|
||||||
|
|
||||||
setPoint: function(point) {
|
setPoint: function(point) {
|
||||||
|
@ -255,8 +255,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getSize: function(/* dontLink */) {
|
getSize: function(/* dontLink */) {
|
||||||
return new (arguments[0] ? Size : LinkedSize)(
|
var ctor = arguments[0] ? Size : LinkedSize;
|
||||||
this.width, this.height, this, 'setSize');
|
return new ctor(this.width, this.height, this, 'setSize');
|
||||||
},
|
},
|
||||||
|
|
||||||
setSize: function(size) {
|
setSize: function(size) {
|
||||||
|
@ -401,8 +401,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getCenter: function(/* dontLink */) {
|
getCenter: function(/* dontLink */) {
|
||||||
return new (arguments[0] ? Point : LinkedPoint)(
|
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||||
this.getCenterX(), this.getCenterY(), this, 'setCenter');
|
return new ctor(this.getCenterX(), this.getCenterY(), this, 'setCenter');
|
||||||
},
|
},
|
||||||
|
|
||||||
setCenter: function(point) {
|
setCenter: function(point) {
|
||||||
|
@ -809,8 +809,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
get = 'get' + part,
|
get = 'get' + part,
|
||||||
set = 'set' + part;
|
set = 'set' + part;
|
||||||
this[get] = function(/* dontLink */) {
|
this[get] = function(/* dontLink */) {
|
||||||
return new (arguments[0] ? Point : LinkedPoint)(
|
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||||
this[getX](), this[getY](), this, set);
|
return new ctor(this[getX](), this[getY](), this, set);
|
||||||
};
|
};
|
||||||
this[set] = function(point) {
|
this[set] = function(point) {
|
||||||
point = Point.read(arguments);
|
point = Point.read(arguments);
|
||||||
|
|
|
@ -759,7 +759,12 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
getPosition: function(/* dontLink */) {
|
getPosition: function(/* dontLink */) {
|
||||||
// Cache position value.
|
// Cache position value.
|
||||||
// Pass true for dontLink in getCenter(), so receive back a normal point
|
// 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 (!position) {
|
||||||
// If a registration point is provided, use it to determine position
|
// If a registration point is provided, use it to determine position
|
||||||
// base don the matrix. Otherwise use the center of the bounds.
|
// 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._matrix._transformPoint(registration)
|
||||||
: this.getBounds().getCenter(true);
|
: this.getBounds().getCenter(true);
|
||||||
}
|
}
|
||||||
// Do not cache LinkedPoints directly, since we would not be able to
|
return new ctor(position.x, position.y, this, 'setPosition');
|
||||||
// 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');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setPosition: function(/* point */) {
|
setPosition: function(/* point */) {
|
||||||
|
@ -786,11 +786,12 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
_registration: null,
|
_registration: null,
|
||||||
|
|
||||||
getRegistration: function(/* dontLink */) {
|
getRegistration: function(/* dontLink */) {
|
||||||
var registration = this._registration;
|
var reg = this._registration;
|
||||||
return registration
|
if (reg) {
|
||||||
? new (arguments[0] ? Point : LinkedPoint)(
|
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||||
registration.x, registration.y, this, 'setRegistration')
|
reg = new ctor(reg.x, reg.y, this, 'setRegistration');
|
||||||
: null;
|
}
|
||||||
|
return reg;
|
||||||
},
|
},
|
||||||
|
|
||||||
setRegistration: function(/* point */) {
|
setRegistration: function(/* point */) {
|
||||||
|
|
Loading…
Reference in a new issue