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

Side by Side Diff: tool/input_sdk/lib/html/html_common/conversions_dart2js.dart

Issue 1528613004: First cut of mini dart:html. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Fix build_sdk Created 5 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 part of html_common;
2
3 /// Converts a JavaScript object with properties into a Dart Map.
4 /// Not suitable for nested objects.
5 Map convertNativeToDart_Dictionary(object) {
6 if (object == null) return null;
7 var dict = {};
8 var keys = JS('JSExtendableArray', 'Object.getOwnPropertyNames(#)', object);
9 for (final key in keys) {
10 dict[key] = JS('var', '#[#]', object, key);
11 }
12 return dict;
13 }
14
15 /// Converts a flat Dart map into a JavaScript object with properties.
16 convertDartToNative_Dictionary(Map dict, [void postCreate(dynamic)]) {
17 if (dict == null) return null;
18 var object = JS('var', '{}');
19 if (postCreate != null) {
20 postCreate(object);
21 }
22 dict.forEach((String key, value) {
23 JS('void', '#[#] = #', object, key, value);
24 });
25 return object;
26 }
27
28
29 /**
30 * Ensures that the input is a JavaScript Array.
31 *
32 * Creates a new JavaScript array if necessary, otherwise returns the original.
33 */
34 List convertDartToNative_StringArray(List<String> input) {
35 // TODO(sra). Implement this.
36 return input;
37 }
38
39 DateTime convertNativeToDart_DateTime(date) {
40 var millisSinceEpoch = JS('int', '#.getTime()', date);
41 return new DateTime.fromMillisecondsSinceEpoch(millisSinceEpoch, isUtc: true);
42 }
43
44 convertDartToNative_DateTime(DateTime date) {
45 return JS('', 'new Date(#)', date.millisecondsSinceEpoch);
46 }
47
48 convertDartToNative_PrepareForStructuredClone(value) =>
49 new _StructuredCloneDart2Js().convertDartToNative_PrepareForStructuredClone( value);
50
51 convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) =>
52 new _AcceptStructuredCloneDart2Js().convertNativeToDart_AcceptStructuredClon e(object, mustCopy: mustCopy);
53
54 class _StructuredCloneDart2Js extends _StructuredClone {
55 newJsMap() => JS('var', '{}');
56 putIntoMap(map, key, value) => JS('void', '#[#] = #', map, key, value);
57 newJsList(length) => JS('JSExtendableArray', 'new Array(#)', length);
58 cloneNotRequired(e) => (e is NativeByteBuffer || e is NativeTypedData);
59 }
60
61 class _AcceptStructuredCloneDart2Js extends _AcceptStructuredClone {
62
63 newJsList(length) => JS('JSExtendableArray', 'new Array(#)', length);
64 newDartList(length) => newJsList(length);
65 identicalInJs(a, b) => identical(a, b);
66
67 void forEachJsField(object, action) {
68 for (final key in JS('JSExtendableArray', 'Object.keys(#)', object)) {
69 action(key, JS('var', '#[#]', object, key));
70 }
71 }
72 }
73
74 bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value);
75 bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value);
76 bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
77 bool isJavaScriptSimpleObject(value) {
78 var proto = JS('', 'Object.getPrototypeOf(#)', value);
79 return JS('bool', '# === Object.prototype', proto) ||
80 JS('bool', '# === null', proto);
81 }
82 bool isImmutableJavaScriptArray(value) =>
83 JS('bool', r'!!(#.immutable$list)', value);
84 bool isJavaScriptPromise(value) =>
85 JS('bool', r'typeof Promise != "undefined" && # instanceof Promise', value);
86
87 Future convertNativePromiseToDartFuture(promise) {
88 var completer = new Completer();
89 var then = convertDartClosureToJS((result) => completer.complete(result), 1);
90 var error = convertDartClosureToJS((result) => completer.completeError(result) , 1);
91 var newPromise = JS('', '#.then(#).catch(#)', promise, then, error);
92 return completer.future;
93 }
94
95 /// Wrap a JS object with an instance of the matching dart:html class. Used only in Dartium.
96 //wrap_jso(jsObject) => jsObject;
97
98 /// Find the underlying JS object for a dart:html Dart object.
99 //unwrap_jso(dartClass_instance) => dartClass_instance;
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/html/html_common/conversions.dart ('k') | tool/input_sdk/lib/html/html_common/css_class_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698