Skip to content

Commit

Permalink
Fixes for [33282](dart-lang/sdk#33282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dana-Ferguson committed Jul 14, 2018
1 parent cc8dfed commit de23433
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 3 additions & 1 deletion lib/src/duration.dart
Expand Up @@ -38,8 +38,10 @@ abstract class ITime {
static final /*BigInt*/ int maxNanoseconds = (maxDays + 1 /*BigInteger.One*/) * TimeConstants.nanosecondsPerDay - 1;

// 285420 years worth -- we are good for anything;
// todo: should this be specific to the Platform?
// todo: why was minMillis == -9007199254740993, which is Platform.intMinValueJS-1;
static const int maxMillis = Platform.intMaxValueJS;
static const int minMillis = -9007199254740993; // Utility.intMinValueJS; // was -maxMillis; very shortly was ~maxMillis (which I guess doesn't work well in JS)
static const int minMillis = Platform.intMinValueJS; // -9007199254740993; // Utility.intMinValueJS; // was -maxMillis; very shortly was ~maxMillis (which I guess doesn't work well in JS)

static bool isInt64Representable(Time span) => span._isInt64Representable;
static Time plusSmallNanoseconds(Time span, int nanoseconds) => span._plusSmallNanoseconds(nanoseconds);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/text/value_cursor.dart
Expand Up @@ -126,7 +126,7 @@ class ValueCursor extends TextCursor {
}
int count = 0;
int digit;
while (result < 922337203685477580 && (digit = _getDigit()) != -1) {
while (result < Platform.valueCursorPrediction && (digit = _getDigit()) != -1) {
result = result * 10 + digit;
count++;
if (!moveNext()) {
Expand All @@ -139,8 +139,8 @@ class ValueCursor extends TextCursor {
return IParseResult.missingNumber<int>(this);
}

if (result >= 922337203685477580 && (digit = _getDigit()) != -1) {
if (result > 922337203685477580) {
if (result >= Platform.valueCursorPrediction && (digit = _getDigit()) != -1) {
if (result > Platform.valueCursorPrediction) {
return _buildNumberOutOfRangeResult<int>(startIndex, tType);
}
if (negative && digit == 8) {
Expand Down
25 changes: 10 additions & 15 deletions lib/src/utility/utilities.dart
Expand Up @@ -38,12 +38,16 @@ abstract class Platform {
static bool get isWeb => _isWeb ?? dirtyCheck() ?? _isWeb;
static bool get isVM => _isVM ?? dirtyCheck() ?? _isVM;

static const intMaxValueJS = 9007199254740992; // math.pow(2, 53);
static const intMinValueJS = -9007199254740992; // -math.pow(2, 53); appears to be the same (not 1 more, not 1 less)
static const int32MinValue = -2147483648;
static const int32MaxValue = 2147483647;
static const int64MinValue = -9223372036854775808;
static const int64MaxValue = 9223372036854775807;
static const int intMaxValueJS = 9007199254740992; // math.pow(2, 53);
static const int intMinValueJS = -9007199254740992; // -math.pow(2, 53); appears to be the same (not 1 more, not 1 less)
static const int int32MinValue = -2147483648;
static const int int32MaxValue = 2147483647;

// representable in JS and VM: +\- 9223372036854775000 (but, constants in JS must be bounded by intMinValueJS and intMaxValueJS)
// Fix for: https://github.com/dart-lang/sdk/issues/33282 <-- bizarre
static const int valueCursorPrediction = 13860*66546695792603; // vm: 922337203685477580; js: 922337203685477600
static const int int64MinValue = 2147483648 * 2147483648 * -2; // vm: -9223372036854775808; js: -9223372036854776000
static const int int64MaxValue = 2147483648 * 2147483648 - 1 + 2147483648 * 2147483648; // vm: 9223372036854775807; js: 9223372036854776000

static int _intMaxValue = isVM ? _intMaxValue = int64MaxValue : _intMaxValue = intMaxValueJS;
static int _intMinValue = isVM ? _intMinValue = int64MinValue : _intMinValue = intMinValueJS;
Expand All @@ -61,15 +65,6 @@ abstract class IDateTimeZoneWriter {
//
}

// todo: all of these may affect performance

// todo: only use this for porting... remove all of these later
@deprecated
class OutBox<T> {
T value;
OutBox(this.value);
}

// https://en.wikipedia.org/wiki/Modulo_operation
// we should only use this where 'x' can be negative
int arithmeticMod(num x, int y) {
Expand Down

0 comments on commit de23433

Please sign in to comment.