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

Side by Side Diff: tests/language/optimized_constant_array_string_access_test.dart

Issue 14566020: - Correctly handle negative constant indices when (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | « runtime/vm/intermediate_language_x64.cc ('k') | 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 // Test optimized constant string and constant array access. 7 // Test optimized constant string and constant array access.
8 8
9 int testConstantStringAndIndexCodeUnitAt() { 9 int testConstantStringAndIndexCodeUnitAt() {
10 int test(b) { 10 int test(b) {
11 if (b) return "hest".codeUnitAt(400); 11 if (b) return "hest".codeUnitAt(400);
12 return "hest".codeUnitAt(2); 12 return "hest".codeUnitAt(2);
13 } 13 }
14 14
15 Expect.throws(() => test(true)); 15 Expect.throws(() => test(true));
16 for (int i = 0; i < 10000; i++) test(false); 16 for (int i = 0; i < 10000; i++) test(false);
17 Expect.throws(() => test(true)); 17 Expect.throws(() => test(true));
18 } 18 }
19 19
20 20
21 int testConstantArrayAndIndexAt() { 21 int testConstantArrayAndIndexAt() {
22 int test(b) { 22 int testPositive(b) {
23 var a = const [1,2,3,4]; 23 var a = const [1,2,3,4];
24 if (b) return a[400]; 24 if (b) return a[400];
25 return a[2]; 25 return a[2];
26 } 26 }
27 27
28 Expect.throws(() => test(true)); 28 int testNegative(b) {
29 for (int i = 0; i < 10000; i++) test(false); 29 var a = const [1,2,3,4];
30 Expect.throws(() => test(true)); 30 if (b) return a[-1];
31 return a[2];
32 }
33
34 Expect.throws(() => testPositive(true));
35 for (int i = 0; i < 10000; i++) testPositive(false);
36 Expect.throws(() => testPositive(true));
37
38 Expect.throws(() => testNegative(true));
39 for (int i = 0; i < 10000; i++) testNegative(false);
40 Expect.throws(() => testNegative(true));
31 } 41 }
32 42
33 43
34 foo(a) { 44 foo(a) {
35 if (a == 1) { return 2; } 45 if (a == 1) { return 2; }
36 var aa = const [1, 2]; 46 var aa = const [1, 2];
37 return aa[2.3]; 47 return aa[2.3];
38 } 48 }
39 49
40 50
41 int testNonSmiIndex() { 51 int testNonSmiIndex() {
42 for (int i = 0; i < 10000; i++) { foo(1); } 52 for (int i = 0; i < 10000; i++) { foo(1); }
43 Expect.throws(() => foo(2)); 53 Expect.throws(() => foo(2));
44 } 54 }
45 55
46 56
47 main() { 57 main() {
48 testConstantStringAndIndexCodeUnitAt(); 58 testConstantStringAndIndexCodeUnitAt();
49 testConstantArrayAndIndexAt(); 59 testConstantArrayAndIndexAt();
50 testNonSmiIndex(); 60 testNonSmiIndex();
51 } 61 }
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698