File tree Expand file tree Collapse file tree 12 files changed +70
-40
lines changed
LanguageFeatures/FinalizationRegistry Expand file tree Collapse file tree 12 files changed +70
-40
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ main() {
26
26
Expect .throws (() {
27
27
S s = p1.ref;
28
28
WeakReference wr = WeakReference <S >(s);
29
- print (wr.target);
30
29
});
31
30
} finally {
32
31
calloc.free (p1);
@@ -36,7 +35,6 @@ main() {
36
35
Expect .throws (() {
37
36
S s = p2.ref;
38
37
WeakReference wr = WeakReference (s);
39
- print (wr.target);
40
38
});
41
39
} finally {
42
40
calloc.free (p2);
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ main() {
28
28
Expect .throws (() {
29
29
U u = p1.ref;
30
30
WeakReference wr = WeakReference <U >(u);
31
- print (wr.target);
32
31
});
33
32
} finally {
34
33
calloc.free (p1);
@@ -38,7 +37,6 @@ main() {
38
37
Expect .throws (() {
39
38
U u = p2.ref;
40
39
WeakReference wr = WeakReference (u);
41
- print (wr.target);
42
40
});
43
41
} finally {
44
42
calloc.free (p2);
Original file line number Diff line number Diff line change @@ -27,24 +27,28 @@ class C {
27
27
28
28
dynamic d;
29
29
30
+ @pragma ('vm:never-inline' )
31
+ C ? getNullObject () => null ;
32
+
30
33
@pragma ('vm:never-inline' )
31
34
WeakReference <C > createWeakReference () {
32
35
C ? c = C (42 );
33
36
d = c;
34
37
WeakReference <C > wr = WeakReference (c);
35
38
Expect .equals (c, wr.target);
36
- c = null ;
39
+ c = getNullObject ();
40
+ Expect .isNull (c);
37
41
triggerGc ();
38
- Expect .isNotNull (wr.target);
39
42
Expect .equals (d, wr.target);
40
43
return wr;
41
44
}
42
45
43
46
main () {
44
47
WeakReference <C > wr = createWeakReference ();
45
48
triggerGc ();
46
- Expect .isNotNull (wr.target);
47
- d = 42 ;
49
+ Expect .equals ("C(42)" , wr.target.toString ());
50
+ d = getNullObject ();
51
+ Expect .isNull (d);
48
52
triggerGc ();
49
53
Expect .isNull (wr.target);
50
54
}
Original file line number Diff line number Diff line change @@ -25,25 +25,35 @@ class C {
25
25
String toString () => "C($id )" ;
26
26
}
27
27
28
- main () async {
28
+ @pragma ('vm:never-inline' )
29
+ C ? getNullObject () => null ;
30
+
31
+ @pragma ('vm:never-inline' )
32
+ Future <WeakReference > createWeakReference () async {
29
33
C ? c1 = C (42 );
30
34
WeakReference <C > wr = WeakReference (c1);
31
35
asyncStart ();
32
36
Future <C ?>.delayed (Duration (milliseconds: 1 ), () => c1).then ((C ? c2) async {
33
- Expect .isNotNull (wr.target);
34
37
Expect .equals (c1, wr.target);
35
38
triggerGc ();
36
39
await Future .delayed (Duration (seconds: 1 ));
37
40
Expect .isNotNull (wr.target);
38
- c2 = null ;
41
+ // Need to be sure that indeed c2 is null and the code is not optimized
42
+ c2 = getNullObject ();
43
+ Expect .isNull (c2);
39
44
triggerGc ();
40
45
Expect .isNull (wr.target);
41
46
asyncEnd ();
42
47
});
43
48
await Future .delayed (Duration (milliseconds: 10 ));
44
- Expect .isNotNull (wr.target);
45
49
Expect .equals (c1, wr.target);
46
- c1 = null ;
50
+ c1 = getNullObject ();
51
+ Expect .isNull (c1);
52
+ return wr;
53
+ }
54
+
55
+ main () async {
56
+ WeakReference wr = await createWeakReference ();
47
57
triggerGc ();
48
- Expect .isNotNull ( wr.target);
58
+ Expect .equals ( "C(42)" , wr.target. toString () );
49
59
}
Original file line number Diff line number Diff line change @@ -25,24 +25,32 @@ class C {
25
25
String toString () => "C($id )" ;
26
26
}
27
27
28
- main () async {
28
+ @pragma ('vm:never-inline' )
29
+ C ? getNullObject () => null ;
30
+
31
+ @pragma ('vm:never-inline' )
32
+ Future <WeakReference > createWeakReference () async {
29
33
C ? c1 = C (42 );
30
34
WeakReference <C > wr = WeakReference (c1);
31
35
asyncStart ();
32
36
Future <C ?>.delayed (Duration (milliseconds: 1 ), () => c1).then ((C ? c2) async {
33
- Expect .isNotNull (wr.target);
34
37
Expect .equals (c1, wr.target);
35
38
triggerGc ();
36
- Expect .isNotNull (wr.target);
37
- c2 = null ;
39
+ Expect .equals (c1, wr.target);
40
+ // Need to be sure that indeed c2 is null and the code is not optimized
41
+ c2 = getNullObject ();
42
+ Expect .isNull (c2);
38
43
triggerGc ();
39
- Expect .isNotNull ( wr.target);
44
+ Expect .equals (c1, wr.target);
40
45
asyncEnd ();
41
46
});
42
- Expect .isNotNull (wr.target);
43
47
Expect .equals (c1, wr.target);
48
+ return wr;
49
+ }
50
+
51
+ main () async {
52
+ WeakReference wr = await createWeakReference ();
44
53
await Future .delayed (Duration (seconds: 1 ));
45
- c1 = null ;
46
54
triggerGc ();
47
55
Expect .isNull (wr.target);
48
56
}
Original file line number Diff line number Diff line change @@ -27,24 +27,32 @@ class C {
27
27
28
28
C ? c1;
29
29
30
+ @pragma ('vm:never-inline' )
31
+ C ? getNullObject () => null ;
32
+
33
+ @pragma ('vm:never-inline' )
34
+ C ? getC () => C (0 );
35
+
30
36
@pragma ('vm:never-inline' )
31
37
WeakReference <C > createWeakReference () {
32
38
C ? c2 = C (42 );
33
39
c1 = c2;
34
40
WeakReference <C > wr = WeakReference (c2);
35
41
Expect .equals (c2, wr.target);
36
- c2 = null ;
42
+ // Need to be sure that indeed c2 is null and the code is not optimized
43
+ c2 = getNullObject ();
44
+ Expect .isNull (c2);
37
45
triggerGc ();
38
- Expect .isNotNull (wr.target);
39
46
Expect .equals (c1, wr.target);
40
47
return wr;
41
48
}
42
49
43
50
main () {
44
51
WeakReference <C > wr = createWeakReference ();
45
52
triggerGc ();
46
- Expect .isNotNull (wr.target);
47
- c1 = C (- 1 );
53
+ Expect .equals ("C(42)" , wr.target.toString ());
54
+ c1 = getC ();
55
+ Expect .isNotNull (c1);
48
56
triggerGc ();
49
57
Expect .isNull (wr.target);
50
58
}
Original file line number Diff line number Diff line change @@ -38,10 +38,17 @@ List<WeakReference<C>> createWeakReference() {
38
38
return [wr1, wr2];
39
39
}
40
40
41
+ @pragma ('vm:never-inline' )
42
+ void checkReferences (List <WeakReference <C >> refs) {
43
+ C ? c1 = refs[0 ].target;
44
+ C ? c2 = refs[1 ].target;
45
+ Expect .isTrue (c1 == null || c1.toString () == "C(42)" );
46
+ Expect .isTrue (c2 == null || c2.toString () == "C(42)" );
47
+ }
48
+
41
49
main () {
42
50
List <WeakReference <C >> refs = createWeakReference ();
43
- Expect .isNotNull (refs[0 ].target);
44
- Expect .isNotNull (refs[1 ].target);
51
+ checkReferences (refs);
45
52
triggerGc ();
46
53
Expect .isNull (refs[0 ].target);
47
54
Expect .isNull (refs[1 ].target);
Original file line number Diff line number Diff line change @@ -30,13 +30,19 @@ WeakReference<C> createWeakReference() {
30
30
C c = C (42 );
31
31
WeakReference <C > wr = WeakReference (c);
32
32
Future <C >.delayed (Duration (milliseconds: 10 ), () => c);
33
- c = C (- 1 );
34
33
return wr;
35
34
}
36
35
37
- main () {
36
+ @pragma ('vm:never-inline' )
37
+ void checkReference (WeakReference <C > ref) {
38
+ C ? c = ref.target;
39
+ Expect .isTrue (c == null || c.toString () == "C(42)" );
40
+ }
41
+
42
+ main () async {
38
43
WeakReference <C > wr = createWeakReference ();
39
- Expect .isNotNull (wr.target);
44
+ checkReference (wr);
45
+ await Future .delayed (Duration (seconds: 1 ));
40
46
triggerGc ();
41
47
Expect .isNull (wr.target);
42
48
}
Original file line number Diff line number Diff line change @@ -16,11 +16,9 @@ import '../../../../Utils/expect.dart';
16
16
main () {
17
17
Expect .throws (() {
18
18
WeakReference wr = WeakReference <String >("Lily was here" );
19
- print (wr.target);
20
19
});
21
20
Expect .throws (() {
22
21
String s = "Lily was here" ;
23
22
WeakReference wr = WeakReference (s);
24
- print (wr.target);
25
23
});
26
24
}
Original file line number Diff line number Diff line change @@ -16,26 +16,20 @@ import '../../../../Utils/expect.dart';
16
16
main () {
17
17
Expect .throws (() {
18
18
WeakReference wr = WeakReference <int >(42 );
19
- print (wr.target);
20
19
});
21
20
Expect .throws (() {
22
21
WeakReference wr = WeakReference (42 );
23
- print (wr.target);
24
22
});
25
23
Expect .throws (() {
26
24
WeakReference wr = WeakReference <double >(3.14 );
27
- print (wr.target);
28
25
});
29
26
Expect .throws (() {
30
27
WeakReference wr = WeakReference (3.14 );
31
- print (wr.target);
32
28
});
33
29
Expect .throws (() {
34
30
WeakReference wr = WeakReference <num >(42 );
35
- print (wr.target);
36
31
});
37
32
Expect .throws (() {
38
33
WeakReference wr = WeakReference <num >(3.14 );
39
- print (wr.target);
40
34
});
41
35
}
Original file line number Diff line number Diff line change @@ -16,6 +16,5 @@ main() {
16
16
Expect .throws (() {
17
17
dynamic d = null ;
18
18
WeakReference wr = WeakReference (d);
19
- print (wr.target);
20
19
});
21
20
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class C {
21
21
}
22
22
23
23
main () {
24
- C ? c = C (42 );
24
+ C c = C (42 );
25
25
WeakReference <C > wr = WeakReference (c);
26
26
Expect .equals (c, wr.target);
27
27
}
You can’t perform that action at this time.
0 commit comments