| 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 // Conversions for IDBKey. | 5 // Conversions for IDBKey. |
| 6 // | 6 // |
| 7 // Per http://www.w3.org/TR/IndexedDB/#key-construct | 7 // Per http://www.w3.org/TR/IndexedDB/#key-construct |
| 8 // | 8 // |
| 9 // "A value is said to be a valid key if it is one of the following types: Array | 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 | 10 // JavaScript objects [ECMA-262], DOMString [WEBIDL], Date [ECMA-262] or float |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // We can get rid of this conversion if _TypedImageData implements the fields | 77 // We can get rid of this conversion if _TypedImageData implements the fields |
| 78 // with native names. | 78 // with native names. |
| 79 _convertDartToNative_ImageData(ImageData imageData) { | 79 _convertDartToNative_ImageData(ImageData imageData) { |
| 80 if (imageData is _ImageDataImpl) return imageData; | 80 if (imageData is _ImageDataImpl) return imageData; |
| 81 return JS('Object', '{data: #, height: #, width: #}', | 81 return JS('Object', '{data: #, height: #, width: #}', |
| 82 imageData.data, imageData.height, imageData.width); | 82 imageData.data, imageData.height, imageData.width); |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 /// Converts a JavaScript object with properties into a Dart Map. | 86 /// Converts a JavaScript object with properties into a Dart Map. |
| 87 /// Not suitable for nested objects. |
| 87 Map _convertNativeToDart_Dictionary(object) { | 88 Map _convertNativeToDart_Dictionary(object) { |
| 88 // TODO: Implement. | 89 // TODO: Implement. |
| 90 var dict = {}; |
| 91 for (final key in JS('List', 'Object.getOwnPropertyNames(#)', object)) { |
| 92 dict[key] = JS('var', '#[#]', object, key); |
| 93 } |
| 94 return dict; |
| 95 } |
| 96 |
| 97 /// Converts a flat Dart map into a JavaScript object with properties. |
| 98 _convertDartToNative_Dictionary(Map dict) { |
| 99 var object = JS('var', '{}'); |
| 100 dict.forEach((String key, value) { |
| 101 JS('void', '#[#] = #', object, key, value); |
| 102 }); |
| 89 return object; | 103 return object; |
| 90 } | 104 } |
| 91 | 105 |
| 92 /// Converts a Dart map into a JavaScript object with properties. | |
| 93 _convertDartToNative_Dictionary(Map dict) { | |
| 94 // TODO: Implement. | |
| 95 return dict; | |
| 96 } | |
| 97 | 106 |
| 98 | |
| 99 /** | 107 /** |
| 100 * Ensures that the input is a JavaScript Array. | 108 * Ensures that the input is a JavaScript Array. |
| 101 * | 109 * |
| 102 * Creates a new JavaScript array if necessary, otherwise returns the original. | 110 * Creates a new JavaScript array if necessary, otherwise returns the original. |
| 103 */ | 111 */ |
| 104 List _convertDartToNative_StringArray(List<String> input) { | 112 List _convertDartToNative_StringArray(List<String> input) { |
| 105 return input; | 113 return input; |
| 106 } | 114 } |
| OLD | NEW |