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

Side by Side Diff: frog/lib/date_implementation.dart

Issue 9695057: Allow "const ... native" constructors and "const factory ... native" constructors in dartc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: # Created 8 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // TODO(jmesserly): the native class should be the real JS Date. 5 // TODO(jmesserly): the native class should be the real JS Date.
6 // TODO(jimhug): Making the date value non-lazy might be a good path there. 6 // TODO(jimhug): Making the date value non-lazy might be a good path there.
7 class DateImplementation implements Date { 7 class DateImplementation implements Date {
8 final int value; 8 final int value;
9 final TimeZoneImplementation timeZone; 9 final TimeZoneImplementation timeZone;
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return value;'''; 257 return value;''';
258 258
259 static int _valueFromString(String str) native 259 static int _valueFromString(String str) native
260 '''var value = Date.parse(str); 260 '''var value = Date.parse(str);
261 if (isNaN(value)) throw Error("Invalid Date"); 261 if (isNaN(value)) throw Error("Invalid Date");
262 return value;'''; 262 return value;''';
263 263
264 static int _now() native "return new Date().valueOf();"; 264 static int _now() native "return new Date().valueOf();";
265 265
266 // Lazily keep a JS Date stored in the dart object. 266 // Lazily keep a JS Date stored in the dart object.
267 var _asJs() native ''' 267 _asJs() native '''
268 if (!this.date) { 268 if (!this.date) {
269 this.date = new Date(this.value); 269 this.date = new Date(this.value);
270 } 270 }
271 return this.date;'''; 271 return this.date;''';
272 } 272 }
273 273
274 // Trivial implementation of TimeZone 274 // Trivial implementation of TimeZone
275 class TimeZoneImplementation implements TimeZone { 275 class TimeZoneImplementation implements TimeZone {
276 const TimeZoneImplementation.utc() : this.isUtc = true; 276 const TimeZoneImplementation.utc() : this.isUtc = true;
277 const TimeZoneImplementation.local() : this.isUtc = false; 277 const TimeZoneImplementation.local() : this.isUtc = false;
278 278
279 bool operator ==(other) { 279 bool operator ==(other) {
280 if (!(other is TimeZoneImplementation)) return false; 280 if (!(other is TimeZoneImplementation)) return false;
281 return isUtc == other.isUtc; 281 return isUtc == other.isUtc;
282 } 282 }
283 283
284 String toString() { 284 String toString() {
285 if (isUtc) return "TimeZone (UTC)"; 285 if (isUtc) return "TimeZone (UTC)";
286 return "TimeZone (Local)"; 286 return "TimeZone (Local)";
287 } 287 }
288 288
289 final bool isUtc; 289 final bool isUtc;
290 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698