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

Side by Side Diff: tools/dom/src/native_DOMImplementation.dart

Issue 12493011: Make sure double to DateTime conversion never throws. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 class _Utils { 7 class _Utils {
8 static double dateTimeToDouble(DateTime dateTime) => 8 static double dateTimeToDouble(DateTime dateTime) =>
9 dateTime.millisecondsSinceEpoch.toDouble(); 9 dateTime.millisecondsSinceEpoch.toDouble();
10 static DateTime doubleToDateTime(double dateTime) => 10 static DateTime doubleToDateTime(double dateTime) {
11 new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); 11 try {
12 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt());
13 } catch {
14 // TODO(antonnm): treat exceptions properly in bindings and
15 // find out how to treat NaNs.
16 return null;
17 }
18 }
12 19
13 static List convertToList(List list) { 20 static List convertToList(List list) {
14 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it. 21 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it.
15 final length = list.length; 22 final length = list.length;
16 List result = new List(length); 23 List result = new List(length);
17 result.setRange(0, length, list); 24 result.setRange(0, length, list);
18 return result; 25 return result;
19 } 26 }
20 27
21 static List convertMapToList(Map map) { 28 static List convertMapToList(Map map) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 bool get isEmpty => Maps.isEmpty(this); 119 bool get isEmpty => Maps.isEmpty(this);
113 } 120 }
114 121
115 get _printClosure => (s) { 122 get _printClosure => (s) {
116 try { 123 try {
117 window.console.log(s); 124 window.console.log(s);
118 } catch (_) { 125 } catch (_) {
119 _Utils.print(s); 126 _Utils.print(s);
120 } 127 }
121 }; 128 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698