Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/compiler/dart2js_extra/code_motion_exception_test.dart

Issue 209693002: Test for preservation of exception order with code motion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/dart2js_extra.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 "package:expect/expect.dart";
6
7 // Test for correct order of exceptions in code with checks that could be moved
8 // merged from successors into a dominator.
9
10 get never => new DateTime.now().millisecondsSinceEpoch == 42;
11 get always => new DateTime.now().millisecondsSinceEpoch > 42;
12
13 // gA and gB have type [null|num], so they compile to a receiver check, and
14 // argument check and then the operation.
15 var gA; // [null|num]
16 var gB; // [null|num]
17
18 foo1(a, b) {
19 // The checks on a and b are not equivalent, so can't be merged.
20 if (never) {
21 return a ^ b;
22 } else {
23 return b ^ a;
24 }
25 }
26
27 call1() { return foo1(gA, gB); }
28
29 test1() {
30 gA = 1;
31 gB = 2;
32 Expect.equals(3, call1());
33
34 gA = null;
35 gB = null;
36 Expect.throws(call1, (e) => e is NoSuchMethodError, 'foo1($gA, $gB) NSME');
37
38 gA = 1;
39 gB = null;
40 Expect.throws(call1, (e) => e is NoSuchMethodError, 'foo1($gA, $gB) NSME');
41
42 gA = null;
43 gB = 2;
44 Expect.throws(call1, (e) => e is ArgumentError, 'foo1($gA, $gB) AE');
45 }
46
47
48 foo2a(a, b) {
49 // The common receiver check on [a] cannot be merged because the operation
50 // (selector) is different.
51 // The common argument check on [b] cannot be merged because it must happen
52 // after the receiver check.
53 if (never) {
54 return a ^ b;
55 } else {
56 return a & b;
57 }
58 }
59
60 foo2b(a, b) {
61 // Same a foo2a except which branch dynamically taken.
62 if (always) {
63 return a ^ b;
64 } else {
65 return a & b;
66 }
67 }
68
69 call2a() { return foo2a(gA, gB); }
70 call2b() { return foo2b(gA, gB); }
71
72 checkNSME(text) {
73 return (e) {
74 Expect.isTrue(e is NoSuchMethodError,
75 'expecting NoSuchMethodError, got "${e.runtimeType}"');
76 Expect.isTrue('$e'.contains(text), '"$e".contains("$text")');
77 return e is NoSuchMethodError;
78 };
79 }
80
81 test2() {
82 gA = 1;
83 gB = 2;
84 Expect.equals(0, call2a());
85 Expect.equals(3, call2b());
86
87 gA = null;
88 gB = null;
89 Expect.throws(call2a, checkNSME(r'$and'), 'foo2($gA, $gB) NSME');
90 Expect.throws(call2b, checkNSME(r'$xor'), 'foo2($gA, $gB) NSME');
91
92 gA = 1;
93 gB = null;
94 Expect.throws(call2a, (e) => e is ArgumentError, 'foo2($gA, $gB) AE');
95 Expect.throws(call2b, (e) => e is ArgumentError, 'foo2($gA, $gB) AE');
96
97 gA = null;
98 gB = 2;
99 Expect.throws(call2a, checkNSME(r'$and'), 'foo2($gA, $gB) NSME');
100 Expect.throws(call2b, checkNSME(r'$xor'), 'foo2($gA, $gB) NSME');
101 }
102
103 main() {
104 test1();
105 test2();
106 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/dart2js_extra.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698