Chromium Code Reviews| 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 } | |
|
sra1
2013/03/26 21:45:58
Add some more complex compound assignments
x.b.d[
ngeoffray
2013/03/28 11:31:03
Done.
| |
| OLD | NEW |