| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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 for the evaluation order of getters and setters. |
| 6 |
| 7 var trace; |
| 8 |
| 9 class X { |
| 10 get b { |
| 11 trace.add('get b'); |
| 12 return new X(); |
| 13 } |
| 14 |
| 15 set c (value) { |
| 16 trace.add('set c'); |
| 17 } |
| 18 |
| 19 toString() { |
| 20 trace.add('toString'); |
| 21 return 'X'; |
| 22 } |
| 23 |
| 24 get c { |
| 25 trace.add('get c'); |
| 26 return 42; |
| 27 } |
| 28 |
| 29 get d { |
| 30 trace.add('get d'); |
| 31 return new X(); |
| 32 } |
| 33 |
| 34 operator [] (index) { |
| 35 trace.add('index'); |
| 36 return 42; |
| 37 } |
| 38 |
| 39 operator []=(index, value) { |
| 40 trace.add('indexSet'); |
| 41 } |
| 42 } |
| 43 |
| 44 main() { |
| 45 var x = new X(); |
| 46 |
| 47 trace = []; |
| 48 x.b.c = '$x'; |
| 49 Expect.listEquals(['get b', 'toString', 'set c'], trace); |
| 50 |
| 51 trace = []; |
| 52 x.b.c += '$x'.hashCode; |
| 53 Expect.listEquals(['get b', 'get c', 'toString', 'set c'], trace); |
| 54 |
| 55 trace = []; |
| 56 x.b.c++; |
| 57 Expect.listEquals(['get b', 'get c', 'set c'], trace); |
| 58 |
| 59 trace = []; |
| 60 x.b.d[42] = '$x'; |
| 61 Expect.listEquals(['get b', 'get d', 'toString', 'indexSet'], trace); |
| 62 |
| 63 trace = []; |
| 64 x.b.d[42] += '$x'.hashCode; |
| 65 Expect.listEquals(['get b', 'get d', 'index', 'toString', 'indexSet'], trace); |
| 66 |
| 67 trace = []; |
| 68 x.b.d[42]++; |
| 69 Expect.listEquals(['get b', 'get d', 'index', 'indexSet'], trace); |
| 70 |
| 71 trace = []; |
| 72 ++x.b.d[42]; |
| 73 Expect.listEquals(['get b', 'get d', 'index', 'indexSet'], trace); |
| 74 |
| 75 trace = []; |
| 76 x.b.d[x.c] *= '$x'.hashCode; |
| 77 Expect.listEquals( |
| 78 ['get b', 'get d', 'get c', 'index', 'toString', 'indexSet'], trace); |
| 79 |
| 80 trace = []; |
| 81 x.b.c = x.d.c = '$x'; |
| 82 Expect.listEquals(['get b', 'get d', 'toString', 'set c', 'set c',], trace); |
| 83 |
| 84 trace = []; |
| 85 x.b.c = x.d[42] *= '$x'.hashCode; |
| 86 Expect.listEquals( |
| 87 ['get b', 'get d', 'index', 'toString', 'indexSet', 'set c'], trace); |
| 88 |
| 89 trace = []; |
| 90 x.b.c = ++x.d.c; |
| 91 Expect.listEquals(['get b', 'get d', 'get c', 'set c', 'set c'], trace); |
| 92 } |
| OLD | NEW |