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

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

Issue 1275703002: - Prevent getting an unmodifiable list being returned from List.from. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | 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) 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 // The _GrowableArrayMarker class is used to signal to the List() factory 5 // The _GrowableArrayMarker class is used to signal to the List() factory
6 // whether a parameter was passed. 6 // whether a parameter was passed.
7 class _GrowableArrayMarker implements int { 7 class _GrowableArrayMarker implements int {
8 const _GrowableArrayMarker(); 8 const _GrowableArrayMarker();
9 } 9 }
10 10
(...skipping 27 matching lines...) Expand all
38 var list = growable ? new _GrowableList<E>(length) : new _List<E>(length); 38 var list = growable ? new _GrowableList<E>(length) : new _List<E>(length);
39 int i = 0; 39 int i = 0;
40 for (var element in elements) { list[i++] = element; } 40 for (var element in elements) { list[i++] = element; }
41 return list; 41 return list;
42 } 42 }
43 List<E> list = new _GrowableList<E>(0); 43 List<E> list = new _GrowableList<E>(0);
44 for (E e in elements) { 44 for (E e in elements) {
45 list.add(e); 45 list.add(e);
46 } 46 }
47 if (growable) return list; 47 if (growable) return list;
48 if (list.length == 0) {
49 // Avoid getting an immutable list from makeListFixedLength.
50 return new List<E>(0);
51 }
48 return makeListFixedLength(list); 52 return makeListFixedLength(list);
49 } 53 }
50 54
51 /* patch */ factory List.unmodifiable(Iterable elements) { 55 /* patch */ factory List.unmodifiable(Iterable elements) {
52 List result = new List<E>.from(elements, growable: false); 56 List result = new List<E>.from(elements, growable: false);
53 return makeFixedListUnmodifiable(result); 57 return makeFixedListUnmodifiable(result);
54 } 58 }
55 59
56 // Factory constructing a mutable List from a parser generated List literal. 60 // Factory constructing a mutable List from a parser generated List literal.
57 // [elements] contains elements that are already type checked. 61 // [elements] contains elements that are already type checked.
58 factory List._fromLiteral(List elements) { 62 factory List._fromLiteral(List elements) {
59 if (elements.isEmpty) { 63 if (elements.isEmpty) {
60 return new _GrowableList<E>(0); 64 return new _GrowableList<E>(0);
61 } 65 }
62 var result = new _GrowableList<E>.withData(elements); 66 var result = new _GrowableList<E>.withData(elements);
63 result._setLength(elements.length); 67 result._setLength(elements.length);
64 return result; 68 return result;
65 } 69 }
66 } 70 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698