| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 */ | 192 */ |
| 193 _convertDartToNative_PrepareForStructuredClone(value) { | 193 _convertDartToNative_PrepareForStructuredClone(value) { |
| 194 | 194 |
| 195 // TODO(sra): Replace slots with identity hash table. | 195 // TODO(sra): Replace slots with identity hash table. |
| 196 var values = []; | 196 var values = []; |
| 197 var copies = []; // initially 'null', 'true' during initial DFS, then a copy. | 197 var copies = []; // initially 'null', 'true' during initial DFS, then a copy. |
| 198 | 198 |
| 199 int findSlot(value) { | 199 int findSlot(value) { |
| 200 int length = values.length; | 200 int length = values.length; |
| 201 for (int i = 0; i < length; i++) { | 201 for (int i = 0; i < length; i++) { |
| 202 if (values[i] === value) return i; | 202 if (identical(values[i], value)) return i; |
| 203 } | 203 } |
| 204 values.add(value); | 204 values.add(value); |
| 205 copies.add(null); | 205 copies.add(null); |
| 206 return length; | 206 return length; |
| 207 } | 207 } |
| 208 readSlot(int i) => copies[i]; | 208 readSlot(int i) => copies[i]; |
| 209 writeSlot(int i, x) { copies[i] = x; } | 209 writeSlot(int i, x) { copies[i] = x; } |
| 210 cleanupSlots() {} // Will be needed if we mark objects with a property. | 210 cleanupSlots() {} // Will be needed if we mark objects with a property. |
| 211 | 211 |
| 212 // Returns the input, or a clone of the input. | 212 // Returns the input, or a clone of the input. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 if (_isJavaScriptArray(e) && | 292 if (_isJavaScriptArray(e) && |
| 293 // We have to copy immutable lists, otherwise the structured clone | 293 // We have to copy immutable lists, otherwise the structured clone |
| 294 // algorithm will copy the .immutable$list marker property, making the | 294 // algorithm will copy the .immutable$list marker property, making the |
| 295 // list immutable when received! | 295 // list immutable when received! |
| 296 !_isImmutableJavaScriptArray(e)) { | 296 !_isImmutableJavaScriptArray(e)) { |
| 297 writeSlot(slot, true); // Deferred copy. | 297 writeSlot(slot, true); // Deferred copy. |
| 298 for ( ; i < length; i++) { | 298 for ( ; i < length; i++) { |
| 299 var element = e[i]; | 299 var element = e[i]; |
| 300 var elementCopy = walk(element); | 300 var elementCopy = walk(element); |
| 301 if (elementCopy !== element) { | 301 if (!identical(elementCopy, element)) { |
| 302 copy = readSlot(slot); // Cyclic reference may have created it. | 302 copy = readSlot(slot); // Cyclic reference may have created it. |
| 303 if (true == copy) { | 303 if (true == copy) { |
| 304 copy = JS('List', 'new Array(#)', length); | 304 copy = JS('List', 'new Array(#)', length); |
| 305 writeSlot(slot, copy); | 305 writeSlot(slot, copy); |
| 306 } | 306 } |
| 307 for (int j = 0; j < i; j++) { | 307 for (int j = 0; j < i; j++) { |
| 308 copy[j] = e[j]; | 308 copy[j] = e[j]; |
| 309 } | 309 } |
| 310 copy[i] = elementCopy; | 310 copy[i] = elementCopy; |
| 311 i++; | 311 i++; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 _convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) { | 357 _convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) { |
| 358 | 358 |
| 359 // TODO(sra): Replace slots with identity hash table that works on non-dart | 359 // TODO(sra): Replace slots with identity hash table that works on non-dart |
| 360 // objects. | 360 // objects. |
| 361 var values = []; | 361 var values = []; |
| 362 var copies = []; | 362 var copies = []; |
| 363 | 363 |
| 364 int findSlot(value) { | 364 int findSlot(value) { |
| 365 int length = values.length; | 365 int length = values.length; |
| 366 for (int i = 0; i < length; i++) { | 366 for (int i = 0; i < length; i++) { |
| 367 if (values[i] === value) return i; | 367 if (identical(values[i], value)) return i; |
| 368 } | 368 } |
| 369 values.add(value); | 369 values.add(value); |
| 370 copies.add(null); | 370 copies.add(null); |
| 371 return length; | 371 return length; |
| 372 } | 372 } |
| 373 readSlot(int i) => copies[i]; | 373 readSlot(int i) => copies[i]; |
| 374 writeSlot(int i, x) { copies[i] = x; } | 374 writeSlot(int i, x) { copies[i] = x; } |
| 375 | 375 |
| 376 walk(e) { | 376 walk(e) { |
| 377 if (e == null) return e; | 377 if (e == null) return e; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 431 } |
| 432 | 432 |
| 433 | 433 |
| 434 bool _isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); | 434 bool _isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); |
| 435 bool _isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); | 435 bool _isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); |
| 436 bool _isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); | 436 bool _isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); |
| 437 bool _isJavaScriptSimpleObject(value) => | 437 bool _isJavaScriptSimpleObject(value) => |
| 438 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); | 438 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); |
| 439 bool _isImmutableJavaScriptArray(value) => | 439 bool _isImmutableJavaScriptArray(value) => |
| 440 JS('bool', r'!!(#.immutable$list)', value); | 440 JS('bool', r'!!(#.immutable$list)', value); |
| OLD | NEW |