| Index: lib/html/src/dart2js_Conversions.dart
|
| diff --git a/lib/html/src/dart2js_Conversions.dart b/lib/html/src/dart2js_Conversions.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e0e2ff2289a80ecb885b053eb6acb83d41b8d3d6
|
| --- /dev/null
|
| +++ b/lib/html/src/dart2js_Conversions.dart
|
| @@ -0,0 +1,106 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +// Conversions for IDBKey.
|
| +//
|
| +// Per http://www.w3.org/TR/IndexedDB/#key-construct
|
| +//
|
| +// "A value is said to be a valid key if it is one of the following types: Array
|
| +// JavaScript objects [ECMA-262], DOMString [WEBIDL], Date [ECMA-262] or float
|
| +// [WEBIDL]. However Arrays are only valid keys if every item in the array is
|
| +// defined and is a valid key (i.e. sparse arrays can not be valid keys) and if
|
| +// the Array doesn't directly or indirectly contain itself. Any non-numeric
|
| +// properties are ignored, and thus does not affect whether the Array is a valid
|
| +// key. Additionally, if the value is of type float, it is only a valid key if
|
| +// it is not NaN, and if the value is of type Date it is only a valid key if its
|
| +// [[PrimitiveValue]] internal property, as defined by [ECMA-262], is not NaN."
|
| +
|
| +// What is required is to ensure that an Lists in the key are actually
|
| +// JavaScript arrays, and any Dates are JavaScript Dates.
|
| +
|
| +/**
|
| + * Converts a native IDBKey into a Dart object.
|
| + *
|
| + * May return the original input. May mutate the original input (but will be
|
| + * idempotent if mutation occurs). It is assumed that this conversion happens
|
| + * on native IDBKeys on all paths that return IDBKeys from native DOM calls.
|
| + *
|
| + * If necessary, JavaScript Dates are converted into Dart Dates.
|
| + */
|
| +_convertNativeToDart_IDBKey(nativeKey) {
|
| + // TODO: Implement.
|
| + // TODO: Cache conversion somewhere.
|
| + return nativeKey;
|
| +}
|
| +
|
| +/**
|
| + * Converts a Dart object into a valid IDBKey.
|
| + *
|
| + * May return the original input. Does not mutate input.
|
| + *
|
| + * If necessary, [dartKey] may be copied to ensure all lists are converted into
|
| + * JavaScript Arrays and Dart Dates into JavaScript Dates.
|
| + */
|
| +
|
| +_convertDartToNative_IDBKey(dartKey) {
|
| + // TODO: Implement.
|
| + // TODO: Cache conversion on object.
|
| + return dartKey;
|
| +}
|
| +
|
| +
|
| +// Conversions for ImageData
|
| +//
|
| +// On Firefox, the returned ImageData is a plain object.
|
| +
|
| +class _TypedImageData implements ImageData {
|
| + final Uint8ClampedArray data;
|
| + final int height;
|
| + final int width;
|
| +
|
| + _TypedImageData(this.data, this.height, this.width);
|
| +}
|
| +
|
| +ImageData _convertNativeToDart_ImageData(nativeImageData) {
|
| + if (nativeImageData is ImageData) return nativeImageData;
|
| +
|
| + // On Firefox the above test fails because imagedata is a plain object.
|
| + // So we create a _TypedImageData.
|
| +
|
| + return new _TypedImageData(
|
| + JS('var', '#.data', nativeImageData),
|
| + JS('var', '#.height', nativeImageData),
|
| + JS('var', '#.width', nativeImageData));
|
| +}
|
| +
|
| +// We can get rid of this conversion if _TypedImageData implements the fields
|
| +// with native names.
|
| +_convertDartToNative_ImageData(ImageData imageData) {
|
| + if (imageData is _ImageDataImpl) return imageData;
|
| + return JS('Object', '{data: #, height: #, width: #}',
|
| + imageData.data, imageData.height, imageData.width);
|
| +}
|
| +
|
| +
|
| +/// Converts a JavaScript object with properties into a Dart Map.
|
| +Map _convertNativeToDart_Dictionary(object) {
|
| + // TODO: Implement.
|
| + return object;
|
| +}
|
| +
|
| +/// Converts a Dart map into a JavaScript object with properties.
|
| +_convertDartToNative_Dictionary(Map dict) {
|
| + // TODO: Implement.
|
| + return dict;
|
| +}
|
| +
|
| +
|
| +/**
|
| + * Ensures that the input is a JavaScript Array.
|
| + *
|
| + * Creates a new JavaScript array if necessary, otherwise returns the original.
|
| + */
|
| +List _convertDartToNative_StringArray(List<String> input) {
|
| + return input;
|
| +}
|
|
|