| OLD | NEW |
| (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 // Check that indexed access to lists throws correct exception if index | |
| 8 // is not int. | |
| 9 | |
| 10 main() { | |
| 11 checkList(new List(10)); | |
| 12 var growable = new List(); | |
| 13 growable.add(1); | |
| 14 growable.add(1); | |
| 15 checkList(growable); | |
| 16 } | |
| 17 | |
| 18 checkList(var list) { | |
| 19 // Check unoptimized. | |
| 20 Expect.isFalse(checkCatch(getIt, list, 1)); | |
| 21 Expect.isTrue(checkCatch(getIt, list, "hi")); | |
| 22 Expect.isFalse(checkCatch(putIt, list, 1)); | |
| 23 Expect.isTrue(checkCatch(putIt, list, "hi")); | |
| 24 // Optimize 'getIt' and 'putIt'. | |
| 25 for (int i = 0; i < 2000; i++) { | |
| 26 putIt(list, 1); | |
| 27 getIt(list, 1); | |
| 28 } | |
| 29 Expect.isTrue(checkCatch(getIt, list, "hi")); | |
| 30 Expect.isTrue(checkCatch(putIt, list, "hi")); | |
| 31 } | |
| 32 | |
| 33 checkCatch(var f, var list, var index) { | |
| 34 try { | |
| 35 f(list, index); | |
| 36 } on ArgumentError catch (e) { | |
| 37 return true; | |
| 38 } on TypeError catch (t) { | |
| 39 return true; // thrown in type checked mode. | |
| 40 } | |
| 41 return false; | |
| 42 } | |
| 43 | |
| 44 getIt(var a, var i) { | |
| 45 return a[i]; | |
| 46 } | |
| 47 | |
| 48 putIt(var a, var i) { | |
| 49 a[i] = null; | |
| 50 } | |
| OLD | NEW |