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

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

Issue 1349293006: Start using the dart2js type conversions in Dartium as well. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged Created 5 years, 3 months 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/conversions_dart2js.dart ('k') | sdk/lib/html/html_common/html_common.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_dartium.dart
diff --git a/sdk/lib/html/html_common/conversions_dartium.dart b/sdk/lib/html/html_common/conversions_dartium.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fc7ca61360b1dba6bef2d672ce93ffc795d0028b
--- /dev/null
+++ b/sdk/lib/html/html_common/conversions_dartium.dart
@@ -0,0 +1,63 @@
+part of html_common;
+
+convertDartToNative_PrepareForStructuredClone(value) =>
+ new _StructuredCloneDartium().convertDartToNative_PrepareForStructuredClone(value);
+
+convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) =>
+ new _AcceptStructuredCloneDartium().convertNativeToDart_AcceptStructuredClone(object, mustCopy: mustCopy);
+
+class _StructuredCloneDartium extends _StructuredClone {
+ newJsMap() => new js.JsObject(js.context["Object"]);
+ putIntoMap(map, key, value) => map[key] = value;
+ newJSList(length) => new js.JsArray();
+ cloneNotRequired(e) => e is js.JsObject;
+}
+
+class _AcceptStructuredCloneDartium extends _AcceptStructuredClone {
+ newDartList(length) => new List(length);
+
+ // JsObjects won't be identical, but will be equal only if the underlying
+ // Js entities are identical.
+ bool identicalInJs(a, b) =>
+ (a is js.JsObject) ? a == b : identical(a, b);
+
+ void forEachJsField(jsObject, action) {
+ var keys = js.context["Object"].callMethod("keys", [jsObject]);
+ for (var key in keys) {
+ action(key, jsObject[key]);
+ }
+ }
+}
+
+final _dateConstructor = js.context["Date"];
+final _regexConstructor = js.context["RegExp"];
+
+bool isJavaScriptDate(value) => value is js.JsObject && value.instanceof(_dateConstructor);
+bool isJavaScriptRegExp(value) => value is js.JsObject && value.instanceof(_regexConstructor);
+bool isJavaScriptArray(value) => value is js.JsArray;
+
+final _object = js.context["Object"];
+final _getPrototypeOf = _object["getPrototypeOf"];
+_getProto(object) {
+ return _getPrototypeOf.apply([object]);
+}
+final _objectProto = js.context["Object"]["prototype"];
+
+bool isJavaScriptSimpleObject(value) {
+ if (!value is js.JsObject) return false;
+ var proto = _getProto(value);
+ return proto == _objectProto || proto == null;
+}
+bool isImmutableJavaScriptArray(value) =>
+ isJavaScriptArray(value) && value["immutable$list"] != null;
+
+final _promiseConstructor = js.context['Promise'];
+bool isJavaScriptPromise(value) => value is js.JsObject && value['constructor'] == _promiseConstructor;
+
+Future convertNativePromiseToDartFuture(js.JsObject promise) {
+ var completer = new Completer();
+ var newPromise = promise
+ .callMethod("then", [(result) => completer.complete(result)])
+ .callMethod("catch", [(result) => completer.completeError(result)]);
+ return completer.future;
+}
« no previous file with comments | « sdk/lib/html/html_common/conversions_dart2js.dart ('k') | sdk/lib/html/html_common/html_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698