| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 /** | 55 /** |
| 56 * Ensures that the input is a JavaScript Array. | 56 * Ensures that the input is a JavaScript Array. |
| 57 * | 57 * |
| 58 * Creates a new JavaScript array if necessary, otherwise returns the original. | 58 * Creates a new JavaScript array if necessary, otherwise returns the original. |
| 59 */ | 59 */ |
| 60 List convertDartToNative_StringArray(List<String> input) { | 60 List convertDartToNative_StringArray(List<String> input) { |
| 61 // TODO(sra). Implement this. | 61 // TODO(sra). Implement this. |
| 62 return input; | 62 return input; |
| 63 } | 63 } |
| 64 | 64 |
| 65 DateTime convertNativeToDart_DateTime(date) { |
| 66 var millisSinceEpoch = JS('int', '#.getTime()', date); |
| 67 return new DateTime.fromMillisecondsSinceEpoch(millisSinceEpoch, isUtc: true); |
| 68 } |
| 69 |
| 70 convertDartToNative_DateTime(DateTime date) { |
| 71 return JS('', 'new Date(#)', date.millisecondsSinceEpoch); |
| 72 } |
| 73 |
| 65 | 74 |
| 66 // ----------------------------------------------------------------------------- | 75 // ----------------------------------------------------------------------------- |
| 67 | 76 |
| 68 /// Converts a Dart value into a JavaScript SerializedScriptValue. | 77 /// Converts a Dart value into a JavaScript SerializedScriptValue. |
| 69 convertDartToNative_SerializedScriptValue(value) { | 78 convertDartToNative_SerializedScriptValue(value) { |
| 70 return _convertDartToNative_PrepareForStructuredClone(value); | 79 return _convertDartToNative_PrepareForStructuredClone(value); |
| 71 } | 80 } |
| 72 | 81 |
| 73 /// Since the source object may be viewed via a JavaScript event listener the | 82 /// Since the source object may be viewed via a JavaScript event listener the |
| 74 /// original may not be modified. | 83 /// original may not be modified. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 writeSlot(int i, x) { copies[i] = x; } | 121 writeSlot(int i, x) { copies[i] = x; } |
| 113 cleanupSlots() {} // Will be needed if we mark objects with a property. | 122 cleanupSlots() {} // Will be needed if we mark objects with a property. |
| 114 | 123 |
| 115 // Returns the input, or a clone of the input. | 124 // Returns the input, or a clone of the input. |
| 116 walk(e) { | 125 walk(e) { |
| 117 if (e == null) return e; | 126 if (e == null) return e; |
| 118 if (e is bool) return e; | 127 if (e is bool) return e; |
| 119 if (e is num) return e; | 128 if (e is num) return e; |
| 120 if (e is String) return e; | 129 if (e is String) return e; |
| 121 if (e is DateTime) { | 130 if (e is DateTime) { |
| 122 // TODO(sra). | 131 return convertDartToNative_DateTime(e); |
| 123 throw new UnimplementedError('structured clone of DateTime'); | |
| 124 } | 132 } |
| 125 if (e is RegExp) { | 133 if (e is RegExp) { |
| 126 // TODO(sra). | 134 // TODO(sra). |
| 127 throw new UnimplementedError('structured clone of RegExp'); | 135 throw new UnimplementedError('structured clone of RegExp'); |
| 128 } | 136 } |
| 129 | 137 |
| 130 // The browser's internal structured cloning algorithm will copy certain | 138 // The browser's internal structured cloning algorithm will copy certain |
| 131 // types of object, but it will copy only its own implementations and not | 139 // types of object, but it will copy only its own implementations and not |
| 132 // just any Dart implementations of the interface. | 140 // just any Dart implementations of the interface. |
| 133 | 141 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 readSlot(int i) => copies[i]; | 238 readSlot(int i) => copies[i]; |
| 231 writeSlot(int i, x) { copies[i] = x; } | 239 writeSlot(int i, x) { copies[i] = x; } |
| 232 | 240 |
| 233 walk(e) { | 241 walk(e) { |
| 234 if (e == null) return e; | 242 if (e == null) return e; |
| 235 if (e is bool) return e; | 243 if (e is bool) return e; |
| 236 if (e is num) return e; | 244 if (e is num) return e; |
| 237 if (e is String) return e; | 245 if (e is String) return e; |
| 238 | 246 |
| 239 if (isJavaScriptDate(e)) { | 247 if (isJavaScriptDate(e)) { |
| 240 // TODO(sra). | 248 return convertNativeToDart_DateTime(e); |
| 241 throw new UnimplementedError('structured clone of DateTime'); | |
| 242 } | 249 } |
| 243 | 250 |
| 244 if (isJavaScriptRegExp(e)) { | 251 if (isJavaScriptRegExp(e)) { |
| 245 // TODO(sra). | 252 // TODO(sra). |
| 246 throw new UnimplementedError('structured clone of RegExp'); | 253 throw new UnimplementedError('structured clone of RegExp'); |
| 247 } | 254 } |
| 248 | 255 |
| 249 if (isJavaScriptSimpleObject(e)) { | 256 if (isJavaScriptSimpleObject(e)) { |
| 250 // TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map | 257 // TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map |
| 251 // implementation that uses the properies as storage. | 258 // implementation that uses the properies as storage. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 const String _serializedScriptValue = | 351 const String _serializedScriptValue = |
| 345 'num|String|bool|' | 352 'num|String|bool|' |
| 346 'JSExtendableArray|=Object|' | 353 'JSExtendableArray|=Object|' |
| 347 'Blob|File|ByteBuffer|TypedData' | 354 'Blob|File|ByteBuffer|TypedData' |
| 348 // TODO(sra): Add Date, RegExp. | 355 // TODO(sra): Add Date, RegExp. |
| 349 ; | 356 ; |
| 350 const annotation_Creates_SerializedScriptValue = | 357 const annotation_Creates_SerializedScriptValue = |
| 351 const Creates(_serializedScriptValue); | 358 const Creates(_serializedScriptValue); |
| 352 const annotation_Returns_SerializedScriptValue = | 359 const annotation_Returns_SerializedScriptValue = |
| 353 const Returns(_serializedScriptValue); | 360 const Returns(_serializedScriptValue); |
| OLD | NEW |