| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 // Assume anything else is already a valid Dart object, either by having | 308 // Assume anything else is already a valid Dart object, either by having |
| 309 // already been processed, or e.g. a clonable native class. | 309 // already been processed, or e.g. a clonable native class. |
| 310 return e; | 310 return e; |
| 311 } | 311 } |
| 312 | 312 |
| 313 var copy = walk(object); | 313 var copy = walk(object); |
| 314 return copy; | 314 return copy; |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Conversions for ImageData |
| 318 // |
| 319 // On Firefox, the returned ImageData is a plain object. |
| 320 |
| 321 class _TypedImageData implements ImageData { |
| 322 final Uint8ClampedList data; |
| 323 final int height; |
| 324 final int width; |
| 325 |
| 326 _TypedImageData(this.data, this.height, this.width); |
| 327 } |
| 328 |
| 329 ImageData convertNativeToDart_ImageData(nativeImageData) { |
| 330 |
| 331 // None of the native getters that return ImageData have the type ImageData |
| 332 // since that is incorrect for FireFox (which returns a plain Object). So we |
| 333 // need something that tells the compiler that the ImageData class has been |
| 334 // instantiated. |
| 335 // TODO(sra): Remove this when all the ImageData returning APIs have been |
| 336 // annotated as returning the union ImageData + Object. |
| 337 JS('ImageData', '0'); |
| 338 |
| 339 if (nativeImageData is ImageData) return nativeImageData; |
| 340 |
| 341 // On Firefox the above test fails because imagedata is a plain object. |
| 342 // So we create a _TypedImageData. |
| 343 |
| 344 return new _TypedImageData( |
| 345 JS('var', '#.data', nativeImageData), |
| 346 JS('var', '#.height', nativeImageData), |
| 347 JS('var', '#.width', nativeImageData)); |
| 348 } |
| 349 |
| 350 // We can get rid of this conversion if _TypedImageData implements the fields |
| 351 // with native names. |
| 352 convertDartToNative_ImageData(ImageData imageData) { |
| 353 if (imageData is _TypedImageData) { |
| 354 return JS('', '{data: #, height: #, width: #}', |
| 355 imageData.data, imageData.height, imageData.width); |
| 356 } |
| 357 return imageData; |
| 358 } |
| 359 |
| 317 | 360 |
| 318 bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); | 361 bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value); |
| 319 bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); | 362 bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value); |
| 320 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); | 363 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value); |
| 321 bool isJavaScriptSimpleObject(value) => | 364 bool isJavaScriptSimpleObject(value) => |
| 322 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); | 365 JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value); |
| 323 bool isImmutableJavaScriptArray(value) => | 366 bool isImmutableJavaScriptArray(value) => |
| 324 JS('bool', r'!!(#.immutable$list)', value); | 367 JS('bool', r'!!(#.immutable$list)', value); |
| 325 | 368 |
| 326 | 369 |
| 327 | 370 |
| 328 const String _serializedScriptValue = | 371 const String _serializedScriptValue = |
| 329 'num|String|bool|' | 372 'num|String|bool|' |
| 330 '=List|=Object|' | 373 '=List|=Object|' |
| 331 'Blob|File|ByteBuffer|TypedData' | 374 'Blob|File|ByteBuffer|TypedData' |
| 332 // TODO(sra): Add Date, RegExp. | 375 // TODO(sra): Add Date, RegExp. |
| 333 ; | 376 ; |
| 334 const annotation_Creates_SerializedScriptValue = | 377 const annotation_Creates_SerializedScriptValue = |
| 335 const Creates(_serializedScriptValue); | 378 const Creates(_serializedScriptValue); |
| 336 const annotation_Returns_SerializedScriptValue = | 379 const annotation_Returns_SerializedScriptValue = |
| 337 const Returns(_serializedScriptValue); | 380 const Returns(_serializedScriptValue); |
| OLD | NEW |