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

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

Issue 17574008: Fixing DateTime values in dart2js serialized script values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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/dart2js/html_dart2js.dart ('k') | tests/html/indexeddb_1_test.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/html_common/conversions.dart b/sdk/lib/html/html_common/conversions.dart
index b387f41b6e86e03f7d344c3d14ed8627e77bd3ce..05f50b42ff63e665b09b82ac3fd91e89cdb6b9bc 100644
--- a/sdk/lib/html/html_common/conversions.dart
+++ b/sdk/lib/html/html_common/conversions.dart
@@ -62,6 +62,15 @@ List convertDartToNative_StringArray(List<String> input) {
return input;
}
+DateTime convertNativeToDart_DateTime(date) {
+ var millisSinceEpoch = JS('int', '#.getTime()', date);
+ return new DateTime.fromMillisecondsSinceEpoch(millisSinceEpoch, isUtc: true);
+}
+
+convertDartToNative_DateTime(DateTime date) {
+ return JS('', 'new Date(#)', date.millisecondsSinceEpoch);
+}
+
// -----------------------------------------------------------------------------
@@ -119,8 +128,7 @@ _convertDartToNative_PrepareForStructuredClone(value) {
if (e is num) return e;
if (e is String) return e;
if (e is DateTime) {
- // TODO(sra).
- throw new UnimplementedError('structured clone of DateTime');
+ return convertDartToNative_DateTime(e);
}
if (e is RegExp) {
// TODO(sra).
@@ -237,8 +245,7 @@ convertNativeToDart_AcceptStructuredClone(object, {mustCopy = false}) {
if (e is String) return e;
if (isJavaScriptDate(e)) {
- // TODO(sra).
- throw new UnimplementedError('structured clone of DateTime');
+ return convertNativeToDart_DateTime(e);
}
if (isJavaScriptRegExp(e)) {
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | tests/html/indexeddb_1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698