| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 class MyList<E> extends Object with ListMixin<E> implements List<E> { | 8 class MyList<E> extends Object with ListMixin<E> implements List<E> { |
| 9 List<E> _list; | 9 List<E> _list; |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 class MyNoSuchMethodList<E> extends Object | 26 class MyNoSuchMethodList<E> extends Object |
| 27 with ListMixin<E> | 27 with ListMixin<E> |
| 28 implements List<E> { | 28 implements List<E> { |
| 29 List<E> _list; | 29 List<E> _list; |
| 30 | 30 |
| 31 MyNoSuchMethodList(List<E> this._list); | 31 MyNoSuchMethodList(List<E> this._list); |
| 32 | 32 |
| 33 noSuchMethod(Invocation invocation) { | 33 noSuchMethod(Invocation invocation) { |
| 34 if (invocation.memberName == #length) { | 34 if (invocation.memberName == #length && invocation.isGetter) { |
| 35 if (invocation.isGetter) return _list.length; | 35 return _list.length; |
| 36 if (invocation.isSetter) { | 36 } |
| 37 _list.length = invocation.positionalArguments.first; | 37 if (invocation.memberName == new Symbol("length=") && invocation.isSetter) { |
| 38 return null; | 38 _list.length = invocation.positionalArguments.first; |
| 39 } | 39 return null; |
| 40 return super.noSuchMethod(invocation); | |
| 41 } | 40 } |
| 42 if (invocation.memberName == new Symbol("[]") && | 41 if (invocation.memberName == new Symbol("[]") && |
| 43 invocation.positionalArguments.length == 1) { | 42 invocation.positionalArguments.length == 1) { |
| 44 return _list[invocation.positionalArguments.first]; | 43 return _list[invocation.positionalArguments.first]; |
| 45 } | 44 } |
| 46 if (invocation.memberName == new Symbol("[]=") && | 45 if (invocation.memberName == new Symbol("[]=") && |
| 47 invocation.positionalArguments.length == 2) { | 46 invocation.positionalArguments.length == 2) { |
| 48 _list[invocation.positionalArguments.first] = | 47 _list[invocation.positionalArguments.first] = |
| 49 invocation.positionalArguments[1]; | 48 invocation.positionalArguments[1]; |
| 50 return null; | 49 return null; |
| 51 } | 50 } |
| 52 return super.noSuchMethod(invocation); | 51 return super.noSuchMethod(invocation); |
| 53 } | 52 } |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Class that behaves like a list but does not implement List. | 55 // Class that behaves like a list but does not implement List. |
| 57 class MyIndexableNoSuchMethod<E> { | 56 class MyIndexableNoSuchMethod<E> { |
| 58 List<E> _list; | 57 List<E> _list; |
| 59 | 58 |
| 60 MyIndexableNoSuchMethod(List<E> this._list); | 59 MyIndexableNoSuchMethod(List<E> this._list); |
| 61 | 60 |
| 62 noSuchMethod(Invocation invocation) { | 61 noSuchMethod(Invocation invocation) { |
| 63 if (invocation.memberName == #length) { | 62 if (invocation.memberName == #length && invocation.isGetter) { |
| 64 if (invocation.isGetter) return _list.length; | 63 return _list.length; |
| 65 if (invocation.isSetter) { | 64 } |
| 66 _list.length = invocation.positionalArguments.first; | 65 if (invocation.memberName == new Symbol("length=") && invocation.isSetter) { |
| 67 return null; | 66 _list.length = invocation.positionalArguments.first; |
| 68 } | 67 return null; |
| 69 return super.noSuchMethod(invocation); | |
| 70 } | 68 } |
| 71 if (invocation.memberName == new Symbol("prototype")) { | 69 if (invocation.memberName == new Symbol("prototype")) { |
| 72 return 42; | 70 return 42; |
| 73 } | 71 } |
| 74 | 72 |
| 75 if (invocation.memberName == new Symbol("[]") && | 73 if (invocation.memberName == new Symbol("[]") && |
| 76 invocation.positionalArguments.length == 1) { | 74 invocation.positionalArguments.length == 1) { |
| 77 return _list[invocation.positionalArguments.first]; | 75 return _list[invocation.positionalArguments.first]; |
| 78 } | 76 } |
| 79 if (invocation.memberName == new Symbol("[]=") && | 77 if (invocation.memberName == new Symbol("[]=") && |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 Expect.equals(3, indexable[2]); | 144 Expect.equals(3, indexable[2]); |
| 147 indexable.length = 2; | 145 indexable.length = 2; |
| 148 Expect.equals(2, indexable.length); | 146 Expect.equals(2, indexable.length); |
| 149 Expect.equals(42, indexable.prototype); | 147 Expect.equals(42, indexable.prototype); |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 void main() { | 151 void main() { |
| 154 testRetainWhere(); | 152 testRetainWhere(); |
| 155 } | 153 } |
| OLD | NEW |