Skip to content

Commit 50d9931

Browse files
committed
Added cached MIN/MAX SAFE INT for IE support phaserjs#4833
1 parent 922cbaa commit 50d9931

7 files changed

Lines changed: 40 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* `Tilemap.getTileLayerNames` is a new method that returns a list of all valid tilelayer names loaded in the Tilemap (thanks @Olliebrown)
1414
* When `forceSetTimeOut` is set to `true` in the Game Config, you can now set the target frame rate by setting the `fps.target` value (thanks @pavels)
1515
* Videos can now be loaded from a data URI, allowing for base64 encoded videos to be used in the Loader instead of file based ones. Although, as with all base64 encoded data, we strongly recommend against this (thanks @apasov)
16+
* `Math.MIN_SAFE_INTEGER` is a new math const that stores the minimum safe integer for browsers that don't provide this, such as IE (thanks @jronn)
17+
* `Math.MAX_SAFE_INTEGER` is a new math const that stores the maximum safe integer for browsers that don't provide this, such as IE (thanks @jronn)
1618

1719
### Updates
1820

@@ -31,6 +33,11 @@
3133
* Light2D was not properly working for DynamicTilemapLayers due to a change in the way tilesets were stored, throwing an Uncaught TypeError at runtime. This is now handled correctly. Fix #4167 #4079 (thanks @koljakutschera @blackjack26 @kainage)
3234
* `Input.dragDistanceThreshold` was not working correctly since 3.18, snapping to the wrong drag state unless the time threshold was also set. Fix #4667 (thanks @muliawanw @Olliebrown)
3335
* `Tilemap.convertLayerToStatic` would throw an error when used multiple times, due to an error with the layer index count. Fix #4737 (thanks @Olliebrown @Vegita2)
36+
* The `Tween` class now uses a cached MAX_SAFE_INTEGER making it compatible with Internet Explorer (thanks @jronn)
37+
* The `StaggerBuilder` class now uses a cached MAX_SAFE_INTEGER making it compatible with Internet Explorer (thanks @jronn)
38+
* The `Rectangle.FromPoints` function now uses a cached MIN_SAFE_INTEGER making it compatible with Internet Explorer (thanks @jronn)
39+
* The `Video` class now uses a cached MIN_SAFE_INTEGER making it compatible with Internet Explorer (thanks @jronn)
40+
* The `Path` class now uses a cached MIN_SAFE_INTEGER making it compatible with Internet Explorer (thanks @jronn)
3441

3542
### Examples, Documentation and TypeScript
3643

src/curves/path/Path.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var QuadraticBezierCurve = require('../QuadraticBezierCurve');
1616
var Rectangle = require('../../geom/rectangle/Rectangle');
1717
var SplineCurve = require('../SplineCurve');
1818
var Vector2 = require('../../math/Vector2');
19+
var MATH_CONST = require('../../math/const');
1920

2021
/**
2122
* @classdesc
@@ -404,8 +405,8 @@ var Path = new Class({
404405
out.y = Number.MAX_VALUE;
405406

406407
var bounds = new Rectangle();
407-
var maxRight = Number.MIN_SAFE_INTEGER;
408-
var maxBottom = Number.MIN_SAFE_INTEGER;
408+
var maxRight = MATH_CONST.MIN_SAFE_INTEGER;
409+
var maxBottom = MATH_CONST.MIN_SAFE_INTEGER;
409410

410411
for (var i = 0; i < this.curves.length; i++)
411412
{

src/gameobjects/video/Video.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var GameObject = require('../GameObject');
1313
var SoundEvents = require('../../sound/events/');
1414
var UUID = require('../../utils/string/UUID');
1515
var VideoRender = require('./VideoRender');
16+
var MATH_CONST = require('../../math/const');
1617

1718
/**
1819
* @classdesc
@@ -333,7 +334,7 @@ var Video = new Class({
333334
* @private
334335
* @since 3.20.0
335336
*/
336-
this._markerOut = Number.MAX_SAFE_INTEGER;
337+
this._markerOut = MATH_CONST.MAX_SAFE_INTEGER;
337338

338339
/**
339340
* The last time the TextureSource was updated.

src/geom/rectangle/FromPoints.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Rectangle = require('./Rectangle');
8+
var MATH_CONST = require('../../math/const');
89

910
// points is an array of Point-like objects,
1011
// either 2 dimensional arrays, or objects with public x/y properties:
@@ -39,8 +40,8 @@ var FromPoints = function (points, out)
3940
var minX = Number.MAX_VALUE;
4041
var minY = Number.MAX_VALUE;
4142

42-
var maxX = Number.MIN_SAFE_INTEGER;
43-
var maxY = Number.MIN_SAFE_INTEGER;
43+
var maxX = MATH_CONST.MIN_SAFE_INTEGER;
44+
var maxY = MATH_CONST.MIN_SAFE_INTEGER;
4445

4546
var p;
4647
var px;

src/math/const.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,27 @@ var MATH_CONST = {
5959
* @type {Phaser.Math.RandomDataGenerator}
6060
* @since 3.0.0
6161
*/
62-
RND: null
62+
RND: null,
63+
64+
/**
65+
* The minimum safe integer this browser supports.
66+
* We use a const for backward compatibility with Internet Explorer.
67+
*
68+
* @name Phaser.Math.MIN_SAFE_INTEGER
69+
* @type {number}
70+
* @since 3.21.0
71+
*/
72+
MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER || -9007199254740991,
73+
74+
/**
75+
* The maximum safe integer this browser supports.
76+
* We use a const for backward compatibility with Internet Explorer.
77+
*
78+
* @name Phaser.Math.MAX_SAFE_INTEGER
79+
* @type {number}
80+
* @since 3.21.0
81+
*/
82+
MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER || 9007199254740991
6383

6484
};
6585

src/tweens/builders/StaggerBuilder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var GetEaseFunction = require('./GetEaseFunction');
88
var GetValue = require('../../utils/object/GetValue');
9+
var MATH_CONST = require('../../math/const');
910

1011
/**
1112
* Creates a Stagger function to be used by a Tween property.
@@ -105,7 +106,7 @@ var StaggerBuilder = function (value, options)
105106
fromY = (gridHeight - 1) / 2;
106107
}
107108

108-
var gridMax = Number.MIN_SAFE_INTEGER;
109+
var gridMax = MATH_CONST.MIN_SAFE_INTEGER;
109110

110111
for (var toY = 0; toY < gridHeight; toY++)
111112
{

src/tweens/tween/Tween.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var Events = require('../events');
1010
var GameObjectCreator = require('../../gameobjects/GameObjectCreator');
1111
var GameObjectFactory = require('../../gameobjects/GameObjectFactory');
1212
var TWEEN_CONST = require('./const');
13+
var MATH_CONST = require('../../math/const');
1314

1415
/**
1516
* @classdesc
@@ -516,7 +517,7 @@ var Tween = new Class({
516517
calcDuration: function ()
517518
{
518519
var maxDuration = 0;
519-
var minDelay = Number.MAX_SAFE_INTEGER;
520+
var minDelay = MATH_CONST.MAX_SAFE_INTEGER;
520521

521522
var data = this.data;
522523

0 commit comments

Comments
 (0)