@@ -465,29 +465,41 @@ rbush.prototype = {
465465
466466 _initFormat : function ( format )
467467 {
468- // data format (minX, minY, maxX, maxY accessors)
468+ // format: [minX, minY, maxX, maxY accessors]
469+ // accessors will be dotted names
470+
471+ // Because we have historically used eval-based function constructor
472+ // the format accerrsors need to have their leading dots stripped to
473+ // obtain the actual accessor
474+ format = format . map (
475+ function ( f )
476+ {
477+ return f . substring ( 1 ) ;
478+ }
479+ ) ;
469480
470481 // Do not use string-generated Functions for CSP policies
471- // Instead a combination of anonymous functions and grabbing
472- // properties by string is used.
473- var compareArr = function ( accessor )
474- {
475- return function ( a , b )
476- {
477- return this [ a + accessor ] - this [ b + accessor ] ;
478- } ;
482+ // Instead a combination of anonymous functions and grabbing properties
483+ // by string is used.
484+ // cf. https://github.com/photonstorm/phaser/issues/3441
485+ // and https://github.com/photonstorm/phaser/issues/3535
486+
487+ var mkCompareFn = function ( attr ) {
488+ return function ( a , b ) {
489+ return a [ attr ] - b [ attr ] ;
490+ } ;
479491 } ;
480492
481- this . compareMinX = compareArr ( format [ 0 ] ) ;
482- this . compareMinY = compareArr ( format [ 1 ] ) ;
493+ this . compareMinX = mkCompareFn ( format [ 0 ] ) ;
494+ this . compareMinY = mkCompareFn ( format [ 1 ] ) ;
483495
484- this . toBBox = function ( a )
496+ this . toBBox = function ( a )
485497 {
486498 return {
487- minX : a + format [ 0 ] ,
488- minY : a + format [ 1 ] ,
489- maxX : a + format [ 2 ] ,
490- maxy : a + format [ 3 ]
499+ minX : a [ format [ 0 ] ] ,
500+ minY : a [ format [ 1 ] ] ,
501+ maxX : a [ format [ 2 ] ] ,
502+ maxY : a [ format [ 3 ] ] ,
491503 } ;
492504 } ;
493505 }
0 commit comments