| OLD | NEW |
| 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 // Mocks of things that Leg cannot read directly. | 5 // Mocks of things that Leg cannot read directly. |
| 6 | 6 |
| 7 // TODO(ahe): Remove this file. | 7 // TODO(ahe): Remove this file. |
| 8 | 8 |
| 9 class AssertionError {} | 9 class AssertionError {} |
| 10 class TypeError extends AssertionError { | 10 class TypeError extends AssertionError { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 factory Uint8List(int length) { | 57 factory Uint8List(int length) { |
| 58 throw new UnsupportedOperationException("new Uint8List($length)"); | 58 throw new UnsupportedOperationException("new Uint8List($length)"); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // TODO(ahe): This definitely does not belong in the core library. | 62 // TODO(ahe): This definitely does not belong in the core library. |
| 63 void exit(int exitCode) { | 63 void exit(int exitCode) { |
| 64 throw new UnsupportedOperationException("exit($exitCode)"); | 64 throw new UnsupportedOperationException("exit($exitCode)"); |
| 65 } | 65 } |
| 66 | 66 |
| 67 class _Expando<T> implements Expando<T> { | |
| 68 | |
| 69 final String name; | |
| 70 | |
| 71 const _Expando([this.name]); | |
| 72 | |
| 73 T operator[](Object object) { | |
| 74 var values = Primitives.getProperty(object, EXPANDO_PROPERTY_NAME); | |
| 75 return (values === null) ? null : Primitives.getProperty(values, _getKey()); | |
| 76 } | |
| 77 | |
| 78 void operator[]=(Object object, T value) { | |
| 79 var values = Primitives.getProperty(object, EXPANDO_PROPERTY_NAME); | |
| 80 if (values === null) { | |
| 81 values = new Object(); | |
| 82 Primitives.setProperty(object, EXPANDO_PROPERTY_NAME, values); | |
| 83 } | |
| 84 Primitives.setProperty(values, _getKey(), value); | |
| 85 } | |
| 86 | |
| 87 String toString() { | |
| 88 String key = _getKey(); | |
| 89 return (name === null) ? "Expando:${key}" : "Expando:${name}@${key}"; | |
| 90 } | |
| 91 | |
| 92 String _getKey() { | |
| 93 String key = Primitives.getProperty(this, KEY_PROPERTY_NAME); | |
| 94 if (key === null) { | |
| 95 key = "expando\$key\$${keyCount++}"; | |
| 96 Primitives.setProperty(this, KEY_PROPERTY_NAME, key); | |
| 97 } | |
| 98 return key; | |
| 99 } | |
| 100 | |
| 101 static final String KEY_PROPERTY_NAME = 'expando\$key'; | |
| 102 static final String EXPANDO_PROPERTY_NAME = 'expando\$values'; | |
| 103 static int keyCount = 0; | |
| 104 | |
| 105 } | |
| OLD | NEW |