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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 // TODO(sra): The JavaScript objects suitable for direct cloning by the | 142 // TODO(sra): The JavaScript objects suitable for direct cloning by the |
143 // structured clone algorithm could be tagged with an private interface. | 143 // structured clone algorithm could be tagged with an private interface. |
144 | 144 |
145 if (e is File) return e; | 145 if (e is File) return e; |
146 if (e is Blob) return e; | 146 if (e is Blob) return e; |
147 if (e is FileList) return e; | 147 if (e is FileList) return e; |
148 | 148 |
149 // TODO(sra): Firefox: How to convert _TypedImageData on the other end? | 149 // TODO(sra): Firefox: How to convert _TypedImageData on the other end? |
150 if (e is ImageData) return e; | 150 if (e is ImageData) return e; |
151 if (e is NativeByteBuffer) return e; | 151 if (e is ByteBuffer) return e; |
152 | 152 |
153 if (e is NativeTypedData) return e; | 153 if (e is TypedData) return e; |
154 | 154 |
155 if (e is Map) { | 155 if (e is Map) { |
156 var slot = findSlot(e); | 156 var slot = findSlot(e); |
157 var copy = readSlot(slot); | 157 var copy = readSlot(slot); |
158 if (copy != null) return copy; | 158 if (copy != null) return copy; |
159 copy = JS('var', '{}'); | 159 copy = JS('var', '{}'); |
160 writeSlot(slot, copy); | 160 writeSlot(slot, copy); |
161 e.forEach((key, value) { | 161 e.forEach((key, value) { |
162 JS('void', '#[#] = #', copy, key, walk(value)); | 162 JS('void', '#[#] = #', copy, key, walk(value)); |
163 }); | 163 }); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 JS('var', '#.premultipliedAlpha', nativeContextAttributes), | 325 JS('var', '#.premultipliedAlpha', nativeContextAttributes), |
326 JS('var', '#.preserveDrawingBuffer', nativeContextAttributes), | 326 JS('var', '#.preserveDrawingBuffer', nativeContextAttributes), |
327 JS('var', '#.stencil', nativeContextAttributes)); | 327 JS('var', '#.stencil', nativeContextAttributes)); |
328 } | 328 } |
329 | 329 |
330 // Conversions for ImageData | 330 // Conversions for ImageData |
331 // | 331 // |
332 // On Firefox, the returned ImageData is a plain object. | 332 // On Firefox, the returned ImageData is a plain object. |
333 | 333 |
334 class _TypedImageData implements ImageData { | 334 class _TypedImageData implements ImageData { |
335 final NativeUint8ClampedList data; | 335 final Uint8ClampedList data; |
336 final int height; | 336 final int height; |
337 final int width; | 337 final int width; |
338 | 338 |
339 _TypedImageData(this.data, this.height, this.width); | 339 _TypedImageData(this.data, this.height, this.width); |
340 } | 340 } |
341 | 341 |
342 ImageData convertNativeToDart_ImageData(nativeImageData) { | 342 ImageData convertNativeToDart_ImageData(nativeImageData) { |
343 | 343 |
344 // None of the native getters that return ImageData are declared as returning | 344 // None of the native getters that return ImageData are declared as returning |
345 // [ImageData] since that is incorrect for FireFox, which returns a plain | 345 // [ImageData] since that is incorrect for FireFox, which returns a plain |
(...skipping 17 matching lines...) Expand all Loading... |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 return nativeImageData; | 366 return nativeImageData; |
367 } | 367 } |
368 | 368 |
369 // On Firefox the above test fails because [nativeImageData] is a plain | 369 // On Firefox the above test fails because [nativeImageData] is a plain |
370 // object. So we create a _TypedImageData. | 370 // object. So we create a _TypedImageData. |
371 | 371 |
372 return new _TypedImageData( | 372 return new _TypedImageData( |
373 JS('NativeUint8ClampedList', '#.data', nativeImageData), | 373 JS('Uint8ClampedList', '#.data', nativeImageData), |
374 JS('var', '#.height', nativeImageData), | 374 JS('var', '#.height', nativeImageData), |
375 JS('var', '#.width', nativeImageData)); | 375 JS('var', '#.width', nativeImageData)); |
376 } | 376 } |
377 | 377 |
378 // We can get rid of this conversion if _TypedImageData implements the fields | 378 // We can get rid of this conversion if _TypedImageData implements the fields |
379 // with native names. | 379 // with native names. |
380 convertDartToNative_ImageData(ImageData imageData) { | 380 convertDartToNative_ImageData(ImageData imageData) { |
381 if (imageData is _TypedImageData) { | 381 if (imageData is _TypedImageData) { |
382 return JS('', '{data: #, height: #, width: #}', | 382 return JS('', '{data: #, height: #, width: #}', |
383 imageData.data, imageData.height, imageData.width); | 383 imageData.data, imageData.height, imageData.width); |
384 } | 384 } |
385 return imageData; | 385 return imageData; |
386 } | 386 } |
387 | 387 |
388 | 388 |
389 bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); | 389 bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); |
390 bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); | 390 bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); |
391 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); | 391 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); |
392 bool isJavaScriptSimpleObject(value) => | 392 bool isJavaScriptSimpleObject(value) => |
393 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); | 393 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); |
394 bool isImmutableJavaScriptArray(value) => | 394 bool isImmutableJavaScriptArray(value) => |
395 JS('bool', r'!!(#.immutable$list)', value); | 395 JS('bool', r'!!(#.immutable$list)', value); |
396 | 396 |
397 | 397 |
398 | 398 |
399 const String _serializedScriptValue = | 399 const String _serializedScriptValue = |
400 'num|String|bool|' | 400 'num|String|bool|' |
401 'JSExtendableArray|=Object|' | 401 'JSExtendableArray|=Object|' |
402 'Blob|File|NativeByteBuffer|NativeTypedData' | 402 'Blob|File|ByteBuffer|TypedData' |
403 // TODO(sra): Add Date, RegExp. | 403 // TODO(sra): Add Date, RegExp. |
404 ; | 404 ; |
405 const annotation_Creates_SerializedScriptValue = | 405 const annotation_Creates_SerializedScriptValue = |
406 const Creates(_serializedScriptValue); | 406 const Creates(_serializedScriptValue); |
407 const annotation_Returns_SerializedScriptValue = | 407 const annotation_Returns_SerializedScriptValue = |
408 const Returns(_serializedScriptValue); | 408 const Returns(_serializedScriptValue); |
OLD | NEW |