From 85beb0398dbd3a9d7bf34a89f118d9bd03162455 Mon Sep 17 00:00:00 2001 From: Mayank Patke Date: Thu, 27 Mar 2025 13:46:20 -0700 Subject: [PATCH] [dart2js] `dart format` js_runtime. Change-Id: I257139079514cb4cb21be51743f6bdd9fcab35e0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417322 Reviewed-by: Stephen Adams Reviewed-by: Sigmund Cherem --- pkg/js_runtime/lib/synced/array_flags.dart | 6 +- .../_internal/js_runtime/lib/async_patch.dart | 173 +++++++++------ .../js_runtime/lib/bigint_patch.dart | 176 ++++++++++++---- .../js_runtime/lib/collection_patch.dart | 52 +++-- .../js_runtime/lib/constant_map.dart | 6 +- .../js_runtime/lib/convert_patch.dart | 13 +- .../_internal/js_runtime/lib/core_patch.dart | 199 ++++++++++++------ .../js_runtime/lib/developer_patch.dart | 91 +++++--- .../_internal/js_runtime/lib/io_patch.dart | 180 ++++++++++------ .../js_runtime/lib/isolate_patch.dart | 58 +++-- .../lib/js_allow_interop_patch.dart | 151 +++++++------ .../_internal/js_runtime/lib/js_number.dart | 68 +++--- .../_internal/js_runtime/lib/js_patch.dart | 75 +++++-- .../js_runtime/lib/linked_hash_map.dart | 6 +- .../_internal/js_runtime/lib/math_patch.dart | 28 ++- .../js_runtime/lib/native_helper.dart | 56 +++-- .../js_runtime/lib/string_helper.dart | 116 +++++++--- .../js_runtime/lib/synced/array_flags.dart | 6 +- 18 files changed, 957 insertions(+), 503 deletions(-) diff --git a/pkg/js_runtime/lib/synced/array_flags.dart b/pkg/js_runtime/lib/synced/array_flags.dart index 319b7372979..17663676333 100644 --- a/pkg/js_runtime/lib/synced/array_flags.dart +++ b/pkg/js_runtime/lib/synced/array_flags.dart @@ -83,8 +83,7 @@ class ArrayFlags { ';setUint16' ';setUint32' ';setFloat32' - ';setFloat64' - // + ';setFloat64' // ; /// A list of 'verbs' for HArrayFlagsCheck, encoded as a string of phrases @@ -102,8 +101,7 @@ class ArrayFlags { static const verbs = // 'modify' // This is the verb for '[]=' so it comes first. ';remove from' - ';add to' - // + ';add to' // ; /// A view of [operationNames] as a map from the name to the index of the name diff --git a/sdk/lib/_internal/js_runtime/lib/async_patch.dart b/sdk/lib/_internal/js_runtime/lib/async_patch.dart index ec48de1c14b..d0fd915471e 100644 --- a/sdk/lib/_internal/js_runtime/lib/async_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/async_patch.dart @@ -55,8 +55,11 @@ class _AsyncRun { f!(); } - var observer = JS('', 'new self.MutationObserver(#)', - convertDartClosureToJS(internalCallback, 1)); + var observer = JS( + '', + 'new self.MutationObserver(#)', + convertDartClosureToJS(internalCallback, 1), + ); JS('', '#.observe(#, { childList: true })', observer, div); return (void callback()) { @@ -64,8 +67,15 @@ class _AsyncRun { storedCallback = callback; // Because of a broken shadow-dom polyfill we have to change the // children instead a cheap property. - JS('', '#.firstChild ? #.removeChild(#): #.appendChild(#)', div, div, - span, div, span); + JS( + '', + '#.firstChild ? #.removeChild(#): #.appendChild(#)', + div, + div, + span, + div, + span, + ); }; } else if (JS('', 'self.setImmediate') != null) { return _scheduleImmediateWithSetImmediate; @@ -79,8 +89,11 @@ class _AsyncRun { callback(); } - JS('void', 'self.scheduleImmediate(#)', - convertDartClosureToJS(internalCallback, 0)); + JS( + 'void', + 'self.scheduleImmediate(#)', + convertDartClosureToJS(internalCallback, 0), + ); } static void _scheduleImmediateWithSetImmediate(void callback()) { @@ -88,8 +101,11 @@ class _AsyncRun { callback(); } - JS('void', 'self.setImmediate(#)', - convertDartClosureToJS(internalCallback, 0)); + JS( + 'void', + 'self.setImmediate(#)', + convertDartClosureToJS(internalCallback, 0), + ); } static void _scheduleImmediateWithTimer(void callback()) { @@ -108,7 +124,9 @@ class Timer { @patch static Timer _createPeriodicTimer( - Duration duration, void callback(Timer timer)) { + Duration duration, + void callback(Timer timer), + ) { int milliseconds = duration.inMilliseconds; if (milliseconds < 0) milliseconds = 0; return _TimerImpl.periodic(milliseconds, callback); @@ -128,33 +146,38 @@ class _TimerImpl implements Timer { callback(); } - _handle = JS('int', 'self.setTimeout(#, #)', - convertDartClosureToJS(internalCallback, 0), milliseconds); + _handle = JS( + 'int', + 'self.setTimeout(#, #)', + convertDartClosureToJS(internalCallback, 0), + milliseconds, + ); } else { throw UnsupportedError('`setTimeout()` not found.'); } } _TimerImpl.periodic(int milliseconds, void callback(Timer timer)) - : _once = false { + : _once = false { if (_hasTimer()) { int start = JS('int', 'Date.now()'); _handle = JS( - 'int', - 'self.setInterval(#, #)', - convertDartClosureToJS(() { - int tick = this._tick + 1; - if (milliseconds > 0) { - int end = JS('int', 'Date.now()'); - int duration = end - start; - if (duration > (tick + 1) * milliseconds) { - tick = duration ~/ milliseconds; - } + 'int', + 'self.setInterval(#, #)', + convertDartClosureToJS(() { + int tick = this._tick + 1; + if (milliseconds > 0) { + int end = JS('int', 'Date.now()'); + int duration = end - start; + if (duration > (tick + 1) * milliseconds) { + tick = duration ~/ milliseconds; } - this._tick = tick; - callback(this); - }, 0), - milliseconds); + } + this._tick = tick; + callback(this); + }, 0), + milliseconds, + ); } else { throw UnsupportedError('Periodic timer.'); } @@ -236,7 +259,9 @@ Completer _makeAsyncAwaitCompleter() { /// Independently, it takes the [completer] and returns the future of the /// completer for convenience of the transformed code. dynamic _asyncStartSync( - _WrappedAsyncBody bodyFunction, _AsyncAwaitCompleter completer) { + _WrappedAsyncBody bodyFunction, + _AsyncAwaitCompleter completer, +) { bodyFunction(async_status_codes.SUCCESS, null); completer.isSync = true; return completer.future; @@ -271,7 +296,9 @@ dynamic _asyncReturn(dynamic object, Completer completer) { dynamic _asyncRethrow(dynamic object, Completer completer) { // The error is a js-error. completer.completeError( - unwrapException(object), getTraceFromException(object)); + unwrapException(object), + getTraceFromException(object), + ); } /// Awaits on the given [object]. @@ -286,8 +313,10 @@ void _awaitOnObject(object, _WrappedAsyncBody bodyFunction) { (result) => bodyFunction(async_status_codes.SUCCESS, result); Function errorCallback = (dynamic error, StackTrace stackTrace) { - ExceptionAndStackTrace wrappedException = - ExceptionAndStackTrace(error, stackTrace); + ExceptionAndStackTrace wrappedException = ExceptionAndStackTrace( + error, + stackTrace, + ); bodyFunction(async_status_codes.ERROR, wrappedException); }; @@ -309,8 +338,8 @@ typedef _WrappedAsyncBody = void Function(int errorCode, dynamic result); _WrappedAsyncBody _wrapJsFunctionForAsync(dynamic /* js function */ function) { var protected = JS( - '', - """ + '', + """ (function (fn, ERROR) { // Invokes [function] with [errorCode] and [result]. // @@ -328,8 +357,9 @@ _WrappedAsyncBody _wrapJsFunctionForAsync(dynamic /* js function */ function) { } } })(#, #)""", - function, - async_status_codes.ERROR); + function, + async_status_codes.ERROR, + ); return Zone.current.registerBinaryCallback((int errorCode, dynamic result) { JS('', '#(#, #)', protected, errorCode, result); @@ -373,9 +403,10 @@ _WrappedAsyncBody _wrapJsFunctionForAsync(dynamic /* js function */ function) { /// If [object] is not a [Future], it is wrapped in a `Future.value`. /// The [asyncBody] is called on completion of the future (see [asyncHelper]. void _asyncStarHelper( - dynamic object, - dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode, - _AsyncStarStreamController controller) { + dynamic object, + dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode, + _AsyncStarStreamController controller, +) { if (identical(bodyFunctionOrErrorCode, async_status_codes.SUCCESS)) { // This happens on return from the async* function. if (controller.isCanceled) { @@ -388,10 +419,14 @@ void _asyncStarHelper( // The error is a js-error. if (controller.isCanceled) { controller.cancelationFuture!._completeError( - unwrapException(object), getTraceFromException(object)); + unwrapException(object), + getTraceFromException(object), + ); } else { controller.addError( - unwrapException(object), getTraceFromException(object)); + unwrapException(object), + getTraceFromException(object), + ); controller.close(); } return; @@ -415,10 +450,11 @@ void _asyncStarHelper( return; } bodyFunction( - controller.isCanceled - ? async_status_codes.STREAM_WAS_CANCELED - : async_status_codes.SUCCESS, - null); + controller.isCanceled + ? async_status_codes.STREAM_WAS_CANCELED + : async_status_codes.SUCCESS, + null, + ); }); return; } else if (object.state == _IterationMarker.YIELD_STAR) { @@ -429,9 +465,10 @@ void _asyncStarHelper( // No need to check for pause because to get here the stream either // completed normally or was cancelled. The stream cannot be paused // after either of these states. - int errorCode = controller.isCanceled - ? async_status_codes.STREAM_WAS_CANCELED - : async_status_codes.SUCCESS; + int errorCode = + controller.isCanceled + ? async_status_codes.STREAM_WAS_CANCELED + : async_status_codes.SUCCESS; bodyFunction(errorCode, null); }); return; @@ -491,30 +528,34 @@ class _AsyncStarStreamController { }); } - controller = StreamController(onListen: () { - _resumeBody(); - }, onResume: () { - // Only schedule again if the async* function actually is suspended. - // Resume directly instead of scheduling, so that the sequence - // `pause-resume-pause` will result in one extra event produced. - if (isSuspended) { - isSuspended = false; + controller = StreamController( + onListen: () { _resumeBody(); - } - }, onCancel: () { - // If the async* is finished we ignore cancel events. - if (!controller.isClosed) { - cancelationFuture = _Future(); + }, + onResume: () { + // Only schedule again if the async* function actually is suspended. + // Resume directly instead of scheduling, so that the sequence + // `pause-resume-pause` will result in one extra event produced. if (isSuspended) { - // Resume the suspended async* function to run finalizers. isSuspended = false; - scheduleMicrotask(() { - body(async_status_codes.STREAM_WAS_CANCELED, null); - }); + _resumeBody(); } - return cancelationFuture; - } - }); + }, + onCancel: () { + // If the async* is finished we ignore cancel events. + if (!controller.isClosed) { + cancelationFuture = _Future(); + if (isSuspended) { + // Resume the suspended async* function to run finalizers. + isSuspended = false; + scheduleMicrotask(() { + body(async_status_codes.STREAM_WAS_CANCELED, null); + }); + } + return cancelationFuture; + } + }, + ); } } diff --git a/sdk/lib/_internal/js_runtime/lib/bigint_patch.dart b/sdk/lib/_internal/js_runtime/lib/bigint_patch.dart index 57155934dc0..6a6f307b659 100644 --- a/sdk/lib/_internal/js_runtime/lib/bigint_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/bigint_patch.dart @@ -282,12 +282,16 @@ class _BigIntImpl implements BigInt { } return _parseRadix( - decimalMatch ?? nonDecimalMatch ?? hexMatch!, radix, isNegative); + decimalMatch ?? nonDecimalMatch ?? hexMatch!, + radix, + isNegative, + ); } static RegExp _parseRE = RegExp( - r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$', - caseSensitive: false); + r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$', + caseSensitive: false, + ); /// Finds the amount significant digits in the provided [digits] array. static int _normalize(int used, Uint16List digits) { @@ -299,10 +303,10 @@ class _BigIntImpl implements BigInt { /// If the [digits] array contains leading 0s, the [used] value is adjusted /// accordingly. The [digits] array is not modified. _BigIntImpl._(bool isNegative, int used, Uint16List digits) - : this._normalized(isNegative, _normalize(used, digits), digits); + : this._normalized(isNegative, _normalize(used, digits), digits); _BigIntImpl._normalized(bool isNegative, this._used, this._digits) - : _isNegative = _used == 0 ? false : isNegative; + : _isNegative = _used == 0 ? false : isNegative; /// Whether this big integer is zero. bool get _isZero => _used == 0; @@ -311,7 +315,11 @@ class _BigIntImpl implements BigInt { /// range [from] to [to-1], starting at index 0, followed by leading zero /// digits. static Uint16List _cloneDigits( - Uint16List digits, int from, int to, int length) { + Uint16List digits, + int from, + int to, + int length, + ) { var resultDigits = Uint16List(length); var n = to - from; for (var i = 0; i < n; i++) { @@ -449,7 +457,11 @@ class _BigIntImpl implements BigInt { /// /// `resultDigits[0..resultUsed-1] = xDigits[0..xUsed-1] << n*_DIGIT_BITS`. static int _dlShiftDigits( - Uint16List xDigits, int xUsed, int n, Uint16List resultDigits) { + Uint16List xDigits, + int xUsed, + int n, + Uint16List resultDigits, + ) { if (xUsed == 0) { return 0; } @@ -500,7 +512,11 @@ class _BigIntImpl implements BigInt { /// /// Does *not* clear digits below ds. static void _lsh( - Uint16List xDigits, int xUsed, int n, Uint16List resultDigits) { + Uint16List xDigits, + int xUsed, + int n, + Uint16List resultDigits, + ) { assert(xUsed > 0); final digitShift = n ~/ _digitBits; final bitShift = n % _digitBits; @@ -544,7 +560,11 @@ class _BigIntImpl implements BigInt { // resultDigits[0..resultUsed-1] = xDigits[0..xUsed-1] << n. // Returns resultUsed. static int _lShiftDigits( - Uint16List xDigits, int xUsed, int n, Uint16List resultDigits) { + Uint16List xDigits, + int xUsed, + int n, + Uint16List resultDigits, + ) { final digitsShift = n ~/ _digitBits; final bitShift = n % _digitBits; if (bitShift == 0) { @@ -564,7 +584,11 @@ class _BigIntImpl implements BigInt { // resultDigits[0..resultUsed-1] = xDigits[0..xUsed-1] >> n. static void _rsh( - Uint16List xDigits, int xUsed, int n, Uint16List resultDigits) { + Uint16List xDigits, + int xUsed, + int n, + Uint16List resultDigits, + ) { assert(xUsed > 0); final digitsShift = n ~/ _digitBits; final bitShift = n % _digitBits; @@ -646,7 +670,11 @@ class _BigIntImpl implements BigInt { /// Returns 0 if equal; a positive number if larger; /// and a negative number if smaller. static int _compareDigits( - Uint16List digits, int used, Uint16List otherDigits, int otherUsed) { + Uint16List digits, + int used, + Uint16List otherDigits, + int otherUsed, + ) { var result = used - otherUsed; if (result == 0) { for (int i = used - 1; i >= 0; i--) { @@ -659,8 +687,13 @@ class _BigIntImpl implements BigInt { // resultDigits[0..used] = digits[0..used-1] + otherDigits[0..otherUsed-1]. // used >= otherUsed > 0. - static void _absAdd(Uint16List digits, int used, Uint16List otherDigits, - int otherUsed, Uint16List resultDigits) { + static void _absAdd( + Uint16List digits, + int used, + Uint16List otherDigits, + int otherUsed, + Uint16List resultDigits, + ) { assert(used >= otherUsed && otherUsed > 0); var carry = 0; for (var i = 0; i < otherUsed; i++) { @@ -678,8 +711,13 @@ class _BigIntImpl implements BigInt { // resultDigits[0..used-1] = digits[0..used-1] - otherDigits[0..otherUsed-1]. // used >= otherUsed > 0. - static void _absSub(Uint16List digits, int used, Uint16List otherDigits, - int otherUsed, Uint16List resultDigits) { + static void _absSub( + Uint16List digits, + int used, + Uint16List otherDigits, + int otherUsed, + Uint16List resultDigits, + ) { assert(used >= otherUsed && otherUsed > 0); var carry = 0; @@ -997,8 +1035,14 @@ class _BigIntImpl implements BigInt { /// Adds the result of the multiplicand-digits * [x] to the accumulator. /// /// Concretely: `accumulatorDigits[j..j+n] += x * m_digits[i..i+n-1]`. - static void _mulAdd(int x, Uint16List multiplicandDigits, int i, - Uint16List accumulatorDigits, int j, int n) { + static void _mulAdd( + int x, + Uint16List multiplicandDigits, + int i, + Uint16List accumulatorDigits, + int j, + int n, + ) { if (x == 0) { // No-op if x is 0. return; @@ -1036,13 +1080,21 @@ class _BigIntImpl implements BigInt { i++; } return _BigIntImpl._( - _isNegative != other._isNegative, resultUsed, resultDigits); + _isNegative != other._isNegative, + resultUsed, + resultDigits, + ); } // r_digits[0..rUsed-1] = xDigits[0..xUsed-1]*otherDigits[0..otherUsed-1]. // Return resultUsed = xUsed + otherUsed. - static int _mulDigits(Uint16List xDigits, int xUsed, Uint16List otherDigits, - int otherUsed, Uint16List resultDigits) { + static int _mulDigits( + Uint16List xDigits, + int xUsed, + Uint16List otherDigits, + int otherUsed, + Uint16List resultDigits, + ) { var resultUsed = xUsed + otherUsed; var i = resultUsed; assert(resultDigits.length >= i); @@ -1059,7 +1111,10 @@ class _BigIntImpl implements BigInt { /// Returns an estimate of `digits[i-1..i] ~/ topDigitDivisor`. static int _estimateQuotientDigit( - int topDigitDivisor, Uint16List digits, int i) { + int topDigitDivisor, + Uint16List digits, + int i, + ) { if (digits[i] == topDigitDivisor) return _digitMask; var quotientDigit = (digits[i] << _digitBits | digits[i - 1]) ~/ topDigitDivisor; @@ -1078,7 +1133,11 @@ class _BigIntImpl implements BigInt { // _lastQuoRem_digits[_lastRem_used.._lastQuoRem_used-1] with proper sign. 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; @@ -1095,8 +1154,12 @@ class _BigIntImpl implements BigInt { _divRem(other); // Return remainder, i.e. // denormalized _lastQuoRem_digits[0.._lastRem_used-1] with proper sign. - var remDigits = - _cloneDigits(_lastQuoRemDigits, 0, _lastRemUsed, _lastRemUsed); + var remDigits = _cloneDigits( + _lastQuoRemDigits, + 0, + _lastRemUsed, + _lastRemUsed, + ); var rem = _BigIntImpl._(false, _lastRemUsed, remDigits); if (_lastRem_nsh > 0) { rem = rem >> _lastRem_nsh; // Denormalize remainder. @@ -1177,8 +1240,11 @@ class _BigIntImpl implements BigInt { --i; while (j > 0) { - var estimatedQuotientDigit = - _estimateQuotientDigit(topDigitDivisor, resultDigits, i); + var estimatedQuotientDigit = _estimateQuotientDigit( + topDigitDivisor, + resultDigits, + i, + ); j--; _mulAdd(estimatedQuotientDigit, nyDigits, 0, resultDigits, j, yUsed); if (resultDigits[i] < estimatedQuotientDigit) { @@ -1401,7 +1467,9 @@ class _BigIntImpl implements BigInt { /// The [exponent] must be non-negative and [modulus] must be /// positive. _BigIntImpl modPow( - covariant _BigIntImpl exponent, covariant _BigIntImpl modulus) { + covariant _BigIntImpl exponent, + covariant _BigIntImpl modulus, + ) { if (exponent._isNegative) { throw ArgumentError("exponent must be positive: $exponent"); } @@ -1429,8 +1497,13 @@ class _BigIntImpl implements BigInt { for (int i = exponentBitlen - 2; i >= 0; i--) { result2Used = z.sqr(resultDigits, resultUsed, result2Digits); if (!(exponent & (one << i))._isZero) { - resultUsed = - z.mul(result2Digits, result2Used, gDigits, gUsed, resultDigits); + resultUsed = z.mul( + result2Digits, + result2Used, + gDigits, + gUsed, + resultDigits, + ); } else { // Swap result and result2. var tmpDigits = resultDigits; @@ -1470,7 +1543,8 @@ class _BigIntImpl implements BigInt { throw ArgumentError.value(0, "other", "must not be zero"); } if (((xUsed == 1) && (xDigits[0] == 1)) || - ((yUsed == 1) && (yDigits[0] == 1))) return one; + ((yUsed == 1) && (yDigits[0] == 1))) + return one; while (((xDigits[0] & 1) == 0) && ((yDigits[0] & 1) == 0)) { _rsh(xDigits, xUsed, 1, xDigits); _rsh(yDigits, yUsed, 1, yDigits); @@ -1493,8 +1567,12 @@ class _BigIntImpl implements BigInt { } } var uDigits = _cloneDigits(xDigits, 0, xUsed, unshiftedMaxUsed); - var vDigits = - _cloneDigits(yDigits, 0, yUsed, unshiftedMaxUsed + 2); // +2 for lsh. + var vDigits = _cloneDigits( + yDigits, + 0, + yUsed, + unshiftedMaxUsed + 2, + ); // +2 for lsh. final bool ac = (xDigits[0] & 1) == 0; // Variables a, b, c, and d require one more digit. @@ -2017,8 +2095,13 @@ class _BigIntImpl implements BigInt { abstract class _BigIntReduction { // Return the number of digits used by r_digits. int convert(_BigIntImpl x, Uint16List r_digits); - int mul(Uint16List xDigits, int xUsed, Uint16List yDigits, int yUsed, - Uint16List resultDigits); + int mul( + Uint16List xDigits, + int xUsed, + Uint16List yDigits, + int yUsed, + Uint16List resultDigits, + ); int sqr(Uint16List xDigits, int xUsed, Uint16List resultDigits); // Return x reverted to _BigIntImpl. @@ -2031,9 +2114,10 @@ class _BigIntClassic implements _BigIntReduction { final _BigIntImpl _normalizedModulus; // Normalized _modulus. _BigIntClassic(this._modulus) - : _normalizedModulus = _modulus << - (_BigIntImpl._digitBits - - _modulus._digits[_modulus._used - 1].bitLength); + : _normalizedModulus = + _modulus << + (_BigIntImpl._digitBits - + _modulus._digits[_modulus._used - 1].bitLength); int convert(_BigIntImpl x, Uint16List resultDigits) { Uint16List digits; @@ -2083,10 +2167,20 @@ class _BigIntClassic implements _BigIntReduction { return _reduce(resultDigits, 2 * xUsed); } - int mul(Uint16List xDigits, int xUsed, Uint16List yDigits, int yUsed, - Uint16List resultDigits) { - var resultUsed = - _BigIntImpl._mulDigits(xDigits, xUsed, yDigits, yUsed, resultDigits); + int mul( + Uint16List xDigits, + int xUsed, + Uint16List yDigits, + int yUsed, + Uint16List resultDigits, + ) { + var resultUsed = _BigIntImpl._mulDigits( + xDigits, + xUsed, + yDigits, + yUsed, + resultDigits, + ); return _reduce(resultDigits, resultUsed); } } diff --git a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart index b7008ac7206..549be8e1bdc 100644 --- a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart @@ -23,10 +23,11 @@ const int _mask30 = 0x3fffffff; // Low 30 bits. @patch class HashMap { @patch - factory HashMap( - {bool equals(K key1, K key2)?, - int hashCode(K key)?, - bool isValidKey(potentialKey)?}) { + factory HashMap({ + bool equals(K key1, K key2)?, + int hashCode(K key)?, + bool isValidKey(potentialKey)?, + }) { if (isValidKey == null) { if (hashCode == null) { if (equals == null) { @@ -405,7 +406,7 @@ base class _CustomHashMap extends _HashMap { final bool Function(Object?) _validKey; _CustomHashMap(this._equals, this._hashCode, bool validKey(potentialKey)?) - : _validKey = (validKey != null) ? validKey : ((v) => v is K); + : _validKey = (validKey != null) ? validKey : ((v) => v is K); V? operator [](Object? key) { if (!_validKey(key)) return null; @@ -503,10 +504,11 @@ class _HashMapKeyIterator implements Iterator { @patch class LinkedHashMap { @patch - factory LinkedHashMap( - {bool equals(K key1, K key2)?, - int hashCode(K key)?, - bool isValidKey(potentialKey)?}) { + factory LinkedHashMap({ + bool equals(K key1, K key2)?, + int hashCode(K key)?, + bool isValidKey(potentialKey)?, + }) { if (isValidKey == null) { if (hashCode == null) { if (equals == null) { @@ -572,8 +574,10 @@ base class _LinkedCustomHashMap extends JsLinkedHashMap { final bool Function(Object?) _validKey; _LinkedCustomHashMap( - this._equals, this._hashCode, bool validKey(potentialKey)?) - : _validKey = (validKey != null) ? validKey : ((v) => v is K); + this._equals, + this._hashCode, + bool validKey(potentialKey)?, + ) : _validKey = (validKey != null) ? validKey : ((v) => v is K); V? operator [](Object? key) { if (!_validKey(key)) return null; @@ -615,10 +619,11 @@ base class _LinkedCustomHashMap extends JsLinkedHashMap { @patch class HashSet { @patch - factory HashSet( - {bool equals(E e1, E e2)?, - int hashCode(E e)?, - bool isValidKey(potentialKey)?}) { + factory HashSet({ + bool equals(E e1, E e2)?, + int hashCode(E e)?, + bool isValidKey(potentialKey)?, + }) { if (isValidKey == null) { if (hashCode == null) { if (equals == null) { @@ -957,7 +962,7 @@ base class _CustomHashSet extends _HashSet { _Hasher _hasher; bool Function(Object?) _validKey; _CustomHashSet(this._equality, this._hasher, bool validKey(potentialKey)?) - : _validKey = (validKey != null) ? validKey : ((x) => x is E); + : _validKey = (validKey != null) ? validKey : ((x) => x is E); Set _newSet() => _CustomHashSet(_equality, _hasher, _validKey); Set _newSimilarSet() => _HashSet(); @@ -1030,10 +1035,11 @@ class _HashSetIterator implements Iterator { @patch class LinkedHashSet { @patch - factory LinkedHashSet( - {bool equals(E e1, E e2)?, - int hashCode(E e)?, - bool isValidKey(potentialKey)?}) { + factory LinkedHashSet({ + bool equals(E e1, E e2)?, + int hashCode(E e)?, + bool isValidKey(potentialKey)?, + }) { if (isValidKey == null) { if (hashCode == null) { if (equals == null) { @@ -1431,8 +1437,10 @@ base class _LinkedCustomHashSet extends _LinkedHashSet { _Hasher _hasher; bool Function(Object?) _validKey; _LinkedCustomHashSet( - this._equality, this._hasher, bool validKey(potentialKey)?) - : _validKey = (validKey != null) ? validKey : ((x) => x is E); + this._equality, + this._hasher, + bool validKey(potentialKey)?, + ) : _validKey = (validKey != null) ? validKey : ((x) => x is E); Set _newSet() => _LinkedCustomHashSet(_equality, _hasher, _validKey); Set _newSimilarSet() => _LinkedHashSet(); diff --git a/sdk/lib/_internal/js_runtime/lib/constant_map.dart b/sdk/lib/_internal/js_runtime/lib/constant_map.dart index 0012ba23410..5697c492a71 100644 --- a/sdk/lib/_internal/js_runtime/lib/constant_map.dart +++ b/sdk/lib/_internal/js_runtime/lib/constant_map.dart @@ -28,8 +28,10 @@ abstract class ConstantMap implements Map { JS('void', '#[#] = #', object, k, index++); } final values = List.from(other.values); - final map = - ConstantStringMap._(object, JS('', '#', values)); + final map = ConstantStringMap._( + object, + JS('', '#', values), + ); map._setKeys(keys); return map; } diff --git a/sdk/lib/_internal/js_runtime/lib/convert_patch.dart b/sdk/lib/_internal/js_runtime/lib/convert_patch.dart index 16ddaa2972a..f169890e5e1 100644 --- a/sdk/lib/_internal/js_runtime/lib/convert_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/convert_patch.dart @@ -30,8 +30,11 @@ _parseJson(String source, reviver(key, value)?) { var parsed; try { - parsed = JS('=Object|JSExtendableArray|Null|bool|num|String', - 'JSON.parse(#)', source); + parsed = JS( + '=Object|JSExtendableArray|Null|bool|num|String', + 'JSON.parse(#)', + source, + ); } catch (e) { throw FormatException(JS('String', 'String(#)', e)); } @@ -308,7 +311,11 @@ class _JsonMap extends MapBase { // ------------------------------------------ static bool _hasProperty(object, String key) => JS( - 'bool', 'Object.prototype.hasOwnProperty.call(#,#)', object, key); + 'bool', + 'Object.prototype.hasOwnProperty.call(#,#)', + object, + key, + ); static _getProperty(object, String key) => JS('', '#[#]', object, key); static _setProperty(object, String key, value) => JS('', '#[#]=#', object, key, value); diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart index a031b4afd51..f8d56963f75 100644 --- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart @@ -83,14 +83,18 @@ class Null { @patch class Function { @patch - static apply(Function function, List? positionalArguments, - [Map? namedArguments]) { + static apply( + Function function, + List? positionalArguments, [ + Map? namedArguments, + ]) { return Primitives.applyFunction( - function, - positionalArguments, - // Use this form so that if namedArguments is always null, we can - // tree-shake _symbolMapToStringMap. - namedArguments == null ? null : _symbolMapToStringMap(namedArguments)); + function, + positionalArguments, + // Use this form so that if namedArguments is always null, we can + // tree-shake _symbolMapToStringMap. + namedArguments == null ? null : _symbolMapToStringMap(namedArguments), + ); } } @@ -132,8 +136,11 @@ class Expando { } static Never _badExpandoKey(object) { - throw ArgumentError.value(object, 'object', - "Expandos are not allowed on strings, numbers, bools, records or null"); + throw ArgumentError.value( + object, + 'object', + "Expandos are not allowed on strings, numbers, bools, records or null", + ); } } @@ -151,7 +158,7 @@ class _WeakReferenceWrapper implements WeakReference { final Object _weakRef; _WeakReferenceWrapper(T object) - : _weakRef = JS('', 'new #(#)', _weakRefConstructor, object); + : _weakRef = JS('', 'new #(#)', _weakRefConstructor, object); T? get target => JS('', '#.deref()', _weakRef); @@ -196,10 +203,15 @@ class _FinalizationRegistryWrapper implements Finalizer { final Object? _registry; _FinalizationRegistryWrapper(void Function(T) callback) - : _registry = _finalizationRegistryConstructor == null - ? null - : JS('', 'new #(#)', _finalizationRegistryConstructor, - convertDartClosureToJS(wrapZoneUnaryCallback(callback), 1)); + : _registry = + _finalizationRegistryConstructor == null + ? null + : JS( + '', + 'new #(#)', + _finalizationRegistryConstructor, + convertDartClosureToJS(wrapZoneUnaryCallback(callback), 1), + ); void attach(Object value, T token, {Object? detach}) { if (_registry != null) { @@ -226,8 +238,11 @@ class _FinalizationRegistryWrapper implements Finalizer { @patch class int { @patch - static int parse(String source, - {int? radix, @deprecated int onError(String source)?}) { + static int parse( + String source, { + int? radix, + @deprecated int onError(String source)?, + }) { int? value = tryParse(source, radix: radix); if (value != null) return value; if (onError != null) return onError(source); @@ -243,8 +258,10 @@ class int { @patch class double { @patch - static double parse(String source, - [@deprecated double onError(String source)?]) { + static double parse( + String source, [ + @deprecated double onError(String source)?, + ]) { double? value = tryParse(source); if (value != null) return value; if (onError != null) return onError(source); @@ -356,7 +373,8 @@ class List { factory List._ofArray(Iterable elements) { return JSArray.markGrowable( - JS('effects:none;depends:no-static', '#.slice(0)', elements)); + JS('effects:none;depends:no-static', '#.slice(0)', elements), + ); } factory List._of(Iterable elements) { @@ -375,8 +393,11 @@ class List { } @patch - factory List.generate(int length, E generator(int index), - {bool growable = true}) { + factory List.generate( + int length, + E generator(int index), { + bool growable = true, + }) { final result = growable ? JSArray.growable(length) : JSArray.fixed(length); for (int i = 0; i < length; i++) { @@ -404,8 +425,11 @@ class Map { @patch class String { @patch - factory String.fromCharCodes(Iterable charCodes, - [int start = 0, int? end]) { + factory String.fromCharCodes( + Iterable charCodes, [ + int start = 0, + int? end, + ]) { RangeError.checkNotNegative(start, "start"); if (end != null) { var maxLength = end - start; @@ -449,7 +473,10 @@ class String { } static String _stringFromUint8List( - NativeUint8List charCodes, int start, int? endOrNull) { + NativeUint8List charCodes, + int start, + int? endOrNull, + ) { int len = charCodes.length; if (start >= len) return ""; int end = (endOrNull == null || endOrNull > len) ? len : endOrNull; @@ -457,7 +484,10 @@ class String { } static String _stringFromIterable( - Iterable charCodes, int start, int? end) { + Iterable charCodes, + int start, + int? end, + ) { if (end != null) charCodes = charCodes.take(end); if (start > 0) charCodes = charCodes.skip(start); return Primitives.stringFromCharCodes(List.of(charCodes)); @@ -484,16 +514,19 @@ class bool { class RegExp { @pragma('dart2js:noInline') @patch - factory RegExp(String source, - {bool multiLine = false, - bool caseSensitive = true, - bool unicode = false, - bool dotAll = false}) => - JSSyntaxRegExp(source, - multiLine: multiLine, - caseSensitive: caseSensitive, - unicode: unicode, - dotAll: dotAll); + factory RegExp( + String source, { + bool multiLine = false, + bool caseSensitive = true, + bool unicode = false, + bool dotAll = false, + }) => JSSyntaxRegExp( + source, + multiLine: multiLine, + caseSensitive: caseSensitive, + unicode: unicode, + dotAll: dotAll, + ); @patch static String escape(String text) => quoteStringForRegExp(text); @@ -501,7 +534,8 @@ class RegExp { // Patch for 'identical' function. @pragma( - 'dart2js:noInline') // No inlining since we recognize the call in optimizer. + 'dart2js:noInline', +) // No inlining since we recognize the call in optimizer. @patch bool identical(Object? a, Object? b) { return JS('bool', '(# == null ? # == null : # === #)', a, b, a, b); @@ -581,24 +615,40 @@ class NoSuchMethodError { @patch factory NoSuchMethodError.withInvocation( - Object? receiver, Invocation invocation) => - NoSuchMethodError._(receiver, invocation.memberName, - invocation.positionalArguments, invocation.namedArguments); + Object? receiver, + Invocation invocation, + ) => NoSuchMethodError._( + receiver, + invocation.memberName, + invocation.positionalArguments, + invocation.namedArguments, + ); - NoSuchMethodError(Object? receiver, Symbol memberName, - List? positionalArguments, Map? namedArguments, - [List? existingArgumentNames = null]) - : this._(receiver, memberName, positionalArguments, namedArguments, - existingArgumentNames); + NoSuchMethodError( + Object? receiver, + Symbol memberName, + List? positionalArguments, + Map? namedArguments, [ + List? existingArgumentNames = null, + ]) : this._( + receiver, + memberName, + positionalArguments, + namedArguments, + existingArgumentNames, + ); - NoSuchMethodError._(Object? receiver, Symbol memberName, - List? positionalArguments, Map? namedArguments, - [List? existingArgumentNames = null]) - : _receiver = receiver, - _memberName = memberName, - _arguments = positionalArguments, - _namedArguments = namedArguments, - _existingArgumentNames = existingArgumentNames; + NoSuchMethodError._( + Object? receiver, + Symbol memberName, + List? positionalArguments, + Map? namedArguments, [ + List? existingArgumentNames = null, + ]) : _receiver = receiver, + _memberName = memberName, + _arguments = positionalArguments, + _namedArguments = namedArguments, + _existingArgumentNames = existingArgumentNames; @patch String toString() { @@ -676,12 +726,12 @@ class _Uri { // compiled with `--server-mode` and running on Node or a similar platform. static final bool _isWindowsCached = !const bool.fromEnvironment('dart.library.html') && - JS( - 'bool', - 'typeof process != "undefined" && ' - 'Object.prototype.toString.call(process) == "[object process]" && ' - 'process.platform == "win32"', - ); + JS( + 'bool', + 'typeof process != "undefined" && ' + 'Object.prototype.toString.call(process) == "[object process]" && ' + 'process.platform == "win32"', + ); // Matches a String that _uriEncodes to itself regardless of the kind of // component. This corresponds to [_unreservedTable], i.e. characters that @@ -693,7 +743,11 @@ class _Uri { /// that appear in [canonicalTable], and returns the escaped string. @patch static String _uriEncode( - int canonicalMask, String text, Encoding encoding, bool spaceToPlus) { + int canonicalMask, + String text, + Encoding encoding, + bool spaceToPlus, + ) { if (identical(encoding, utf8) && _needsNoEncoding.hasMatch(text)) { return text; } @@ -720,7 +774,8 @@ class _Uri { @patch static String _makeQueryFromParameters( - Map*/ > queryParameters) { + Map*/> queryParameters, + ) { if (!_useURLSearchParams) { return _makeQueryFromParametersDefault(queryParameters); } @@ -769,15 +824,18 @@ class _Uri { // Handle other cases with one RegExp. encoded = JS( - '', - r'#.replace(/=&|\*|%7E/g, (m) => m === "=&" ? "&" : m === "*" ? "%2A" : "~")', - encoded); + '', + r'#.replace(/=&|\*|%7E/g, (m) => m === "=&" ? "&" : m === "*" ? "%2A" : "~")', + encoded, + ); return encoded; } - static final bool _useURLSearchParams = - JS('bool', 'typeof URLSearchParams == "function"'); + static final bool _useURLSearchParams = JS( + 'bool', + 'typeof URLSearchParams == "function"', + ); } @patch @@ -805,8 +863,9 @@ class _DuplicatedFieldInitializerError extends Error { /// The signature is hardwired to the kernel nodes generated in the /// `Dart2jsTarget` and read in the `KernelSsaGraphBuilder`. external Invocation _createInvocationMirror( - String memberName, - List typeArguments, - List positionalArguments, - Map namedArguments, - int kind); + String memberName, + List typeArguments, + List positionalArguments, + Map namedArguments, + int kind, +); diff --git a/sdk/lib/_internal/js_runtime/lib/developer_patch.dart b/sdk/lib/_internal/js_runtime/lib/developer_patch.dart index 11c6e2cd22f..f9de36bd582 100644 --- a/sdk/lib/_internal/js_runtime/lib/developer_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/developer_patch.dart @@ -42,7 +42,10 @@ extension type _JSPerformance(JSObject performance) { external JSAny? get _clearMarksMethod; external void measure( - JSString measureName, JSString startMark, JSString endMark); + JSString measureName, + JSString startMark, + JSString endMark, + ); external void mark(JSString markName, JSObject markOptions); @@ -55,27 +58,29 @@ extension type _JSJSON(JSObject performance) { external JSObject parse(JSString string); } -_JSPerformance? _performance = (() { - final value = _jsPerformance; - if (value.isA()) { - final performance = _JSPerformance(value as JSObject); - if (performance._measureMethod != null && - performance._markMethod != null && - performance._clearMeasuresMethod != null && - performance._clearMarksMethod != null) { - return performance; - } - } - return null; -})(); +_JSPerformance? _performance = + (() { + final value = _jsPerformance; + if (value.isA()) { + final performance = _JSPerformance(value as JSObject); + if (performance._measureMethod != null && + performance._markMethod != null && + performance._clearMeasuresMethod != null && + performance._clearMarksMethod != null) { + return performance; + } + } + return null; + })(); -_JSJSON _json = (() { - final value = _jsJSON; - if (value.isA()) { - return value as _JSJSON; - } - throw UnsupportedError('Missing JSON.parse() support'); -})(); +_JSJSON _json = + (() { + final value = _jsJSON; + if (value.isA()) { + return value as _JSJSON; + } + throw UnsupportedError('Missing JSON.parse() support'); + })(); @patch @pragma('dart2js:tryInline') @@ -90,14 +95,16 @@ Object? inspect(Object? object) { } @patch -void log(String message, - {DateTime? time, - int? sequenceNumber, - int level = 0, - String name = '', - Zone? zone, - Object? error, - StackTrace? stackTrace}) { +void log( + String message, { + DateTime? time, + int? sequenceNumber, + int level = 0, + String name = '', + Zone? zone, + Object? error, + StackTrace? stackTrace, +}) { // TODO. } @@ -202,7 +209,12 @@ bool get _areAllBeginEventsPaired => _eventNameToCount.isEmpty; @patch void _reportTaskEvent( - int taskId, int flowId, int type, String name, String argumentsAsJson) { + int taskId, + int flowId, + int type, + String name, + String argumentsAsJson, +) { // Ignore any unsupported events. if (_isUnsupportedEvent(type)) return; @@ -248,9 +260,16 @@ void _reportTaskEvent( // event with the same name. if (isEndEvent) { final beginEventName = _createEventName( - taskId: taskId, name: name, isBeginEvent: true, isEndEvent: false); - _performance!.measure(name.toJS, _postfixWithCount(beginEventName).toJS, - currentEventName.toJS); + taskId: taskId, + name: name, + isBeginEvent: true, + isEndEvent: false, + ); + _performance!.measure( + name.toJS, + _postfixWithCount(beginEventName).toJS, + currentEventName.toJS, + ); _markAndMeasureEntryCount++; _decrementEventCount(beginEventName); } @@ -310,7 +329,8 @@ final class _FakeUserTag implements UserTag { // Throw an exception if we've reached the maximum number of user tags. if (_instances.length == UserTag.maxUserTags) { throw UnsupportedError( - 'UserTag instance limit (${UserTag.maxUserTags}) reached.'); + 'UserTag instance limit (${UserTag.maxUserTags}) reached.', + ); } return _instances[label] = _FakeUserTag.real(label); } @@ -339,5 +359,6 @@ abstract final class NativeRuntime { @patch static void writeHeapSnapshotToFile(String filepath) => throw UnsupportedError( - "Generating heap snapshots is not supported on the web."); + "Generating heap snapshots is not supported on the web.", + ); } diff --git a/sdk/lib/_internal/js_runtime/lib/io_patch.dart b/sdk/lib/_internal/js_runtime/lib/io_patch.dart index 4aa3c09719c..92b57375df4 100644 --- a/sdk/lib/_internal/js_runtime/lib/io_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/io_patch.dart @@ -52,11 +52,12 @@ class _Directory { @patch static void _fillWithDirectoryListing( - _Namespace namespace, - List list, - Uint8List path, - bool recursive, - bool followLinks) { + _Namespace namespace, + List list, + Uint8List path, + bool recursive, + bool followLinks, + ) { throw UnsupportedError("Directory._fillWithDirectoryListing"); } } @@ -89,7 +90,10 @@ class FileStat { class FileSystemEntity { @patch static _getTypeNative( - _Namespace namespace, Uint8List path, bool followLinks) { + _Namespace namespace, + Uint8List path, + bool followLinks, + ) { throw UnsupportedError("FileSystemEntity._getType"); } @@ -343,34 +347,43 @@ class ProcessInfo { @patch class Process { @patch - static Future start(String executable, List arguments, - {String? workingDirectory, - Map? environment, - bool includeParentEnvironment = true, - bool runInShell = false, - ProcessStartMode mode = ProcessStartMode.normal}) { + static Future start( + String executable, + List arguments, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + ProcessStartMode mode = ProcessStartMode.normal, + }) { throw UnsupportedError("Process.start"); } @patch - static Future run(String executable, List arguments, - {String? workingDirectory, - Map? environment, - bool includeParentEnvironment = true, - bool runInShell = false, - Encoding? stdoutEncoding = systemEncoding, - Encoding? stderrEncoding = systemEncoding}) { + static Future run( + String executable, + List arguments, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + Encoding? stdoutEncoding = systemEncoding, + Encoding? stderrEncoding = systemEncoding, + }) { throw UnsupportedError("Process.run"); } @patch - static ProcessResult runSync(String executable, List arguments, - {String? workingDirectory, - Map? environment, - bool includeParentEnvironment = true, - bool runInShell = false, - Encoding? stdoutEncoding = systemEncoding, - Encoding? stderrEncoding = systemEncoding}) { + static ProcessResult runSync( + String executable, + List arguments, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + Encoding? stdoutEncoding = systemEncoding, + Encoding? stderrEncoding = systemEncoding, + }) { throw UnsupportedError("Process.runSync"); } @@ -408,20 +421,26 @@ class InternetAddress { } @patch - factory InternetAddress.fromRawAddress(Uint8List rawAddress, - {InternetAddressType? type}) { + factory InternetAddress.fromRawAddress( + Uint8List rawAddress, { + InternetAddressType? type, + }) { throw UnsupportedError("InternetAddress.fromRawAddress"); } @patch - static Future> lookup(String host, - {InternetAddressType type = InternetAddressType.any}) { + static Future> lookup( + String host, { + InternetAddressType type = InternetAddressType.any, + }) { throw UnsupportedError("InternetAddress.lookup"); } @patch static InternetAddress _cloneWithNewHost( - InternetAddress address, String host) { + InternetAddress address, + String host, + ) { throw UnsupportedError("InternetAddress._cloneWithNewHost"); } @@ -439,10 +458,11 @@ class NetworkInterface { } @patch - static Future> list( - {bool includeLoopback = false, - bool includeLinkLocal = false, - InternetAddressType type = InternetAddressType.any}) { + static Future> list({ + bool includeLoopback = false, + bool includeLinkLocal = false, + InternetAddressType type = InternetAddressType.any, + }) { throw UnsupportedError("NetworkInterface.list"); } } @@ -450,8 +470,13 @@ class NetworkInterface { @patch class RawServerSocket { @patch - static Future bind(address, int port, - {int backlog = 0, bool v6Only = false, bool shared = false}) { + static Future bind( + address, + int port, { + int backlog = 0, + bool v6Only = false, + bool shared = false, + }) { throw UnsupportedError("RawServerSocket.bind"); } } @@ -459,8 +484,13 @@ class RawServerSocket { @patch class ServerSocket { @patch - static Future _bind(address, int port, - {int backlog = 0, bool v6Only = false, bool shared = false}) { + static Future _bind( + address, + int port, { + int backlog = 0, + bool v6Only = false, + bool shared = false, + }) { throw UnsupportedError("ServerSocket.bind"); } } @@ -468,14 +498,23 @@ class ServerSocket { @patch class RawSocket { @patch - static Future connect(dynamic host, int port, - {dynamic sourceAddress, int sourcePort = 0, Duration? timeout}) { + static Future connect( + dynamic host, + int port, { + dynamic sourceAddress, + int sourcePort = 0, + Duration? timeout, + }) { throw UnsupportedError("RawSocket constructor"); } @patch - static Future> startConnect(dynamic host, int port, - {dynamic sourceAddress, int sourcePort = 0}) { + static Future> startConnect( + dynamic host, + int port, { + dynamic sourceAddress, + int sourcePort = 0, + }) { throw UnsupportedError("RawSocket constructor"); } } @@ -483,14 +522,23 @@ class RawSocket { @patch class Socket { @patch - static Future _connect(dynamic host, int port, - {dynamic sourceAddress, int sourcePort = 0, Duration? timeout}) { + static Future _connect( + dynamic host, + int port, { + dynamic sourceAddress, + int sourcePort = 0, + Duration? timeout, + }) { throw UnsupportedError("Socket constructor"); } @patch - static Future> _startConnect(dynamic host, int port, - {dynamic sourceAddress, int sourcePort = 0}) { + static Future> _startConnect( + dynamic host, + int port, { + dynamic sourceAddress, + int sourcePort = 0, + }) { throw UnsupportedError("Socket constructor"); } } @@ -522,7 +570,8 @@ class ResourceHandle { @patch factory ResourceHandle.fromRawDatagramSocket( - RawDatagramSocket rawDatagramSocket) { + RawDatagramSocket rawDatagramSocket, + ) { throw UnsupportedError("ResourceHandle.fromRawDatagramSocket constructor"); } @@ -600,8 +649,13 @@ class X509Certificate { @patch class RawDatagramSocket { @patch - static Future bind(dynamic host, int port, - {bool reuseAddress = true, bool reusePort = false, int ttl = 1}) { + static Future bind( + dynamic host, + int port, { + bool reuseAddress = true, + bool reusePort = false, + int ttl = 1, + }) { throw UnsupportedError("RawDatagramSocket.bind"); } } @@ -657,19 +711,24 @@ class _WindowsCodePageEncoder { class RawZLibFilter { @patch static RawZLibFilter _makeZLibDeflateFilter( - bool gzip, - int level, - int windowBits, - int memLevel, - int strategy, - List? dictionary, - bool raw) { + bool gzip, + int level, + int windowBits, + int memLevel, + int strategy, + List? dictionary, + bool raw, + ) { throw UnsupportedError("_newZLibDeflateFilter"); } @patch static RawZLibFilter _makeZLibInflateFilter( - bool gzip, int windowBits, List? dictionary, bool raw) { + bool gzip, + int windowBits, + List? dictionary, + bool raw, + ) { throw UnsupportedError("_newZLibInflateFilter"); } } @@ -744,7 +803,10 @@ class Stdout { class _FileSystemWatcher { @patch static Stream _watch( - String path, int events, bool recursive) { + String path, + int events, + bool recursive, + ) { throw UnsupportedError("_FileSystemWatcher.watch"); } diff --git a/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart b/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart index dde986aecad..2ac0732d045 100644 --- a/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart @@ -42,27 +42,34 @@ class Isolate { } @patch - static Future spawn(void entryPoint(T message), T message, - {bool paused = false, - bool errorsAreFatal = true, - SendPort? onExit, - SendPort? onError, - String? debugName}) { + static Future spawn( + void entryPoint(T message), + T message, { + bool paused = false, + bool errorsAreFatal = true, + SendPort? onExit, + SendPort? onError, + String? debugName, + }) { throw UnsupportedError("Isolate.spawn"); } @patch - static Future spawnUri(Uri uri, List args, var message, - {bool paused = false, - SendPort? onExit, - SendPort? onError, - bool errorsAreFatal = true, - bool? checked, - Map? environment, - Uri? packageRoot, - Uri? packageConfig, - bool automaticPackageResolution = false, - String? debugName}) { + static Future spawnUri( + Uri uri, + List args, + var message, { + bool paused = false, + SendPort? onExit, + SendPort? onError, + bool errorsAreFatal = true, + bool? checked, + Map? environment, + Uri? packageRoot, + Uri? packageConfig, + bool automaticPackageResolution = false, + String? debugName, + }) { throw UnsupportedError("Isolate.spawnUri"); } @@ -97,8 +104,11 @@ class Isolate { } @patch - void ping(SendPort responsePort, - {Object? response, int priority = immediate}) { + void ping( + SendPort responsePort, { + Object? response, + int priority = immediate, + }) { throw UnsupportedError("Isolate.ping"); } @@ -132,10 +142,12 @@ class ReceivePort { class _ReceivePortImpl extends Stream implements ReceivePort { _ReceivePortImpl([String debugName = '']); - StreamSubscription listen(void Function(dynamic)? onData, - {Function? onError, - void Function()? onDone, - bool? cancelOnError = true}) { + StreamSubscription listen( + void Function(dynamic)? onData, { + Function? onError, + void Function()? onDone, + bool? cancelOnError = true, + }) { throw UnsupportedError("ReceivePort.listen"); } diff --git a/sdk/lib/_internal/js_runtime/lib/js_allow_interop_patch.dart b/sdk/lib/_internal/js_runtime/lib/js_allow_interop_patch.dart index c5d77eb99d9..c8abc126bcf 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_allow_interop_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_allow_interop_patch.dart @@ -17,16 +17,17 @@ _convertDartFunctionFast(Function f) { var existing = JS('', '#.#', f, JS_FUNCTION_PROPERTY_NAME); if (existing != null) return existing; var ret = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function() { return _call(f, Array.prototype.slice.apply(arguments)); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast), + f, + ); JS('', '#.# = #', ret, DART_CLOSURE_PROPERTY_NAME, f); JS('', '#.# = #', f, JS_FUNCTION_PROPERTY_NAME, ret); return ret; @@ -36,16 +37,17 @@ _convertDartFunctionFastCaptureThis(Function f) { var existing = JS('', '#.#', f, JS_FUNCTION_PROPERTY_NAME_CAPTURE_THIS); if (existing != null) return existing; var ret = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function() { return _call(f, this,Array.prototype.slice.apply(arguments)); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFastCaptureThis), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFastCaptureThis), + f, + ); JS('', '#.# = #', ret, DART_CLOSURE_PROPERTY_NAME, f); JS('', '#.# = #', f, JS_FUNCTION_PROPERTY_NAME_CAPTURE_THIS, ret); return ret; @@ -74,7 +76,8 @@ Function allowInteropCaptureThis(Function f) { if (isJSFunction(f)) { // Behavior when the function is already a JS function is unspecified. throw ArgumentError( - "Function is already a JS function so cannot capture this."); + "Function is already a JS function so cannot capture this.", + ); return f; } else { return _convertDartFunctionFastCaptureThis(f); @@ -89,16 +92,17 @@ JavaScriptFunction _functionToJS0(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function() { return _call(f); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast0), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast0), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -108,16 +112,17 @@ JavaScriptFunction _functionToJSCaptureThis0(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function() { return _call(f, this, 1); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast1), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast1), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -127,16 +132,17 @@ JavaScriptFunction _functionToJS1(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1) { return _call(f, arg1, arguments.length); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast1), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast1), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -146,16 +152,17 @@ JavaScriptFunction _functionToJSCaptureThis1(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1) { return _call(f, this, arg1, arguments.length + 1); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast2), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast2), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -165,16 +172,17 @@ JavaScriptFunction _functionToJS2(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2) { return _call(f, arg1, arg2, arguments.length); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast2), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast2), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -184,16 +192,17 @@ JavaScriptFunction _functionToJSCaptureThis2(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2) { return _call(f, this, arg1, arg2, arguments.length + 1); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast3), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast3), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -203,16 +212,17 @@ JavaScriptFunction _functionToJS3(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2, arg3) { return _call(f, arg1, arg2, arg3, arguments.length); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast3), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast3), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -222,16 +232,17 @@ JavaScriptFunction _functionToJSCaptureThis3(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2, arg3) { return _call(f, this, arg1, arg2, arg3, arguments.length + 1); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast4), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast4), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -241,16 +252,17 @@ JavaScriptFunction _functionToJS4(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2, arg3, arg4) { return _call(f, arg1, arg2, arg3, arg4, arguments.length); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast4), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast4), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -260,16 +272,17 @@ JavaScriptFunction _functionToJSCaptureThis4(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2, arg3, arg4) { return _call(f, this, arg1, arg2, arg3, arg4, arguments.length + 1); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast5), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast5), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -279,16 +292,17 @@ JavaScriptFunction _functionToJS5(Function f) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f) { return function(arg1, arg2, arg3, arg4, arg5) { return _call(f, arg1, arg2, arg3, arg4, arg5, arguments.length); } }(#, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFast5), - f); + DART_CLOSURE_TO_JS(_callDartFunctionFast5), + f, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -298,8 +312,8 @@ JavaScriptFunction _functionToJSN(Function f, int maxLength) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f, maxLength) { return function() { return _call(f, Array.prototype.slice.call(arguments, 0, @@ -307,9 +321,10 @@ JavaScriptFunction _functionToJSN(Function f, int maxLength) { } }(#, #, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFastN), - f, - maxLength); + DART_CLOSURE_TO_JS(_callDartFunctionFastN), + f, + maxLength, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -323,8 +338,8 @@ JavaScriptFunction _functionToJSCaptureThisN(Function f, int maxLength) { throw ArgumentError('Attempting to rewrap a JS function.'); } final result = JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f, maxLength) { return function() { var args = [this]; @@ -334,9 +349,10 @@ JavaScriptFunction _functionToJSCaptureThisN(Function f, int maxLength) { } }(#, #, #) ''', - DART_CLOSURE_TO_JS(_callDartFunctionFastN), - f, - maxLength); + DART_CLOSURE_TO_JS(_callDartFunctionFastN), + f, + maxLength, + ); JS('', '#.# = #', result, DART_CLOSURE_PROPERTY_NAME, f); return result; } @@ -370,7 +386,14 @@ _callDartFunctionFast4(Function callback, arg1, arg2, arg3, arg4, int length) { } _callDartFunctionFast5( - Function callback, arg1, arg2, arg3, arg4, arg5, int length) { + Function callback, + arg1, + arg2, + arg3, + arg4, + arg5, + int length, +) { if (length >= 5) return callback(arg1, arg2, arg3, arg4, arg5); if (length == 4) return callback(arg1, arg2, arg3, arg4); if (length == 3) return callback(arg1, arg2, arg3); diff --git a/sdk/lib/_internal/js_runtime/lib/js_number.dart b/sdk/lib/_internal/js_runtime/lib/js_number.dart index fae9b512c93..db653c0ff95 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_number.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_number.dart @@ -57,18 +57,20 @@ final class JSNumber extends Interceptor implements double { bool get isNegative => (this == 0) ? (1 / this) < 0 : this < 0; bool get isNaN => JS( - 'returns:bool;effects:none;depends:none;throws:never;gvn:true', - r'isNaN(#)', - this); + 'returns:bool;effects:none;depends:none;throws:never;gvn:true', + r'isNaN(#)', + this, + ); bool get isInfinite { return JS('bool', r'# == (1/0)', this) || JS('bool', r'# == (-1/0)', this); } bool get isFinite => JS( - 'returns:bool;effects:none;depends:none;throws:never;gvn:true', - r'isFinite(#)', - this); + 'returns:bool;effects:none;depends:none;throws:never;gvn:true', + r'isFinite(#)', + this, + ); JSNumber remainder(num b) { if (b is! num) throw argumentErrorValue(b); @@ -78,15 +80,18 @@ final class JSNumber extends Interceptor implements double { // Use invoke_dynamic_specializer instead of inlining. @pragma('dart2js:noInline') JSNumber abs() => JS( - 'returns:num;effects:none;depends:none;throws:never;gvn:true', - r'Math.abs(#)', - this); + 'returns:num;effects:none;depends:none;throws:never;gvn:true', + r'Math.abs(#)', + this, + ); - JSNumber get sign => (this > 0 - ? 1 - : this < 0 - ? -1 - : this) as JSNumber; + JSNumber get sign => + (this > 0 + ? 1 + : this < 0 + ? -1 + : this) + as JSNumber; static const int _MIN_INT32 = -0x80000000; static const int _MAX_INT32 = 0x7FFFFFFF; @@ -242,8 +247,11 @@ final class JSNumber extends Interceptor implements double { static String _handleIEtoString(String result) { // Result is probably IE's untraditional format for large numbers, // e.g., "8.0000000000008(e+15)" for 0x8000000000000800.toString(16). - List? match = JS('JSArray|Null', - r'/^([\da-z]+)(?:\.([\da-z]+))?\(e\+(\d+)\)$/.exec(#)', result); + List? match = JS( + 'JSArray|Null', + r'/^([\da-z]+)(?:\.([\da-z]+))?\(e\+(\d+)\)$/.exec(#)', + result, + ); if (match == null) { // Then we don't know how to handle it at all. throw UnsupportedError('Unexpected toString result: $result'); @@ -375,7 +383,8 @@ final class JSNumber extends Interceptor implements double { // [quotient] is either NaN, Infinity or -Infinity. throw UnsupportedError( - 'Result of truncating division is $quotient: $this ~/ $other'); + 'Result of truncating division is $quotient: $this ~/ $other', + ); } // TODO(ngeoffray): Move the bit operations below to [JSInt] and @@ -494,16 +503,19 @@ final class JSInt extends JSNumber implements int, TrustedGetRuntimeType { // Use invoke_dynamic_specializer instead of inlining. @pragma('dart2js:noInline') JSInt abs() => JS( - 'returns:int;effects:none;depends:none;throws:never;gvn:true', - r'Math.abs(#)', - this); + 'returns:int;effects:none;depends:none;throws:never;gvn:true', + r'Math.abs(#)', + this, + ); @override - JSInt get sign => (this > 0 - ? 1 - : this < 0 - ? -1 - : this) as JSInt; + JSInt get sign => + (this > 0 + ? 1 + : this < 0 + ? -1 + : this) + as JSInt; @override JSInt operator -() => JS('int', r'-#', this); @@ -553,7 +565,11 @@ final class JSInt extends JSNumber implements int, TrustedGetRuntimeType { // represented precisely as a Number (double). if (this < -maxPreciseInteger || this > maxPreciseInteger) { throw RangeError.range( - this, -maxPreciseInteger, maxPreciseInteger, 'receiver'); + this, + -maxPreciseInteger, + maxPreciseInteger, + 'receiver', + ); } if (e > maxPreciseInteger) { throw RangeError.range(e, 0, maxPreciseInteger, 'exponent'); diff --git a/sdk/lib/_internal/js_runtime/lib/js_patch.dart b/sdk/lib/_internal/js_runtime/lib/js_patch.dart index 221a721b96b..a8d3ee6a5ab 100644 --- a/sdk/lib/_internal/js_runtime/lib/js_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/js_patch.dart @@ -24,8 +24,8 @@ final JsObject _context = _castToJsObject(_wrapToDart(JS('', 'self'))); _convertDartFunction(Function f, {bool captureThis = false}) { return JS( - 'JavaScriptFunction', - ''' + 'JavaScriptFunction', + ''' function(_call, f, captureThis) { return function() { return _call(f, captureThis, this, @@ -33,9 +33,10 @@ _convertDartFunction(Function f, {bool captureThis = false}) { } }(#, #, #) ''', - DART_CLOSURE_TO_JS(_callDartFunction), - f, - captureThis); + DART_CLOSURE_TO_JS(_callDartFunction), + f, + captureThis, + ); } _callDartFunction(callback, bool captureThis, self, List arguments) { @@ -77,22 +78,27 @@ class JsObject { var arg0 = _convertToJS(JS('', '#[0]', arguments)); var arg1 = _convertToJS(JS('', '#[1]', arguments)); return _castToJsObject( - _wrapToDart(JS('', 'new #(#, #)', ctor, arg0, arg1))); + _wrapToDart(JS('', 'new #(#, #)', ctor, arg0, arg1)), + ); case 3: var arg0 = _convertToJS(JS('', '#[0]', arguments)); var arg1 = _convertToJS(JS('', '#[1]', arguments)); var arg2 = _convertToJS(JS('', '#[2]', arguments)); return _castToJsObject( - _wrapToDart(JS('', 'new #(#, #, #)', ctor, arg0, arg1, arg2))); + _wrapToDart(JS('', 'new #(#, #, #)', ctor, arg0, arg1, arg2)), + ); case 4: var arg0 = _convertToJS(JS('', '#[0]', arguments)); var arg1 = _convertToJS(JS('', '#[1]', arguments)); var arg2 = _convertToJS(JS('', '#[2]', arguments)); var arg3 = _convertToJS(JS('', '#[3]', arguments)); - return _castToJsObject(_wrapToDart( - JS('', 'new #(#, #, #, #)', ctor, arg0, arg1, arg2, arg3))); + return _castToJsObject( + _wrapToDart( + JS('', 'new #(#, #, #, #)', ctor, arg0, arg1, arg2, arg3), + ), + ); } } @@ -219,8 +225,16 @@ class JsObject { if (method is! String && method is! num) { throw ArgumentError("method is not a String or num"); } - return _convertToDart(JS('', '#[#].apply(#, #)', _jsObject, method, - _jsObject, args == null ? null : List.from(args.map(_convertToJS)))); + return _convertToDart( + JS( + '', + '#[#].apply(#, #)', + _jsObject, + method, + _jsObject, + args == null ? null : List.from(args.map(_convertToJS)), + ), + ); } } @@ -235,12 +249,15 @@ class JsFunction extends JsObject { JsFunction._fromJs(Object jsObject) : super._fromJs(jsObject); @patch - dynamic apply(List args, {thisArg}) => _convertToDart(JS( + dynamic apply(List args, {thisArg}) => _convertToDart( + JS( '', '#.apply(#, #)', _jsObject, _convertToJS(thisArg), - args == null ? null : List.from(args.map(_convertToJS)))); + args == null ? null : List.from(args.map(_convertToJS)), + ), + ); } @patch @@ -319,9 +336,10 @@ class JsArray /*extends JsObject with ListMixin*/ { @patch void addAll(Iterable iterable) { - var list = (JS('bool', '# instanceof Array', iterable)) - ? JS('JSArray', '#', iterable) - : List.from(iterable); + var list = + (JS('bool', '# instanceof Array', iterable)) + ? JS('JSArray', '#', iterable) + : List.from(iterable); callMethod('push', list); } @@ -371,8 +389,9 @@ class JsArray /*extends JsObject with ListMixin*/ { } // property added to a Dart object referencing its JS-side DartObject proxy -final String _DART_OBJECT_PROPERTY_NAME = - getIsolateAffinityTag(r'_$dart_dartObject'); +final String _DART_OBJECT_PROPERTY_NAME = getIsolateAffinityTag( + r'_$dart_dartObject', +); // property added to a JS object referencing its Dart-side JsObject proxy const _JS_OBJECT_PROPERTY_NAME = r'_$dart_jsObject'; @@ -444,7 +463,10 @@ Object? _convertToJS(Object? o) { } var ctor = _dartProxyCtor; return _getJsProxy( - o, _JS_OBJECT_PROPERTY_NAME, (o) => JS('', 'new #(#)', ctor, o)); + o, + _JS_OBJECT_PROPERTY_NAME, + (o) => JS('', 'new #(#)', ctor, o), + ); } Object? _getJsProxy(o, String propertyName, createProxy(o)) { @@ -481,14 +503,23 @@ Object? _convertToDart(o) { Object _wrapToDart(o) { if (JS('bool', 'typeof # == "function"', o)) { return _getDartProxy( - o, DART_CLOSURE_PROPERTY_NAME, (o) => JsFunction._fromJs(o)); + o, + DART_CLOSURE_PROPERTY_NAME, + (o) => JsFunction._fromJs(o), + ); } if (JS('bool', '# instanceof Array', o)) { return _getDartProxy( - o, _DART_OBJECT_PROPERTY_NAME, (o) => JsArray._fromJs(o)); + o, + _DART_OBJECT_PROPERTY_NAME, + (o) => JsArray._fromJs(o), + ); } return _getDartProxy( - o, _DART_OBJECT_PROPERTY_NAME, (o) => JsObject._fromJs(o)); + o, + _DART_OBJECT_PROPERTY_NAME, + (o) => JsObject._fromJs(o), + ); } Object _getDartProxy(o, String propertyName, JsObject createProxy(o)) { diff --git a/sdk/lib/_internal/js_runtime/lib/linked_hash_map.dart b/sdk/lib/_internal/js_runtime/lib/linked_hash_map.dart index bfd6ec63b86..4017cc732f2 100644 --- a/sdk/lib/_internal/js_runtime/lib/linked_hash_map.dart +++ b/sdk/lib/_internal/js_runtime/lib/linked_hash_map.dart @@ -373,7 +373,7 @@ class LinkedHashMapKeyIterator implements Iterator { E? _current; LinkedHashMapKeyIterator(this._map, this._modifications) - : _cell = _map._first; + : _cell = _map._first; @pragma('dart2js:as:trust') E get current => _current as E; @@ -426,7 +426,7 @@ class LinkedHashMapValueIterator implements Iterator { E? _current; LinkedHashMapValueIterator(this._map, this._modifications) - : _cell = _map._first; + : _cell = _map._first; @pragma('dart2js:as:trust') E get current => _current as E; @@ -468,7 +468,7 @@ class LinkedHashMapEntryIterator implements Iterator> { MapEntry? _current; LinkedHashMapEntryIterator(this._map, this._modifications) - : _cell = _map._first; + : _cell = _map._first; MapEntry get current => _current!; diff --git a/sdk/lib/_internal/js_runtime/lib/math_patch.dart b/sdk/lib/_internal/js_runtime/lib/math_patch.dart index d8a3575aade..6e93771cf7a 100644 --- a/sdk/lib/_internal/js_runtime/lib/math_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/math_patch.dart @@ -10,17 +10,19 @@ import 'dart:typed_data' show ByteData; @patch T min(T a, T b) => JS( - 'returns:num;depends:none;effects:none;gvn:true', - r'Math.min(#, #)', - checkNum(a), - checkNum(b)); + 'returns:num;depends:none;effects:none;gvn:true', + r'Math.min(#, #)', + checkNum(a), + checkNum(b), +); @patch T max(T a, T b) => JS( - 'returns:num;depends:none;effects:none;gvn:true', - r'Math.max(#, #)', - checkNum(a), - checkNum(b)); + 'returns:num;depends:none;effects:none;gvn:true', + r'Math.max(#, #)', + checkNum(a), + checkNum(b), +); @patch double sqrt(num x) => JS('num', r'Math.sqrt(#)', checkNum(x)); @@ -257,13 +259,17 @@ class _JSSecureRandom implements Random { } } throw UnsupportedError( - 'No source of cryptographically secure random numbers available.'); + 'No source of cryptographically secure random numbers available.', + ); } /// Fill _buffer from [start] to `start + length` with random bytes. void _getRandomBytes(int start, int length) { - JS('void', 'crypto.getRandomValues(#)', - _buffer.buffer.asUint8List(start, length)); + JS( + 'void', + 'crypto.getRandomValues(#)', + _buffer.buffer.asUint8List(start, length), + ); } bool nextBool() { diff --git a/sdk/lib/_internal/js_runtime/lib/native_helper.dart b/sdk/lib/_internal/js_runtime/lib/native_helper.dart index d2bf3315a8f..533c648a02e 100644 --- a/sdk/lib/_internal/js_runtime/lib/native_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/native_helper.dart @@ -59,9 +59,10 @@ String toStringForNativeObject(var obj) { // TODO(sra): Is this code dead? // [getTagFunction] might be uninitialized, but in usual usage, toString has // been called via an interceptor and initialized it. - String name = getTagFunction == null - ? '' - : JS('String', '#', getTagFunction!(obj)); + String name = + getTagFunction == null + ? '' + : JS('String', '#', getTagFunction!(obj)); return 'Instance of $name'; } @@ -70,23 +71,24 @@ int hashCodeForNativeObject(object) => Primitives.objectHashCode(object); /// Sets a JavaScript property on an object. void defineProperty(var obj, String property, var value) { JS( - 'void', - 'Object.defineProperty(#, #, ' - '{value: #, enumerable: false, writable: true, configurable: true})', - obj, - property, - value); + 'void', + 'Object.defineProperty(#, #, ' + '{value: #, enumerable: false, writable: true, configurable: true})', + obj, + property, + value, + ); } // Is [obj] an instance of a Dart-defined class? bool isDartObject(obj) { // Some of the extra parens here are necessary. return JS( - 'bool', - '((#) instanceof (#))', - obj, - JS_BUILTIN( - 'depends:none;effects:none;', JsBuiltin.dartObjectConstructor)); + 'bool', + '((#) instanceof (#))', + obj, + JS_BUILTIN('depends:none;effects:none;', JsBuiltin.dartObjectConstructor), + ); } /// A JavaScript object mapping tags to the constructors of interceptors. @@ -103,7 +105,11 @@ get leafTags => JS_EMBEDDED_GLOBAL('=Object', LEAF_TAGS); String findDispatchTagForInterceptorClass(interceptorClassConstructor) { return JS( - '', r'#.#', interceptorClassConstructor, NATIVE_SUPERCLASS_TAG_NAME); + '', + r'#.#', + interceptorClassConstructor, + NATIVE_SUPERCLASS_TAG_NAME, + ); } /// Cache of dispatch records for instances. This is a JavaScript object used @@ -260,8 +266,12 @@ setNativeSubclassDispatchRecord(proto, interceptor) { } String constructorNameFallback(object) { - return JS('returns:String;effects:none;depends:none', '#(#)', - _constructorNameFallback, object); + return JS( + 'returns:String;effects:none;depends:none', + '#(#)', + _constructorNameFallback, + object, + ); } var initNativeDispatchFlag; // null or true @@ -358,8 +368,12 @@ void initHooks() { var hooks = JS('', '#()', _baseHooks); // Customize for browsers where `object.constructor.name` fails: - var _fallbackConstructorHooksTransformer = JS('', '#(#)', - _fallbackConstructorHooksTransformerGenerator, _constructorNameFallback); + var _fallbackConstructorHooksTransformer = JS( + '', + '#(#)', + _fallbackConstructorHooksTransformerGenerator, + _constructorNameFallback, + ); hooks = applyHooksTransformer(_fallbackConstructorHooksTransformer, hooks); // Customize for browsers: @@ -373,7 +387,9 @@ void initHooks() { // TODO(sra): Update ShadowDOM polyfil to use // [dartNativeDispatchHooksTransformer] and remove this hook. hooks = applyHooksTransformer( - _dartExperimentalFixupGetTagHooksTransformer, hooks); + _dartExperimentalFixupGetTagHooksTransformer, + hooks, + ); // Apply global hooks. // diff --git a/sdk/lib/_internal/js_runtime/lib/string_helper.dart b/sdk/lib/_internal/js_runtime/lib/string_helper.dart index 41fa7bbc60f..874add357dd 100644 --- a/sdk/lib/_internal/js_runtime/lib/string_helper.dart +++ b/sdk/lib/_internal/js_runtime/lib/string_helper.dart @@ -5,7 +5,10 @@ part of _js_helper; int stringIndexOfStringUnchecked( - String receiver, String other, int startIndex) { + String receiver, + String other, + int startIndex, +) { return JS('int', '#.indexOf(#, #)', receiver, other, startIndex); } @@ -18,16 +21,21 @@ String substring2Unchecked(String receiver, int startIndex, int endIndex) { } bool stringContainsStringUnchecked( - String receiver, String other, int startIndex) { + String receiver, + String other, + int startIndex, +) { return stringIndexOfStringUnchecked(receiver, other, startIndex) >= 0; } List stringSplitUnchecked( - String receiver, - /* String | JavaScript RegExp */ - pattern) { - return JSArray.markGrowable(JS( - 'returns:JSExtendableArray;new:true', '#.split(#)', receiver, pattern)); + String receiver, + /* String | JavaScript RegExp */ + pattern, +) { + return JSArray.markGrowable( + JS('returns:JSExtendableArray;new:true', '#.split(#)', receiver, pattern), + ); } class StringMatch implements Match { @@ -58,7 +66,10 @@ class StringMatch implements Match { } Iterable allMatchesInStringUnchecked( - String pattern, String string, int startIndex) { + String pattern, + String string, + int startIndex, +) { return _StringAllMatchesIterable(string, pattern, startIndex); } @@ -123,8 +134,13 @@ bool stringContainsUnchecked(String receiver, Pattern other, int startIndex) { } String stringReplaceJS(String receiver, jsRegExp, String replacement) { - return JS('String', r'#.replace(#, #)', receiver, jsRegExp, - escapeReplacement(replacement)); + return JS( + 'String', + r'#.replace(#, #)', + receiver, + jsRegExp, + escapeReplacement(replacement), + ); } String escapeReplacement(String replacement) { @@ -141,8 +157,12 @@ String escapeReplacement(String replacement) { return replacement; } -String stringReplaceFirstRE(String receiver, JSSyntaxRegExp regexp, - String replacement, int startIndex) { +String stringReplaceFirstRE( + String receiver, + JSSyntaxRegExp regexp, + String replacement, + int startIndex, +) { var match = regexp._execGlobal(receiver, startIndex); if (match == null) return receiver; var start = match.start; @@ -162,7 +182,10 @@ quoteStringForRegExp(string) { } String stringReplaceAllUnchecked( - String receiver, Pattern pattern, String replacement) { + String receiver, + Pattern pattern, + String replacement, +) { checkString(replacement); if (pattern is String) { return stringReplaceAllUncheckedString(receiver, pattern, replacement); @@ -177,7 +200,10 @@ String stringReplaceAllUnchecked( } String stringReplaceAllGeneral( - String receiver, Pattern pattern, String replacement) { + String receiver, + Pattern pattern, + String replacement, +) { checkNull(pattern); int startIndex = 0; StringBuffer result = StringBuffer(); @@ -195,7 +221,10 @@ String stringReplaceAllGeneral( /// (String.prototype.replaceAll)[https://github.com/tc39/proposal-string-replace-all] /// when available. String stringReplaceAllUncheckedString( - String receiver, String pattern, String replacement) { + String receiver, + String pattern, + String replacement, +) { if (pattern == "") { if (receiver == "") { return JS('String', '#', replacement); // help type inference. @@ -211,7 +240,8 @@ String stringReplaceAllUncheckedString( } if (!const bool.fromEnvironment( - 'dart2js.testing.String.replaceAll.force.regexp')) { + 'dart2js.testing.String.replaceAll.force.regexp', + )) { // First check for no match. int index = stringIndexOfStringUnchecked(receiver, pattern, 0); if (index < 0) return receiver; @@ -232,20 +262,31 @@ String stringReplaceAllUncheckedString( } String stringReplaceAllUsingSplitJoin( - String receiver, String pattern, String replacement) { + String receiver, + String pattern, + String replacement, +) { return JS('String', '#.split(#).join(#)', receiver, pattern, replacement); } String _matchString(Match match) => match[0]!; String _stringIdentity(String string) => string; -String stringReplaceAllFuncUnchecked(String receiver, Pattern pattern, - String Function(Match)? onMatch, String Function(String)? onNonMatch) { +String stringReplaceAllFuncUnchecked( + String receiver, + Pattern pattern, + String Function(Match)? onMatch, + String Function(String)? onNonMatch, +) { onMatch ??= _matchString; onNonMatch ??= _stringIdentity; if (pattern is String) { return stringReplaceAllStringFuncUnchecked( - receiver, pattern, onMatch, onNonMatch); + receiver, + pattern, + onMatch, + onNonMatch, + ); } // Placing the Pattern test here is indistinguishable from placing it at the // top of the method but it saves an extra check on the `pattern is String` @@ -264,8 +305,11 @@ String stringReplaceAllFuncUnchecked(String receiver, Pattern pattern, return buffer.toString(); } -String stringReplaceAllEmptyFuncUnchecked(String receiver, - String Function(Match) onMatch, String Function(String) onNonMatch) { +String stringReplaceAllEmptyFuncUnchecked( + String receiver, + String Function(Match) onMatch, + String Function(String) onNonMatch, +) { // Pattern is the empty string. StringBuffer buffer = StringBuffer(); int length = receiver.length; @@ -293,8 +337,12 @@ String stringReplaceAllEmptyFuncUnchecked(String receiver, return buffer.toString(); } -String stringReplaceAllStringFuncUnchecked(String receiver, String pattern, - String Function(Match) onMatch, String Function(String) onNonMatch) { +String stringReplaceAllStringFuncUnchecked( + String receiver, + String pattern, + String Function(Match) onMatch, + String Function(String) onNonMatch, +) { int patternLength = pattern.length; if (patternLength == 0) { return stringReplaceAllEmptyFuncUnchecked(receiver, onMatch, onNonMatch); @@ -316,7 +364,11 @@ String stringReplaceAllStringFuncUnchecked(String receiver, String pattern, } String stringReplaceFirstUnchecked( - String receiver, Pattern pattern, String replacement, int startIndex) { + String receiver, + Pattern pattern, + String replacement, + int startIndex, +) { if (pattern is String) { int index = stringIndexOfStringUnchecked(receiver, pattern, startIndex); if (index < 0) return receiver; @@ -335,8 +387,12 @@ String stringReplaceFirstUnchecked( return receiver.replaceRange(match.start, match.end, replacement); } -String stringReplaceFirstMappedUnchecked(String receiver, Pattern pattern, - String Function(Match) replace, int startIndex) { +String stringReplaceFirstMappedUnchecked( + String receiver, + Pattern pattern, + String Function(Match) replace, + int startIndex, +) { Iterator matches = pattern.allMatches(receiver, startIndex).iterator; if (!matches.moveNext()) return receiver; Match match = matches.current; @@ -345,7 +401,11 @@ String stringReplaceFirstMappedUnchecked(String receiver, Pattern pattern, } String stringReplaceRangeUnchecked( - String receiver, int start, int end, String replacement) { + String receiver, + int start, + int end, + String replacement, +) { var prefix = JS('String', '#.substring(0, #)', receiver, start); var suffix = JS('String', '#.substring(#)', receiver, end); return "$prefix$replacement$suffix"; diff --git a/sdk/lib/_internal/js_runtime/lib/synced/array_flags.dart b/sdk/lib/_internal/js_runtime/lib/synced/array_flags.dart index 319b7372979..17663676333 100644 --- a/sdk/lib/_internal/js_runtime/lib/synced/array_flags.dart +++ b/sdk/lib/_internal/js_runtime/lib/synced/array_flags.dart @@ -83,8 +83,7 @@ class ArrayFlags { ';setUint16' ';setUint32' ';setFloat32' - ';setFloat64' - // + ';setFloat64' // ; /// A list of 'verbs' for HArrayFlagsCheck, encoded as a string of phrases @@ -102,8 +101,7 @@ class ArrayFlags { static const verbs = // 'modify' // This is the verb for '[]=' so it comes first. ';remove from' - ';add to' - // + ';add to' // ; /// A view of [operationNames] as a map from the name to the index of the name