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

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

Issue 1327423002: Test for consistent JSArray indexer errors (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | 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) 2015, 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 // Test that optimized JSArray indexers enerate the same error as dyncamically
6 // dispatched calls.
7
8 import 'package:expect/expect.dart';
9
10 @NoInline() @AssumeDynamic()
11 confuse(x) => x;
12
13
14 Error getError(action()) {
15 try {
16 action();
17 Expect.fail('must throw');
Lasse Reichstein Nielsen 2015/09/11 06:16:57 Move this outside the try/catch, otherwise you'll
sra1 2015/09/11 17:33:34 Done.
18 } catch (e) {
19 return e;
20 }
21 }
22
23 indexErrorContainsIndex() {
24 fault(i) {
Lasse Reichstein Nielsen 2015/09/11 06:16:58 You could write this as: fault(i) => () => confu
sra1 2015/09/11 17:33:34 Done.
25 return confuse([])[i];
26 }
27
28 var e1 = getError(() => fault(1234));
29 var e2 = getError(() => fault(1234000));
30 var e3 = getError(() => fault(1234000000000));
31
32 Expect.equals('$e1', '$e2'.replaceAll('000', ''));
33 Expect.equals('$e1', '$e3'.replaceAll('000', ''));
34 Expect.equals('$e1'.length + 3, '$e2'.length);
35 Expect.equals('$e1'.length + 9, '$e3'.length);
36 }
37
38 indexEmpty() {
39 fault1() {
40 // Single indexing might go via one-shot interceptor that might have an
41 // accelerated path.
42 return confuse([])[0];
43 }
44
45 fault2() {
46 var a = [];
47 while (confuse(false)) a.add(1);
48 // Easily inferred type and open coded indexer.
49 return a[0];
50 }
51
52 fault3() {
53 var a = confuse([]);
54 // Multiple indexing might go via shared interceptor.
55 return [a[0], a[1], a[2]];
56 }
57
58 var e1 = getError(fault1);
59 var e2 = getError(fault2);
60 var e3 = getError(fault3);
61
62 Expect.equals('$e1', '$e2');
63 Expect.equals('$e1', '$e3');
64 }
65
66 indexHugeEmpty() {
67 int HUGE;
68
69 fault1() {
70 return confuse([])[HUGE];
71 }
72
73 fault2() {
74 var a = [];
75 while (confuse(false)) a.add(1);
76 return a[HUGE];
77 }
78
79 fault3() {
80 var a = confuse([]);
81 return [a[HUGE], a[1], a[2]];
82 }
83
84 HUGE = 1000000000000;
Lasse Reichstein Nielsen 2015/09/11 06:16:57 Why not initialize HUGE above? If there is a reaso
sra1 2015/09/11 17:33:34 Done.
85 var e1 = getError(fault1);
86 var e2 = getError(fault2);
87 var e3 = getError(fault3);
88
89 Expect.equals('$e1', '$e2');
90 Expect.equals('$e1', '$e3');
91 }
92
93 indexNonempty() {
94 fault1() {
95 // Single indexing might go via one-shot interceptor that might have an
96 // accelerated path.
97 return confuse([1])[1];
98 }
99
100 fault2() {
101 var a = [1];
102 while (confuse(false)) a.add(1);
103 // Easily inferred type and open coded indexer.
104 return a[1];
105 }
106
107 fault3() {
108 var a = confuse([1]);
109 // Multiple indexing might go via shared interceptor.
110 return [a[0], a[1], a[2]];
111 }
112
113 var e1 = getError(fault1);
114 var e2 = getError(fault2);
115 var e3 = getError(fault3);
116
117 Expect.equals('$e1', '$e2');
118 Expect.equals('$e1', '$e3');
119 }
Lasse Reichstein Nielsen 2015/09/11 06:16:57 Could these tests be parameterized with (list, ind
sra1 2015/09/11 17:33:34 I'm wary that making the code general will inhibit
120
121 indexHugeNonempty() {
122 int HUGE;
123
124 fault1() {
125 return confuse([1])[HUGE];
126 }
127
128 fault2() {
129 var a = [1];
130 while (confuse(false)) a.add(1);
131 return a[HUGE];
132 }
133
134 fault3() {
135 var a = confuse([1]);
136 return [a[HUGE], a[1], a[2]];
137 }
138
139 HUGE = 1000000000000;
140 var e1 = getError(fault1);
141 var e2 = getError(fault2);
142 var e3 = getError(fault3);
143
144 Expect.equals('$e1', '$e2');
145 Expect.equals('$e1', '$e3');
146 }
147
148 indexSetEmpty() {
149 fault1() {
150 // Single indexing might go via one-shot interceptor that has an accelerated
151 // path.
152 confuse([])[0] = 0;
153 }
154
155 fault2() {
156 var a = [];
157 while (confuse(false)) a.add(1);
158 // Easily inferred type and open coded indexer.
159 a[0] = 0;
160 return a;
161 }
162
163 fault3() {
164 var a = confuse([]);
165 // Multiple indexing might go via shared interceptor.
166 a[0] = 0;
167 a[1] = 0;
168 a[2] = 0;
169 return a;
170 }
171
172 var e1 = getError(fault1);
173 var e2 = getError(fault2);
174 var e3 = getError(fault3);
175
176 Expect.equals('$e1', '$e2');
177 Expect.equals('$e1', '$e3');
178 }
179
180 indexSetNonempty() {
Lasse Reichstein Nielsen 2015/09/11 06:16:57 No Huge version of indexSet tests?
sra1 2015/09/11 17:33:34 Added in the 'variable' tests.
181 fault1() {
182 // Single indexing might go via one-shot interceptor that has an accelerated
183 // path.
184 confuse([1])[1] = 0;
185 }
186
187 fault2() {
188 var a = [1];
189 while (confuse(false)) a.add(1);
190 // Easily inferred type and open coded indexer.
191 a[1] = 0;
192 return a;
193 }
194
195 fault3() {
196 var a = confuse([1]);
197 // Multiple indexing might go via shared interceptor.
198 a[0] = 0;
199 a[1] = 0;
200 a[2] = 0;
201 return a;
202 }
203
204 var e1 = getError(fault1);
205 var e2 = getError(fault2);
206 var e3 = getError(fault3);
207
208 Expect.equals('$e1', '$e2');
209 Expect.equals('$e1', '$e3');
210 }
211
212 main() {
213 indexErrorContainsIndex();
214 indexEmpty();
215 indexHugeEmpty();
216 indexNonempty();
217 indexHugeNonempty();
218 indexSetEmpty();
219 indexSetNonempty();
Lasse Reichstein Nielsen 2015/09/11 06:16:57 Maybe also test negative indices.
sra1 2015/09/11 17:33:34 Done.
220 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698