Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: runtime/lib/array.dart

Issue 8648003: Fix bug 557: Disallow user side allocation of ImmutableArray. Also added "instantiation-checks" f... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/bool.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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 class ListFactory { 5 class ListFactory {
6 6
7 factory List<T>.from(Iterable<T> other) { 7 factory List<T>.from(Iterable<T> other) {
8 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); 8 GrowableObjectArray<T> list = new GrowableObjectArray<T>();
9 for (final e in other) { 9 for (final e in other) {
10 list.add(e); 10 list.add(e);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 // This is essentially the same class as ObjectArray, but it does not 155 // This is essentially the same class as ObjectArray, but it does not
156 // permit any modification of array elements from Dart code. We use 156 // permit any modification of array elements from Dart code. We use
157 // this class for arrays constructed from Dart array literals. 157 // this class for arrays constructed from Dart array literals.
158 // TODO(hausner): We should consider the trade-offs between two 158 // TODO(hausner): We should consider the trade-offs between two
159 // classes (and inline cache misses) versus a field in the native 159 // classes (and inline cache misses) versus a field in the native
160 // implementation (checks when modifying). We should keep watching 160 // implementation (checks when modifying). We should keep watching
161 // the inline cache misses. 161 // the inline cache misses.
162 class ImmutableArray<T> implements List<T> { 162 class ImmutableArray<T> implements List<T> {
163 163
164 factory ImmutableArray._uninstantiable() {
165 throw const UnsupportedOperationException(
166 "ImmutableArray can only be allocated by the VM");
167 }
168
164 T operator [](int index) native "ObjectArray_getIndexed"; 169 T operator [](int index) native "ObjectArray_getIndexed";
165 170
166 void operator []=(int index, T value) { 171 void operator []=(int index, T value) {
167 throw const UnsupportedOperationException( 172 throw const UnsupportedOperationException(
168 "Cannot modify an immutable array"); 173 "Cannot modify an immutable array");
169 } 174 }
170 175
171 int get length() native "ObjectArray_getLength"; 176 int get length() native "ObjectArray_getLength";
172 177
173 void copyFrom(List src, int srcStart, int dstStart, int count) { 178 void copyFrom(List src, int srcStart, int dstStart, int count) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (!hasNext()) { 300 if (!hasNext()) {
296 throw const NoMoreElementsException(); 301 throw const NoMoreElementsException();
297 } 302 }
298 return _array[_pos++]; 303 return _array[_pos++];
299 } 304 }
300 305
301 final List<T> _array; 306 final List<T> _array;
302 final int _length; // Cache array length for faster access. 307 final int _length; // Cache array length for faster access.
303 int _pos; 308 int _pos;
304 } 309 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/bool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698