diff --git a/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart b/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart index 5700a3165d9..a8e6e12ab80 100644 --- a/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart +++ b/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart @@ -28,7 +28,7 @@ import 'dart:typed_data' show Endian, Uint8List, Uint16List; String _symbolToString(Symbol symbol) => symbol is PrivateSymbol ? PrivateSymbol.getName(symbol) - : _symbol_dev.Symbol.getName(symbol); + : _symbol_dev.Symbol.getName(symbol as _symbol_dev.Symbol); @patch int identityHashCode(Object? object) { @@ -102,7 +102,7 @@ class Null { @patch class Function { @patch - static apply(Function f, List? positionalArguments, + static apply(Function function, List? positionalArguments, [Map? namedArguments]) { positionalArguments ??= []; // dcall expects the namedArguments as a JS map in the last slot. @@ -111,9 +111,9 @@ class Function { namedArguments.forEach((symbol, arg) { JS('', '#[#] = #', map, _symbolToString(symbol), arg); }); - return dart.dcall(f, positionalArguments, map); + return dart.dcall(function, positionalArguments, map); } - return dart.dcall(f, positionalArguments); + return dart.dcall(function, positionalArguments); } static Map _toMangledNames( @@ -132,14 +132,14 @@ class Function { @JSExportName('as') static Object _as_Function(Object o) { // Avoid extra function call to core.Function.is() by manually inlining. - if (JS('!', 'typeof $o == "function"') || o == null) return o; + if (JS('!', 'typeof $o == "function"') || o == null) return o; return dart.cast(o, dart.unwrapType(Function), false); } @JSExportName('_check') static Object _check_Function(Object o) { // Avoid extra function call to core.Function.is() by manually inlining. - if (JS('!', 'typeof $o == "function"') || o == null) return o; + if (JS('!', 'typeof $o == "function"') || o == null) return o; return dart.cast(o, dart.unwrapType(Function), true); } } @@ -188,7 +188,7 @@ class int { @patch static int parse(String source, {int? radix, @deprecated int onError(String source)?}) { - return Primitives.parseInt(source, radix, onError)!; + return Primitives.parseInt(source, radix, onError); } @patch @@ -233,8 +233,8 @@ class int { class double { @patch static double parse(String source, - [@deprecated double onError(String source)]) { - return Primitives.parseDouble(source, onError)!; + [@deprecated double onError(String source)?]) { + return Primitives.parseDouble(source, onError); } @patch @@ -308,7 +308,7 @@ class BigInt implements Comparable { @patch class Error { @patch - static String _objectToString(Object? object) { + static String _objectToString(Object object) { return "Instance of '${dart.typeName(dart.getReifiedType(object))}'"; } @@ -452,7 +452,7 @@ class DateTime { int get weekday => Primitives.getWeekday(this); @patch - bool operator ==(dynamic other) => + bool operator ==(Object other) => other is DateTime && _value == other.millisecondsSinceEpoch && isUtc == other.isUtc; @@ -505,16 +505,16 @@ class Stopwatch { @patch class List { @patch - factory List([@undefined int _length]) { + factory List([@undefined int? length]) { dynamic list; - if (JS('!', '# === void 0', _length)) { + if (JS('!', '# === void 0', length)) { list = JS('', '[]'); } else { - int length = JS('!', '#', _length); - if (_length == null || length < 0) { + int _length = JS('!', '#', length); + if (length == null || _length < 0) { throw ArgumentError("Length must be a non-negative integer: $_length"); } - list = JS('', 'new Array(#)', length); + list = JS('', 'new Array(#)', _length); JS('', '#.fill(null)', list); JSArray.markFixedList(list); } @@ -522,7 +522,7 @@ class List { } @patch - factory List.empty({bool growable = false}) { + factory List.empty({bool growable = true}) { var list = JSArray.of(JS('', 'new Array()')); if (!growable) JSArray.markFixedList(list); return list; @@ -565,7 +565,7 @@ class List { @patch class Map { @patch - factory Map.unmodifiable(Map other) { + factory Map.unmodifiable(Map other) { return UnmodifiableMapView(Map.from(other)); } @@ -740,7 +740,7 @@ class StringBuffer { } @patch - void writeAll(Iterable objects, [String separator = ""]) { + void writeAll(Iterable objects, [String separator = ""]) { _contents = _writeAll(_contents, objects, separator); } @@ -1003,14 +1003,14 @@ class _BigIntImpl implements BigInt { // Result cache for last _divRem call. // Result cache for last _divRem call. - static Uint16List _lastDividendDigits; - static int _lastDividendUsed; - static Uint16List _lastDivisorDigits; - static int _lastDivisorUsed; - static Uint16List _lastQuoRemDigits; - static int _lastQuoRemUsed; - static int _lastRemUsed; - static int _lastRem_nsh; + static Uint16List? _lastDividendDigits; + static int? _lastDividendUsed; + static Uint16List? _lastDivisorDigits; + static int? _lastDivisorUsed; + static Uint16List? _lastQuoRemDigits; + static int? _lastQuoRemUsed; + static int? _lastRemUsed; + static int? _lastRem_nsh; /// Whether this bigint is negative. final bool _isNegative; @@ -1070,7 +1070,7 @@ class _BigIntImpl implements BigInt { // Read in the source 4 digits at a time. // The first part may have a few leading virtual '0's to make the remaining // parts all have exactly 4 digits. - int digitInPartCount = 4 - source.length.remainder(4); + var digitInPartCount = 4 - source.length.remainder(4); if (digitInPartCount == 4) digitInPartCount = 0; for (int i = 0; i < source.length; i++) { part = part * 10 + source.codeUnitAt(i) - _0; @@ -1112,7 +1112,7 @@ class _BigIntImpl implements BigInt { /// If [isNegative] is true, negates the result before returning it. /// /// The [source] (substring) must be a valid hex literal. - static _BigIntImpl _parseHex(String source, int startPos, bool isNegative) { + static _BigIntImpl? _parseHex(String source, int startPos, bool isNegative) { int hexDigitsPerChunk = _digitBits ~/ 4; int sourceLength = source.length - startPos; int chunkCount = (sourceLength / hexDigitsPerChunk).ceil(); @@ -1146,7 +1146,7 @@ class _BigIntImpl implements BigInt { /// /// The [source] will be checked for invalid characters. If it is invalid, /// this function returns `null`. - static _BigIntImpl _parseRadix(String source, int radix, bool isNegative) { + static _BigIntImpl? _parseRadix(String source, int radix, bool isNegative) { var result = zero; var base = _BigIntImpl._fromInt(radix); for (int i = 0; i < source.length; i++) { @@ -1198,11 +1198,11 @@ class _BigIntImpl implements BigInt { return _parseDecimal(decimalMatch, isNegative); } if (radix == 16 && (decimalMatch != null || nonDecimalMatch != null)) { - return _parseHex(decimalMatch ?? nonDecimalMatch, 0, isNegative); + return _parseHex(decimalMatch ?? nonDecimalMatch!, 0, isNegative); } return _parseRadix( - decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative); + decimalMatch ?? nonDecimalMatch ?? hexMatch!, radix, isNegative); } static RegExp _parseRE = RegExp( @@ -1250,7 +1250,7 @@ class _BigIntImpl implements BigInt { // then use the bit-manipulating `_fromDouble` for all other values. if (value.abs() < 0x100000000) return _BigIntImpl._fromInt(value.toInt()); if (value is double) return _BigIntImpl._fromDouble(value); - return _BigIntImpl._fromInt(value); + return _BigIntImpl._fromInt(value as int); } factory _BigIntImpl._fromInt(int value) { @@ -2014,9 +2014,9 @@ class _BigIntImpl implements BigInt { _divRem(other); // Return quotient, i.e. // _lastQuoRem_digits[_lastRem_used.._lastQuoRem_used-1] with proper sign. - var lastQuo_used = _lastQuoRemUsed - _lastRemUsed; + var lastQuo_used = _lastQuoRemUsed! - _lastRemUsed!; var quo_digits = _cloneDigits( - _lastQuoRemDigits, _lastRemUsed, _lastQuoRemUsed, lastQuo_used); + _lastQuoRemDigits!, _lastRemUsed!, _lastQuoRemUsed!, lastQuo_used); var quo = _BigIntImpl._(false, lastQuo_used, quo_digits); if ((_isNegative != other._isNegative) && (quo._used > 0)) { quo = -quo; @@ -2034,10 +2034,10 @@ class _BigIntImpl implements BigInt { // Return remainder, i.e. // denormalized _lastQuoRem_digits[0.._lastRem_used-1] with proper sign. var remDigits = - _cloneDigits(_lastQuoRemDigits, 0, _lastRemUsed, _lastRemUsed); - var rem = _BigIntImpl._(false, _lastRemUsed, remDigits); - if (_lastRem_nsh > 0) { - rem = rem >> _lastRem_nsh; // Denormalize remainder. + _cloneDigits(_lastQuoRemDigits!, 0, _lastRemUsed!, _lastRemUsed!); + var rem = _BigIntImpl._(false, _lastRemUsed!, remDigits); + if (_lastRem_nsh! > 0) { + rem = rem >> _lastRem_nsh!; // Denormalize remainder. } if (_isNegative && (rem._used > 0)) { rem = -rem; diff --git a/sdk_nnbd/lib/_internal/js_dev_runtime/private/js_helper.dart b/sdk_nnbd/lib/_internal/js_dev_runtime/private/js_helper.dart index e86378de6da..dcf1866a052 100644 --- a/sdk_nnbd/lib/_internal/js_dev_runtime/private/js_helper.dart +++ b/sdk_nnbd/lib/_internal/js_dev_runtime/private/js_helper.dart @@ -203,7 +203,7 @@ class Primitives { } static int timerFrequency; - static num Function() timerTicks; + static int Function() timerTicks; static bool get isD8 { return JS( @@ -268,7 +268,7 @@ class Primitives { } @notNull - static String stringFromCharCodes(JSArray charCodes) { + static String stringFromCharCodes(List charCodes) { for (@nullCheck var i in charCodes) { if (i < 0) throw argumentErrorValue(i); if (i > 0xffff) return stringFromCodePoints(charCodes); @@ -362,7 +362,7 @@ class Primitives { return -JS('!', r'#.getTimezoneOffset()', lazyAsJsDate(receiver)); } - static num valueFromDecomposedDate( + static int valueFromDecomposedDate( @nullCheck int years, @nullCheck int month, @nullCheck int day, @@ -375,10 +375,10 @@ class Primitives { var jsMonth = month - 1; num value; if (isUtc) { - value = JS('!', r'Date.UTC(#, #, #, #, #, #, #)', years, jsMonth, day, - hours, minutes, seconds, milliseconds); + value = JS('!', r'Date.UTC(#, #, #, #, #, #, #)', years, jsMonth, + day, hours, minutes, seconds, milliseconds); } else { - value = JS('!', r'new Date(#, #, #, #, #, #, #).valueOf()', years, + value = JS('!', r'new Date(#, #, #, #, #, #, #).valueOf()', years, jsMonth, day, hours, minutes, seconds, milliseconds); } if (value.isNaN || @@ -390,14 +390,14 @@ class Primitives { return value; } - static num patchUpY2K(value, years, isUtc) { - var date = JS('', r'new Date(#)', value); + static int patchUpY2K(value, years, isUtc) { + var date = JS('!', r'new Date(#)', value); if (isUtc) { - JS('', r'#.setUTCFullYear(#)', date, years); + JS('!', r'#.setUTCFullYear(#)', date, years); } else { - JS('', r'#.setFullYear(#)', date, years); + JS('!', r'#.setFullYear(#)', date, years); } - return JS('!', r'#.valueOf()', date); + return JS('!', r'#.valueOf()', date); } // Lazily keep a JS Date stored in the JS object.