| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Conversions for IDBKey. |
| 6 // |
| 7 // Per http://www.w3.org/TR/IndexedDB/#key-construct |
| 8 // |
| 9 // "A value is said to be a valid key if it is one of the following types: Array |
| 10 // JavaScript objects [ECMA-262], DOMString [WEBIDL], Date [ECMA-262] or float |
| 11 // [WEBIDL]. However Arrays are only valid keys if every item in the array is |
| 12 // defined and is a valid key (i.e. sparse arrays can not be valid keys) and if |
| 13 // the Array doesn't directly or indirectly contain itself. Any non-numeric |
| 14 // properties are ignored, and thus does not affect whether the Array is a valid |
| 15 // key. Additionally, if the value is of type float, it is only a valid key if |
| 16 // it is not NaN, and if the value is of type Date it is only a valid key if its |
| 17 // [[PrimitiveValue]] internal property, as defined by [ECMA-262], is not NaN." |
| 18 |
| 19 // What is required is to ensure that an Lists in the key are actually |
| 20 // JavaScript arrays, and any Dates are JavaScript Dates. |
| 21 |
| 22 /** |
| 23 * Converts a native IDBKey into a Dart object. |
| 24 * |
| 25 * May return the original input. May mutate the original input (but will be |
| 26 * idempotent if mutation occurs). It is assumed that this conversion happens |
| 27 * on native IDBKeys on all paths that return IDBKeys from native DOM calls. |
| 28 * |
| 29 * If necessary, JavaScript Dates are converted into Dart Dates. |
| 30 */ |
| 31 _convertNativeToDart_IDBKey(nativeKey) { |
| 32 // TODO: Implement. |
| 33 // TODO: Cache conversion somewhere. |
| 34 return nativeKey; |
| 35 } |
| 36 |
| 37 /** |
| 38 * Converts a Dart object into a valid IDBKey. |
| 39 * |
| 40 * May return the original input. Does not mutate input. |
| 41 * |
| 42 * If necessary, [dartKey] may be copied to ensure all lists are converted into |
| 43 * JavaScript Arrays and Dart Dates into JavaScript Dates. |
| 44 */ |
| 45 |
| 46 _convertDartToNative_IDBKey(dartKey) { |
| 47 // TODO: Implement. |
| 48 // TODO: Cache conversion on object. |
| 49 return dartKey; |
| 50 } |
| 51 |
| 52 |
| 53 // Conversions for ImageData |
| 54 // |
| 55 // On Firefox, the returned ImageData is a plain object. |
| 56 |
| 57 class _TypedImageData implements ImageData { |
| 58 final Uint8ClampedArray data; |
| 59 final int height; |
| 60 final int width; |
| 61 |
| 62 _TypedImageData(this.data, this.height, this.width); |
| 63 } |
| 64 |
| 65 ImageData _convertNativeToDart_ImageData(nativeImageData) { |
| 66 if (nativeImageData is ImageData) return nativeImageData; |
| 67 |
| 68 // On Firefox the above test fails because imagedata is a plain object. |
| 69 // So we create a _TypedImageData. |
| 70 |
| 71 return new _TypedImageData( |
| 72 JS('var', '#.data', nativeImageData), |
| 73 JS('var', '#.height', nativeImageData), |
| 74 JS('var', '#.width', nativeImageData)); |
| 75 } |
| 76 |
| 77 // We can get rid of this conversion if _TypedImageData implements the fields |
| 78 // with native names. |
| 79 _convertDartToNative_ImageData(ImageData imageData) { |
| 80 if (imageData is _ImageDataImpl) return imageData; |
| 81 return JS('Object', '{data: #, height: #, width: #}', |
| 82 imageData.data, imageData.height, imageData.width); |
| 83 } |
| 84 |
| 85 |
| 86 /// Converts a JavaScript object with properties into a Dart Map. |
| 87 Map _convertNativeToDart_Dictionary(object) { |
| 88 // TODO: Implement. |
| 89 return object; |
| 90 } |
| 91 |
| 92 /// Converts a Dart map into a JavaScript object with properties. |
| 93 _convertDartToNative_Dictionary(Map dict) { |
| 94 // TODO: Implement. |
| 95 return dict; |
| 96 } |
| 97 |
| 98 |
| 99 /** |
| 100 * Ensures that the input is a JavaScript Array. |
| 101 * |
| 102 * Creates a new JavaScript array if necessary, otherwise returns the original. |
| 103 */ |
| 104 List _convertDartToNative_StringArray(List<String> input) { |
| 105 return input; |
| 106 } |
| OLD | NEW |