Chromium Code Reviews| 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 | |
| 54 // Conversions for ImageData | |
| 55 // | |
| 56 // On Firefox, the returned ImageData is a plain object. | |
| 57 | |
| 58 class FakeImageData implements ImageData { | |
|
vsm
2012/08/22 18:49:36
Nit: I'd use a different name than 'Fake'. E.g.,
| |
| 59 final Uint8ClampedArray data; | |
| 60 final int height; | |
| 61 final int width; | |
| 62 | |
| 63 FakeImageData._internal(this.data, this.height, this.width); | |
| 64 } | |
| 65 | |
| 66 ImageData _convertNativeToDart_ImageData(Object nativeImageData) { | |
| 67 if (nativeImageData is ImageData) return nativeImageData; | |
| 68 | |
| 69 // On Firefox the above test fails because imagedata is a plain object. | |
| 70 // So we create a FakeImageData. | |
| 71 | |
| 72 return new FakeImageData._internal( | |
| 73 JS('var', '#.data', nativeImageData), | |
| 74 JS('var', '#.height', nativeImageData), | |
| 75 JS('var', '#.width', nativeImageData)); | |
| 76 } | |
| 77 | |
| 78 Object _convertDartToNative_ImageData(ImageData imageData) { | |
| 79 if (imageData is _ImageDataImpl) return imageData; | |
| 80 | |
| 81 // We can get rid of this conversion if FakeImageData implements the fields | |
| 82 // with native names. | |
| 83 return JS('Object', '{data: #, height: #, width: #}', | |
| 84 imageData.data, imageData.height, imageData.width); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 /// Converts a JavaScript object with properties into a Dart Map. | |
| 89 Map _convertNativeToDart_Dictionary(Object object) { | |
| 90 // TODO: Implement. | |
| 91 return object; | |
| 92 } | |
| 93 | |
| 94 /// Converts a Dart map into a JavaScript object with properties. | |
| 95 Object _convertDartToNative_Dictionary(Map dict) { | |
| 96 // TODO: Implement. | |
| 97 return dict; | |
| 98 } | |
| 99 | |
| 100 | |
| 101 /** | |
| 102 * Ensures that the input is a JavaScript Array. | |
| 103 * | |
| 104 * Creates a new JavaScript array if necessary, otherwise returns the original. | |
| 105 */ | |
| 106 Object _ensureStringArray(List<String> input) { | |
|
vsm
2012/08/22 18:49:36
Rename to convertDartToNative for consistency?
| |
| 107 } | |
| OLD | NEW |