Skip to content

Commit d6e7aac

Browse files
committed
Version 2.12.1
* Cherry-pick ea3dfc9 to stable * Cherry-pick eb6b474 to stable * Cherry-pick d9361f7 to stable * Cherry-pick e962528 to stable * Cherry-pick 29c2197 to stable
2 parents 72c1995 + b73ec79 commit d6e7aac

File tree

7 files changed

+342
-196
lines changed

7 files changed

+342
-196
lines changed

CHANGELOG.md

Lines changed: 222 additions & 159 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Verify that socket connection gracefully closes if cancelled.
6+
7+
import 'dart:async';
8+
import 'dart:io';
9+
10+
import 'package:expect/expect.dart';
11+
12+
void main() async {
13+
final task = await Socket.startConnect('google.com', 80);
14+
task.cancel();
15+
try {
16+
await task.socket;
17+
} catch (e) {
18+
Expect.isTrue(e is SocketException);
19+
final socketException = e as SocketException;
20+
Expect.isTrue(
21+
socketException.message.startsWith('Connection attempt cancelled'));
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Verify that socket connection gracefully closes if cancelled.
6+
7+
import 'dart:async';
8+
import 'dart:io';
9+
10+
import 'package:expect/expect.dart';
11+
12+
void main() async {
13+
final task = await Socket.startConnect('google.com', 80);
14+
task.cancel();
15+
try {
16+
await task.socket;
17+
} catch (e) {
18+
Expect.isTrue(e is SocketException);
19+
final socketException = e as SocketException;
20+
Expect.isTrue(
21+
socketException.message.startsWith('Connection attempt cancelled'));
22+
}
23+
}

sdk/lib/_internal/vm/bin/socket_patch.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
844844
}
845845
connecting.clear();
846846
addressesSubscription.cancel();
847-
result.complete(socket);
847+
if (!result.isCompleted) {
848+
// Might be already completed via onCancel
849+
result.complete(socket);
850+
}
848851
}, error: (e, st) {
849852
connecting.remove(socket);
850853
socket.close();
@@ -864,6 +867,7 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
864867
s.setHandlers();
865868
s.setListening(read: false, write: false);
866869
}
870+
addressesSubscription.cancel();
867871
connecting.clear();
868872
if (!result.isCompleted) {
869873
error ??= createError(

sdk/lib/_internal/vm/lib/typed_data_patch.dart

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,7 @@ mixin _IntListMixin implements List<int> {
150150
return -1;
151151
}
152152

153-
List<int> operator +(List<int> other) {
154-
int totalLength = this.length + other.length;
155-
return <int>[]
156-
..length = totalLength
157-
..setRange(0, this.length, this)
158-
..setRange(this.length, totalLength, other);
159-
}
153+
List<int> operator +(List<int> other) => [...this, ...other];
160154

161155
bool contains(Object? element) {
162156
var len = this.length;
@@ -506,13 +500,7 @@ mixin _DoubleListMixin implements List<double> {
506500
return -1;
507501
}
508502

509-
List<double> operator +(List<double> other) {
510-
int totalLength = this.length + other.length;
511-
return <double>[]
512-
..length = totalLength
513-
..setRange(0, this.length, this)
514-
..setRange(this.length, totalLength, other);
515-
}
503+
List<double> operator +(List<double> other) => [...this, ...other];
516504

517505
bool contains(Object? element) {
518506
var len = this.length;
@@ -868,13 +856,7 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
868856
return -1;
869857
}
870858

871-
List<Float32x4> operator +(List<Float32x4> other) {
872-
int totalLength = this.length + other.length;
873-
return <Float32x4>[]
874-
..length = totalLength
875-
..setRange(0, this.length, this)
876-
..setRange(this.length, totalLength, other);
877-
}
859+
List<Float32x4> operator +(List<Float32x4> other) => [...this, ...other];
878860

879861
bool contains(Object? element) {
880862
var len = this.length;
@@ -1228,13 +1210,7 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
12281210
return -1;
12291211
}
12301212

1231-
List<Int32x4> operator +(List<Int32x4> other) {
1232-
int totalLength = this.length + other.length;
1233-
return <Int32x4>[]
1234-
..length = totalLength
1235-
..setRange(0, this.length, this)
1236-
..setRange(this.length, totalLength, other);
1237-
}
1213+
List<Int32x4> operator +(List<Int32x4> other) => [...this, ...other];
12381214

12391215
bool contains(Object? element) {
12401216
var len = this.length;
@@ -1587,13 +1563,7 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
15871563
return -1;
15881564
}
15891565

1590-
List<Float64x2> operator +(List<Float64x2> other) {
1591-
int totalLength = this.length + other.length;
1592-
return <Float64x2>[]
1593-
..length = totalLength
1594-
..setRange(0, this.length, this)
1595-
..setRange(this.length, totalLength, other);
1596-
}
1566+
List<Float64x2> operator +(List<Float64x2> other) => [...this, ...other];
15971567

15981568
bool contains(Object? element) {
15991569
var len = this.length;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:math' show Random;
6+
import 'dart:typed_data';
7+
import 'package:expect/expect.dart';
8+
9+
void main() {
10+
var r = Random();
11+
int genInt() => r.nextInt(256);
12+
double genDbl() => r.nextDouble();
13+
Int32x4 genIx4() => Int32x4(genInt(), genInt(), genInt(), genInt());
14+
Float32x4 genFx4() => Float32x4(genDbl(), genDbl(), genDbl(), genDbl());
15+
Float64x2 genDx2() => Float64x2(genDbl(), genDbl());
16+
17+
test("Uint8List", (n) => Uint8List(n)..fill(genInt));
18+
test("Uint16List", (n) => Uint16List(n)..fill(genInt));
19+
test("Uint32List", (n) => Uint32List(n)..fill(genInt));
20+
test("Int8List", (n) => Int8List(n)..fill(genInt));
21+
test("Int16List", (n) => Int16List(n)..fill(genInt));
22+
test("Int32List", (n) => Int32List(n)..fill(genInt));
23+
test("Uint8ClampedList", (n) => Uint8ClampedList(n)..fill(genInt));
24+
test("Float32List", (n) => Float32List(n)..fill(genDbl));
25+
test("Float64List", (n) => Float64List(n)..fill(genDbl));
26+
test("Int32x4List", (n) => Int32x4List(n)..fill(genIx4));
27+
test("Float32x4List", (n) => Float32x4List(n)..fill(genFx4));
28+
test("Float64x2List", (n) => Float64x2List(n)..fill(genDx2));
29+
}
30+
31+
void test<T>(String name, List<T> create(int n)) {
32+
var l1 = create(17);
33+
var l2 = create(13);
34+
List<T> l3;
35+
try {
36+
// Shouldn't throw:
37+
l3 = l1 + l2;
38+
} catch (e) {
39+
// Until we change Expect.fail to return Never.
40+
Expect.fail("$name: $e") as Never;
41+
}
42+
Expect.equals(30, l3.length);
43+
if (0 is T || 0.0 is T) {
44+
// Int32x4 etc. do not support `==`.
45+
Expect.listEquals(l1, l3.sublist(0, 17), "$name first");
46+
Expect.listEquals(l2, l3.sublist(17), "$name second");
47+
}
48+
// Result is growable, shouldn't throw.
49+
try {
50+
l3.add(l3.first);
51+
} catch (e) {
52+
Expect.fail("$name: $e");
53+
}
54+
}
55+
56+
// Fill a list with (random) generated values.
57+
extension<T> on List<T> {
58+
void fill(T gen()) {
59+
for (var i = 0; i < length; i++) {
60+
this[i] = gen();
61+
}
62+
}
63+
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
CHANNEL stable
2727
MAJOR 2
2828
MINOR 12
29-
PATCH 0
29+
PATCH 1
3030
PRERELEASE 0
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)