| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 class _TypedImageData implements ImageData { | 55 class _TypedImageData implements ImageData { |
| 56 final Uint8ClampedArray data; | 56 final Uint8ClampedArray data; |
| 57 final int height; | 57 final int height; |
| 58 final int width; | 58 final int width; |
| 59 | 59 |
| 60 _TypedImageData(this.data, this.height, this.width); | 60 _TypedImageData(this.data, this.height, this.width); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ImageData _convertNativeToDart_ImageData(nativeImageData) { | 63 ImageData _convertNativeToDart_ImageData(nativeImageData) { |
| 64 |
| 65 // None of the native getters that return ImageData have the type ImageData |
| 66 // since that is incorrect for FireFox (which returns a plain Object). So we |
| 67 // need something that tells the compiler that the ImageData class has been |
| 68 // instantiated. |
| 69 // TODO(sra): Remove this when all the ImageData returning APIs have been |
| 70 // annotated as returning the union ImageData + Object. |
| 71 JS('ImageData', '0'); |
| 72 |
| 64 if (nativeImageData is ImageData) return nativeImageData; | 73 if (nativeImageData is ImageData) return nativeImageData; |
| 65 | 74 |
| 66 // On Firefox the above test fails because imagedata is a plain object. | 75 // On Firefox the above test fails because imagedata is a plain object. |
| 67 // So we create a _TypedImageData. | 76 // So we create a _TypedImageData. |
| 68 | 77 |
| 69 return new _TypedImageData( | 78 return new _TypedImageData( |
| 70 JS('var', '#.data', nativeImageData), | 79 JS('var', '#.data', nativeImageData), |
| 71 JS('var', '#.height', nativeImageData), | 80 JS('var', '#.height', nativeImageData), |
| 72 JS('var', '#.width', nativeImageData)); | 81 JS('var', '#.width', nativeImageData)); |
| 73 } | 82 } |
| 74 | 83 |
| 75 // We can get rid of this conversion if _TypedImageData implements the fields | 84 // We can get rid of this conversion if _TypedImageData implements the fields |
| 76 // with native names. | 85 // with native names. |
| 77 _convertDartToNative_ImageData(ImageData imageData) { | 86 _convertDartToNative_ImageData(ImageData imageData) { |
| 78 if (imageData is _TypedImageData) { | 87 if (imageData is _TypedImageData) { |
| 79 return JS('Object', '{data: #, height: #, width: #}', | 88 return JS('', '{data: #, height: #, width: #}', |
| 80 imageData.data, imageData.height, imageData.width); | 89 imageData.data, imageData.height, imageData.width); |
| 81 } | 90 } |
| 82 return imageData; | 91 return imageData; |
| 83 } | 92 } |
| 84 | 93 |
| 85 | 94 |
| 86 /// Converts a JavaScript object with properties into a Dart Map. | 95 /// Converts a JavaScript object with properties into a Dart Map. |
| 87 /// Not suitable for nested objects. | 96 /// Not suitable for nested objects. |
| 88 Map _convertNativeToDart_Dictionary(object) { | 97 Map _convertNativeToDart_Dictionary(object) { |
| 89 if (object == null) return null; | 98 if (object == null) return null; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 424 } |
| 416 | 425 |
| 417 | 426 |
| 418 bool _isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); | 427 bool _isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); |
| 419 bool _isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); | 428 bool _isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); |
| 420 bool _isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); | 429 bool _isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); |
| 421 bool _isJavaScriptSimpleObject(value) => | 430 bool _isJavaScriptSimpleObject(value) => |
| 422 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); | 431 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); |
| 423 bool _isImmutableJavaScriptArray(value) => | 432 bool _isImmutableJavaScriptArray(value) => |
| 424 JS('bool', r'!!(#.immutable$list)', value); | 433 JS('bool', r'!!(#.immutable$list)', value); |
| OLD | NEW |