Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: sdk/lib/html/html_common/conversions.dart

Issue 11316113: Creating a common library for all DOM types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merging with latest from tree. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/html_common/collections.dart ('k') | sdk/lib/html/html_common/html_common_dart2js.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/html_common/conversions.dart
diff --git a/sdk/lib/html/src/dart2js_Conversions.dart b/sdk/lib/html/html_common/conversions.dart
similarity index 68%
copy from sdk/lib/html/src/dart2js_Conversions.dart
copy to sdk/lib/html/html_common/conversions.dart
index cc4469970dccdfe87f214d13ca0b68cbad8c4ba5..f4d42adfbd8d103e5c0d34dd38192821fdae878e 100644
--- a/sdk/lib/html/src/dart2js_Conversions.dart
+++ b/sdk/lib/html/html_common/conversions.dart
@@ -26,77 +26,12 @@
// We omit an unwrapper for Window as no methods take a non-local
// window as a parameter.
-part of html;
-
-Window _convertNativeToDart_Window(win) {
- return _DOMWindowCrossFrame._createSafe(win);
-}
-
-EventTarget _convertNativeToDart_EventTarget(e) {
- // Assume it's a Window if it contains the setInterval property. It may be
- // from a different frame - without a patched prototype - so we cannot
- // rely on Dart type checking.
- if (JS('bool', r'"setInterval" in #', e))
- return _DOMWindowCrossFrame._createSafe(e);
- else
- return e;
-}
-
-EventTarget _convertDartToNative_EventTarget(e) {
- if (e is _DOMWindowCrossFrame) {
- return e._window;
- } else {
- return e;
- }
-}
-
-// 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) {
-
- // None of the native getters that return ImageData have the type ImageData
- // since that is incorrect for FireFox (which returns a plain Object). So we
- // need something that tells the compiler that the ImageData class has been
- // instantiated.
- // TODO(sra): Remove this when all the ImageData returning APIs have been
- // annotated as returning the union ImageData + Object.
- JS('ImageData', '0');
-
- 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 _TypedImageData) {
- return JS('', '{data: #, height: #, width: #}',
- imageData.data, imageData.height, imageData.width);
- }
- return imageData;
-}
+part of html_common;
/// Converts a JavaScript object with properties into a Dart Map.
/// Not suitable for nested objects.
-Map _convertNativeToDart_Dictionary(object) {
+Map convertNativeToDart_Dictionary(object) {
if (object == null) return null;
var dict = {};
for (final key in JS('=List', 'Object.getOwnPropertyNames(#)', object)) {
@@ -106,7 +41,7 @@ Map _convertNativeToDart_Dictionary(object) {
}
/// Converts a flat Dart map into a JavaScript object with properties.
-_convertDartToNative_Dictionary(Map dict) {
+convertDartToNative_Dictionary(Map dict) {
if (dict == null) return null;
var object = JS('var', '{}');
dict.forEach((String key, value) {
@@ -121,7 +56,7 @@ _convertDartToNative_Dictionary(Map dict) {
*
* Creates a new JavaScript array if necessary, otherwise returns the original.
*/
-List _convertDartToNative_StringArray(List<String> input) {
+List convertDartToNative_StringArray(List<String> input) {
// TODO(sra). Implement this.
return input;
}
@@ -129,61 +64,15 @@ List _convertDartToNative_StringArray(List<String> input) {
// -----------------------------------------------------------------------------
-/**
- * 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) {
- containsDate(object) {
- if (_isJavaScriptDate(object)) return true;
- if (object is List) {
- for (int i = 0; i < object.length; i++) {
- if (containsDate(object[i])) return true;
- }
- }
- return false; // number, string.
- }
- if (containsDate(nativeKey)) {
- throw new UnimplementedError('IDBKey containing Date');
- }
- // 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.
- return dartKey;
-}
-
-
-
-/// May modify original. If so, action is idempotent.
-_convertNativeToDart_IDBAny(object) {
- return _convertNativeToDart_AcceptStructuredClone(object, mustCopy: false);
-}
-
/// Converts a Dart value into a JavaScript SerializedScriptValue.
-_convertDartToNative_SerializedScriptValue(value) {
+convertDartToNative_SerializedScriptValue(value) {
return _convertDartToNative_PrepareForStructuredClone(value);
}
/// Since the source object may be viewed via a JavaScript event listener the
/// original may not be modified.
-_convertNativeToDart_SerializedScriptValue(object) {
- return _convertNativeToDart_AcceptStructuredClone(object, mustCopy: true);
+convertNativeToDart_SerializedScriptValue(object) {
+ return convertNativeToDart_AcceptStructuredClone(object, mustCopy: true);
}
@@ -246,7 +135,7 @@ _convertDartToNative_PrepareForStructuredClone(value) {
if (e is File) return e;
if (e is Blob) return e;
- if (e is _FileList) return e;
+ if (e is FileList) return e;
// TODO(sra): Firefox: How to convert _TypedImageData on the other end?
if (e is ImageData) return e;
@@ -284,11 +173,11 @@ _convertDartToNative_PrepareForStructuredClone(value) {
int i = 0;
- if (_isJavaScriptArray(e) &&
+ if (isJavaScriptArray(e) &&
// We have to copy immutable lists, otherwise the structured clone
// algorithm will copy the .immutable$list marker property, making the
// list immutable when received!
- !_isImmutableJavaScriptArray(e)) {
+ !isImmutableJavaScriptArray(e)) {
writeSlot(slot, true); // Deferred copy.
for ( ; i < length; i++) {
var element = e[i];
@@ -349,7 +238,7 @@ _convertDartToNative_PrepareForStructuredClone(value) {
* MessageEvents. Mutating the object to make it more 'Dart-like' would corrupt
* the value as seen from the JavaScript listeners.
*/
-_convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
+convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
// TODO(sra): Replace slots with identity hash table that works on non-dart
// objects.
@@ -374,17 +263,17 @@ _convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
if (e is num) return e;
if (e is String) return e;
- if (_isJavaScriptDate(e)) {
+ if (isJavaScriptDate(e)) {
// TODO(sra).
throw new UnimplementedError('structured clone of Date');
}
- if (_isJavaScriptRegExp(e)) {
+ if (isJavaScriptRegExp(e)) {
// TODO(sra).
throw new UnimplementedError('structured clone of RegExp');
}
- if (_isJavaScriptSimpleObject(e)) {
+ if (isJavaScriptSimpleObject(e)) {
// TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map
// implementation that uses the properies as storage.
var slot = findSlot(e);
@@ -399,7 +288,7 @@ _convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
return copy;
}
- if (_isJavaScriptArray(e)) {
+ if (isJavaScriptArray(e)) {
var slot = findSlot(e);
var copy = readSlot(slot);
if (copy != null) return copy;
@@ -426,12 +315,12 @@ _convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
}
-bool _isJavaScriptDate(value) => JS('bool', '# instanceof Date', value);
-bool _isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value);
-bool _isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
-bool _isJavaScriptSimpleObject(value) =>
+bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value);
+bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value);
+bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
+bool isJavaScriptSimpleObject(value) =>
JS('bool', 'Object.getPrototypeOf(#) === Object.prototype', value);
-bool _isImmutableJavaScriptArray(value) =>
+bool isImmutableJavaScriptArray(value) =>
JS('bool', r'!!(#.immutable$list)', value);
@@ -442,11 +331,7 @@ const String _serializedScriptValue =
'Blob|File|ArrayBuffer|ArrayBufferView'
// TODO(sra): Add Date, RegExp.
;
-const _annotation_Creates_SerializedScriptValue =
+const annotation_Creates_SerializedScriptValue =
const Creates(_serializedScriptValue);
-const _annotation_Returns_SerializedScriptValue =
+const annotation_Returns_SerializedScriptValue =
const Returns(_serializedScriptValue);
-
-const String _idbKey = '=List|=Object|num|String'; // TODO(sra): Add Date.
-const _annotation_Creates_IDBKey = const Creates(_idbKey);
-const _annotation_Returns_IDBKey = const Returns(_idbKey);
« no previous file with comments | « sdk/lib/html/html_common/collections.dart ('k') | sdk/lib/html/html_common/html_common_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698