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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 // We can get rid of this conversion if _TypedImageData implements the fields | 86 // We can get rid of this conversion if _TypedImageData implements the fields |
87 // with native names. | 87 // with native names. |
88 _convertDartToNative_ImageData(ImageData imageData) { | 88 _convertDartToNative_ImageData(ImageData imageData) { |
89 if (imageData is _TypedImageData) { | 89 if (imageData is _TypedImageData) { |
90 return JS('', '{data: #, height: #, width: #}', | 90 return JS('', '{data: #, height: #, width: #}', |
91 imageData.data, imageData.height, imageData.width); | 91 imageData.data, imageData.height, imageData.width); |
92 } | 92 } |
93 return imageData; | 93 return imageData; |
94 } | 94 } |
95 | |
96 | |
97 // ----------------------------------------------------------------------------- | |
98 | |
99 /** | |
100 * Converts a native IDBKey into a Dart object. | |
sra1
2012/12/04 20:26:24
Move the comment at the top of the file too.
| |
101 * | |
102 * May return the original input. May mutate the original input (but will be | |
103 * idempotent if mutation occurs). It is assumed that this conversion happens | |
104 * on native IDBKeys on all paths that return IDBKeys from native DOM calls. | |
105 * | |
106 * If necessary, JavaScript Dates are converted into Dart Dates. | |
107 */ | |
108 _convertNativeToDart_IDBKey(nativeKey) { | |
109 containsDate(object) { | |
110 if (isJavaScriptDate(object)) return true; | |
111 if (object is List) { | |
112 for (int i = 0; i < object.length; i++) { | |
113 if (containsDate(object[i])) return true; | |
114 } | |
115 } | |
116 return false; // number, string. | |
117 } | |
118 if (containsDate(nativeKey)) { | |
119 throw new UnimplementedError('IDBKey containing Date'); | |
120 } | |
121 // TODO: Cache conversion somewhere? | |
122 return nativeKey; | |
123 } | |
124 | |
125 /** | |
126 * Converts a Dart object into a valid IDBKey. | |
127 * | |
128 * May return the original input. Does not mutate input. | |
129 * | |
130 * If necessary, [dartKey] may be copied to ensure all lists are converted into | |
131 * JavaScript Arrays and Dart Dates into JavaScript Dates. | |
132 */ | |
133 _convertDartToNative_IDBKey(dartKey) { | |
134 // TODO: Implement. | |
135 return dartKey; | |
136 } | |
137 | |
138 | |
139 | |
140 /// May modify original. If so, action is idempotent. | |
141 _convertNativeToDart_IDBAny(object) { | |
142 return convertNativeToDart_AcceptStructuredClone(object, mustCopy: false); | |
143 } | |
144 | |
145 | |
146 const String _idbKey = '=List|=Object|num|String'; // TODO(sra): Add Date. | |
147 const _annotation_Creates_IDBKey = const Creates(_idbKey); | |
148 const _annotation_Returns_IDBKey = const Returns(_idbKey); | |
OLD | NEW |