Skip to content

Commit 7d8459d

Browse files
kevmoocommit-bot@chromium.org
authored andcommitted
dart:_http: apply and fix most of pkg:lints recommended lints
TEST=N/A Change-Id: I3e3f0cd1d94743fbbe8cfcc5723eb38608be2a8b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217503 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Ben Konyi <[email protected]> Auto-Submit: Kevin Moore <[email protected]>
1 parent d0e5602 commit 7d8459d

14 files changed

+1940
-2304
lines changed

pkg/compiler/test/analyses/api_allowed.json

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,16 @@
9494
"org-dartlang-sdk:///lib/convert/json.dart": {
9595
"Dynamic invocation of 'toJson'.": 1
9696
},
97-
"org-dartlang-sdk:///lib/_http/crypto.dart": {
98-
"Dynamic invocation of '+'.": 2,
99-
"Dynamic invocation of '&'.": 3,
100-
"Dynamic invocation of 'unary-'.": 1,
101-
"Dynamic invocation of '-'.": 2
102-
},
103-
"org-dartlang-sdk:///lib/_http/http_date.dart": {
104-
"Dynamic access of 'length'.": 3,
105-
"Dynamic invocation of '<'.": 1,
106-
"Dynamic invocation of '>='.": 2,
107-
"Dynamic invocation of '[]'.": 7
108-
},
109-
"org-dartlang-sdk:///lib/_http/http_headers.dart": {
110-
"Dynamic invocation of 'toLowerCase'.": 1
111-
},
11297
"org-dartlang-sdk:///lib/_http/http_impl.dart": {
113-
"Dynamic access of 'headers'.": 1,
114-
"Dynamic invocation of 'forEach'.": 1,
115-
"Dynamic access of 'connectionInfo'.": 4,
116-
"Dynamic access of 'localPort'.": 1,
117-
"Dynamic access of 'remoteAddress'.": 2,
118-
"Dynamic access of 'address'.": 4,
119-
"Dynamic access of 'remotePort'.": 2,
12098
"Dynamic access of 'message'.": 3,
121-
"Dynamic invocation of 'call'.": 1,
12299
"Dynamic invocation of 'destroy'.": 2,
100+
"Dynamic access of 'address'.": 3,
123101
"Dynamic access of 'type'.": 1,
124102
"Dynamic invocation of 'setOption'.": 1,
125103
"Dynamic access of 'host'.": 2,
126104
"Dynamic access of 'port'.": 2,
105+
"Dynamic access of 'remoteAddress'.": 1,
106+
"Dynamic access of 'remotePort'.": 1,
127107
"Dynamic invocation of 'dart._http::_toJSON'.": 3,
128108
"Dynamic invocation of 'listen'.": 1,
129109
"Dynamic invocation of 'close'.": 1

pkg/front_end/testcases/nnbd_mixed/mock_http_headers.dart.weak.outline.expect

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ Evaluated: MapLiteral @ org-dartlang-testcase:///mock_http_headers.dart:13:7 ->
170170
Evaluated: SymbolLiteral @ org-dartlang-testcase:///mock_http_headers.dart:13:7 -> SymbolConstant(#noFolding)
171171
Evaluated: ListLiteral @ org-dartlang-testcase:///mock_http_headers.dart:13:7 -> ListConstant(const <Type*>[])
172172
Evaluated: MapLiteral @ org-dartlang-testcase:///mock_http_headers.dart:13:7 -> MapConstant(const <Symbol*, dynamic>{})
173-
Evaluated: SymbolLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:782:8 -> SymbolConstant(#clear)
174-
Evaluated: ListLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:782:8 -> ListConstant(const <Type*>[])
175-
Evaluated: ListLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:782:8 -> ListConstant(const <dynamic>[])
176-
Evaluated: MapLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:782:8 -> MapConstant(const <Symbol*, dynamic>{})
173+
Evaluated: SymbolLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:707:8 -> SymbolConstant(#clear)
174+
Evaluated: ListLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:707:8 -> ListConstant(const <Type*>[])
175+
Evaluated: ListLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:707:8 -> ListConstant(const <dynamic>[])
176+
Evaluated: MapLiteral @ org-dartlang-sdk:///sdk/lib/_http/http.dart:707:8 -> MapConstant(const <Symbol*, dynamic>{})
177177
Extra constant evaluation: evaluated: 268, effectively constant: 91

pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class Class extends core::Object {
2222
synthetic constructor •() → self::Class
2323
: super core::Object::•()
2424
;
25-
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3266,getterSelectorId:3267] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int
25+
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3252,getterSelectorId:3253] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int
2626
return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int};
2727
}

pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class ConstClass extends core::Object {
5151
synthetic constructor •() → self::ConstClass
5252
: super core::Object::•()
5353
;
54-
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3270,getterSelectorId:3271] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int
54+
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3256,getterSelectorId:3257] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int
5555
return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int};
5656
}

sdk/lib/_http/crypto.dart

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class _CryptoUtils {
2121
// -1 : '\r' or '\n'
2222
// 0 : = (Padding character).
2323
// >0 : Base 64 alphabet index of given byte.
24-
static const List<int> _decodeTable = const [
24+
static const List<int> _decodeTable = [
2525
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, //
2626
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, //
2727
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, //
@@ -40,18 +40,16 @@ class _CryptoUtils {
4040
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2
4141
];
4242

43-
static Random _rng = new Random.secure();
44-
4543
static Uint8List getRandomBytes(int count) {
46-
final Uint8List result = new Uint8List(count);
44+
final Uint8List result = Uint8List(count);
4745
for (int i = 0; i < count; i++) {
48-
result[i] = _rng.nextInt(0xff);
46+
result[i] = Random.secure().nextInt(0xff);
4947
}
5048
return result;
5149
}
5250

5351
static String bytesToHex(List<int> bytes) {
54-
var result = new StringBuffer();
52+
var result = StringBuffer();
5553
for (var part in bytes) {
5654
result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}');
5755
}
@@ -66,15 +64,15 @@ class _CryptoUtils {
6664
}
6765
final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable;
6866
// Size of 24 bit chunks.
69-
final int remainderLength = len.remainder(3) as int;
67+
final int remainderLength = len.remainder(3);
7068
final int chunkLength = len - remainderLength;
7169
// Size of base output.
7270
int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0);
7371
// Add extra for line separators.
7472
if (addLineSeparator) {
7573
outputLen += ((outputLen - 1) ~/ LINE_LENGTH) << 1;
7674
}
77-
List<int> out = new List<int>.filled(outputLen, 0);
75+
List<int> out = List<int>.filled(outputLen, 0);
7876

7977
// Encode 24 bit chunks.
8078
int j = 0, i = 0, c = 0;
@@ -111,14 +109,14 @@ class _CryptoUtils {
111109
out[j++] = PAD;
112110
}
113111

114-
return new String.fromCharCodes(out);
112+
return String.fromCharCodes(out);
115113
}
116114

117115
static List<int> base64StringToBytes(String input,
118116
[bool ignoreInvalidCharacters = true]) {
119117
int len = input.length;
120118
if (len == 0) {
121-
return new List<int>.empty();
119+
return List<int>.empty();
122120
}
123121

124122
// Count '\r', '\n' and illegal characters, For illegal characters,
@@ -129,13 +127,13 @@ class _CryptoUtils {
129127
if (c < 0) {
130128
extrasLen++;
131129
if (c == -2 && !ignoreInvalidCharacters) {
132-
throw new FormatException('Invalid character: ${input[i]}');
130+
throw FormatException('Invalid character: ${input[i]}');
133131
}
134132
}
135133
}
136134

137135
if ((len - extrasLen) % 4 != 0) {
138-
throw new FormatException('''Size of Base 64 characters in Input
136+
throw FormatException('''Size of Base 64 characters in Input
139137
must be a multiple of 4. Input: $input''');
140138
}
141139

@@ -147,7 +145,7 @@ class _CryptoUtils {
147145
if (currentCodeUnit == PAD) padLength++;
148146
}
149147
int outputLen = (((len - extrasLen) * 6) >> 3) - padLength;
150-
List<int> out = new List<int>.filled(outputLen, 0);
148+
List<int> out = List<int>.filled(outputLen, 0);
151149

152150
for (int i = 0, o = 0; o < outputLen;) {
153151
// Accumulate 4 valid 6 bit Base 64 characters into an int.
@@ -183,20 +181,19 @@ abstract class _HashBase {
183181
final bool _bigEndianWords;
184182
int _lengthInBytes = 0;
185183
List<int> _pendingData;
186-
List<int> _currentChunk;
187-
List<int> _h;
184+
final List<int> _currentChunk;
185+
final List<int> _h;
188186
bool _digestCalled = false;
189187

190188
_HashBase(this._chunkSizeInWords, int digestSizeInWords, this._bigEndianWords)
191189
: _pendingData = [],
192-
_currentChunk = new List.filled(_chunkSizeInWords, 0),
193-
_h = new List.filled(digestSizeInWords, 0);
190+
_currentChunk = List.filled(_chunkSizeInWords, 0),
191+
_h = List.filled(digestSizeInWords, 0);
194192

195193
// Update the hasher with more data.
196194
add(List<int> data) {
197195
if (_digestCalled) {
198-
throw new StateError(
199-
'Hash update method called after digest was retrieved');
196+
throw StateError('Hash update method called after digest was retrieved');
200197
}
201198
_lengthInBytes += data.length;
202199
_pendingData.addAll(data);
@@ -211,7 +208,7 @@ abstract class _HashBase {
211208
_digestCalled = true;
212209
_finalizeData();
213210
_iterate();
214-
assert(_pendingData.length == 0);
211+
assert(_pendingData.isEmpty);
215212
return _resultAsBytes();
216213
}
217214

@@ -227,8 +224,8 @@ abstract class _HashBase {
227224
_updateHash(List<int> m);
228225

229226
// Helper methods.
230-
_add32(x, y) => (x + y) & _MASK_32;
231-
_roundUp(val, n) => (val + n - 1) & -n;
227+
int _add32(int x, int y) => (x + y) & _MASK_32;
228+
int _roundUp(int val, int n) => (val + n - 1) & -n;
232229

233230
// Rotate left limiting to unsigned 32-bit values.
234231
int _rotl32(int val, int shift) {
@@ -266,7 +263,7 @@ abstract class _HashBase {
266263

267264
// Convert a 32-bit word to four bytes.
268265
List<int> _wordToBytes(int word) {
269-
List<int> bytes = new List.filled(_BYTES_PER_WORD, 0);
266+
List<int> bytes = List.filled(_BYTES_PER_WORD, 0);
270267
bytes[0] = (word >> (_bigEndianWords ? 24 : 0)) & _MASK_8;
271268
bytes[1] = (word >> (_bigEndianWords ? 16 : 8)) & _MASK_8;
272269
bytes[2] = (word >> (_bigEndianWords ? 8 : 16)) & _MASK_8;
@@ -323,10 +320,10 @@ class _MD5 extends _HashBase {
323320

324321
// Returns a new instance of this Hash.
325322
_MD5 newInstance() {
326-
return new _MD5();
323+
return _MD5();
327324
}
328325

329-
static const _k = const [
326+
static const _k = [
330327
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, //
331328
0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //
332329
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, //
@@ -340,7 +337,7 @@ class _MD5 extends _HashBase {
340337
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
341338
];
342339

343-
static const _r = const [
340+
static const _r = [
344341
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, //
345342
20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, //
346343
16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, //
@@ -357,8 +354,8 @@ class _MD5 extends _HashBase {
357354
var c = _h[2];
358355
var d = _h[3];
359356

360-
var t0;
361-
var t1;
357+
int t0;
358+
int t1;
362359

363360
for (var i = 0; i < 64; i++) {
364361
if (i < 16) {
@@ -392,7 +389,7 @@ class _MD5 extends _HashBase {
392389

393390
// The SHA1 hasher is used to compute an SHA1 message digest.
394391
class _SHA1 extends _HashBase {
395-
List<int> _w;
392+
final List<int> _w;
396393

397394
// Construct a SHA1 hasher object.
398395
_SHA1()
@@ -407,7 +404,7 @@ class _SHA1 extends _HashBase {
407404

408405
// Returns a new instance of this Hash.
409406
_SHA1 newInstance() {
410-
return new _SHA1();
407+
return _SHA1();
411408
}
412409

413410
// Compute one iteration of the SHA1 algorithm with a chunk of

0 commit comments

Comments
 (0)