| 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 | 5 |
| 6 // Conversions for IDBKey. | 6 // Conversions for IDBKey. |
| 7 // | 7 // |
| 8 // Per http://www.w3.org/TR/IndexedDB/#key-construct | 8 // Per http://www.w3.org/TR/IndexedDB/#key-construct |
| 9 // | 9 // |
| 10 // "A value is said to be a valid key if it is one of the following types: Array | 10 // "A value is said to be a valid key if it is one of the following types: Array |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 if (copy != null) { | 166 if (copy != null) { |
| 167 if (true == copy) { // Cycle, so commit to making a copy. | 167 if (true == copy) { // Cycle, so commit to making a copy. |
| 168 copy = JS('=List', 'new Array(#)', length); | 168 copy = JS('=List', 'new Array(#)', length); |
| 169 writeSlot(slot, copy); | 169 writeSlot(slot, copy); |
| 170 } | 170 } |
| 171 return copy; | 171 return copy; |
| 172 } | 172 } |
| 173 | 173 |
| 174 int i = 0; | 174 int i = 0; |
| 175 | 175 |
| 176 if (isJavaScriptArray(e) && | 176 // Always clone the list, as it may have non-native properties or methods |
| 177 // We have to copy immutable lists, otherwise the structured clone | 177 // from interceptors and such. |
| 178 // algorithm will copy the .immutable$list marker property, making the | 178 copy = JS('=List', 'new Array(#)', length); |
| 179 // list immutable when received! | 179 writeSlot(slot, copy); |
| 180 !isImmutableJavaScriptArray(e)) { | |
| 181 writeSlot(slot, true); // Deferred copy. | |
| 182 for ( ; i < length; i++) { | |
| 183 var element = e[i]; | |
| 184 var elementCopy = walk(element); | |
| 185 if (!identical(elementCopy, element)) { | |
| 186 copy = readSlot(slot); // Cyclic reference may have created it. | |
| 187 if (true == copy) { | |
| 188 copy = JS('=List', 'new Array(#)', length); | |
| 189 writeSlot(slot, copy); | |
| 190 } | |
| 191 for (int j = 0; j < i; j++) { | |
| 192 copy[j] = e[j]; | |
| 193 } | |
| 194 copy[i] = elementCopy; | |
| 195 i++; | |
| 196 break; | |
| 197 } | |
| 198 } | |
| 199 if (copy == null) { | |
| 200 copy = e; | |
| 201 writeSlot(slot, copy); | |
| 202 } | |
| 203 } else { | |
| 204 // Not a JavaScript Array. We are forced to make a copy. | |
| 205 copy = JS('=List', 'new Array(#)', length); | |
| 206 writeSlot(slot, copy); | |
| 207 } | |
| 208 | 180 |
| 209 for ( ; i < length; i++) { | 181 for ( ; i < length; i++) { |
| 210 copy[i] = walk(e[i]); | 182 copy[i] = walk(e[i]); |
| 211 } | 183 } |
| 212 return copy; | 184 return copy; |
| 213 } | 185 } |
| 214 | 186 |
| 215 throw new UnimplementedError('structured clone of other type'); | 187 throw new UnimplementedError('structured clone of other type'); |
| 216 } | 188 } |
| 217 | 189 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 const String _serializedScriptValue = | 343 const String _serializedScriptValue = |
| 372 'num|String|bool|' | 344 'num|String|bool|' |
| 373 '=List|=Object|' | 345 '=List|=Object|' |
| 374 'Blob|File|ByteBuffer|TypedData' | 346 'Blob|File|ByteBuffer|TypedData' |
| 375 // TODO(sra): Add Date, RegExp. | 347 // TODO(sra): Add Date, RegExp. |
| 376 ; | 348 ; |
| 377 const annotation_Creates_SerializedScriptValue = | 349 const annotation_Creates_SerializedScriptValue = |
| 378 const Creates(_serializedScriptValue); | 350 const Creates(_serializedScriptValue); |
| 379 const annotation_Returns_SerializedScriptValue = | 351 const annotation_Returns_SerializedScriptValue = |
| 380 const Returns(_serializedScriptValue); | 352 const Returns(_serializedScriptValue); |
| OLD | NEW |