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

Side by Side Diff: tool/input_sdk/private/js_helper.dart

Issue 2010693002: Add a type on lazyAsJsDate (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Review fixes Created 4 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart._js_helper; 5 library dart._js_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'dart:_foreign_helper' show 9 import 'dart:_foreign_helper' show
10 JS, 10 JS,
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 314 }
315 315
316 static String stringConcatUnchecked(String string1, String string2) { 316 static String stringConcatUnchecked(String string1, String string2) {
317 return JS_STRING_CONCAT(string1, string2); 317 return JS_STRING_CONCAT(string1, string2);
318 } 318 }
319 319
320 static String flattenString(String str) { 320 static String flattenString(String str) {
321 return JS('String', "#.charCodeAt(0) == 0 ? # : #", str, str, str); 321 return JS('String', "#.charCodeAt(0) == 0 ? # : #", str, str, str);
322 } 322 }
323 323
324 static String getTimeZoneName(receiver) { 324 static String getTimeZoneName(DateTime receiver) {
325 // Firefox and Chrome emit the timezone in parenthesis. 325 // Firefox and Chrome emit the timezone in parenthesis.
326 // Example: "Wed May 16 2012 21:13:00 GMT+0200 (CEST)". 326 // Example: "Wed May 16 2012 21:13:00 GMT+0200 (CEST)".
327 // We extract this name using a regexp. 327 // We extract this name using a regexp.
328 var d = lazyAsJsDate(receiver); 328 var d = lazyAsJsDate(receiver);
329 List match = JS('JSArray|Null', r'/\((.*)\)/.exec(#.toString())', d); 329 List match = JS('JSArray|Null', r'/\((.*)\)/.exec(#.toString())', d);
330 if (match != null) return match[1]; 330 if (match != null) return match[1];
331 331
332 // Internet Explorer 10+ emits the zone name without parenthesis: 332 // Internet Explorer 10+ emits the zone name without parenthesis:
333 // Example: Thu Oct 31 14:07:44 PDT 2013 333 // Example: Thu Oct 31 14:07:44 PDT 2013
334 match = JS('JSArray|Null', 334 match = JS('JSArray|Null',
(...skipping 13 matching lines...) Expand all
348 348
349 // IE 9 and Opera don't provide the zone name. We fall back to emitting the 349 // IE 9 and Opera don't provide the zone name. We fall back to emitting the
350 // UTC/GMT offset. 350 // UTC/GMT offset.
351 // Example (IE9): Wed Nov 20 09:51:00 UTC+0100 2013 351 // Example (IE9): Wed Nov 20 09:51:00 UTC+0100 2013
352 // (Opera): Wed Nov 20 2013 11:03:38 GMT+0100 352 // (Opera): Wed Nov 20 2013 11:03:38 GMT+0100
353 match = JS('JSArray|Null', r'/(?:GMT|UTC)[+-]\d{4}/.exec(#.toString())', d); 353 match = JS('JSArray|Null', r'/(?:GMT|UTC)[+-]\d{4}/.exec(#.toString())', d);
354 if (match != null) return match[0]; 354 if (match != null) return match[0];
355 return ""; 355 return "";
356 } 356 }
357 357
358 static int getTimeZoneOffsetInMinutes(receiver) { 358 static int getTimeZoneOffsetInMinutes(DateTime receiver) {
359 // Note that JS and Dart disagree on the sign of the offset. 359 // Note that JS and Dart disagree on the sign of the offset.
360 return -JS('int', r'#.getTimezoneOffset()', lazyAsJsDate(receiver)); 360 return -JS('int', r'#.getTimezoneOffset()', lazyAsJsDate(receiver));
361 } 361 }
362 362
363 static valueFromDecomposedDate(years, month, day, hours, minutes, seconds, 363 static valueFromDecomposedDate(years, month, day, hours, minutes, seconds,
364 milliseconds, isUtc) { 364 milliseconds, isUtc) {
365 final int MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; 365 final int MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000;
366 checkInt(years); 366 checkInt(years);
367 checkInt(month); 367 checkInt(month);
368 checkInt(day); 368 checkInt(day);
(...skipping 24 matching lines...) Expand all
393 var date = JS('', r'new Date(#)', value); 393 var date = JS('', r'new Date(#)', value);
394 if (isUtc) { 394 if (isUtc) {
395 JS('num', r'#.setUTCFullYear(#)', date, years); 395 JS('num', r'#.setUTCFullYear(#)', date, years);
396 } else { 396 } else {
397 JS('num', r'#.setFullYear(#)', date, years); 397 JS('num', r'#.setFullYear(#)', date, years);
398 } 398 }
399 return JS('num', r'#.valueOf()', date); 399 return JS('num', r'#.valueOf()', date);
400 } 400 }
401 401
402 // Lazily keep a JS Date stored in the JS object. 402 // Lazily keep a JS Date stored in the JS object.
403 static lazyAsJsDate(receiver) { 403 static lazyAsJsDate(DateTime receiver) {
404 if (JS('bool', r'#.date === (void 0)', receiver)) { 404 if (JS('bool', r'#.date === (void 0)', receiver)) {
405 JS('void', r'#.date = new Date(#)', receiver, 405 JS('void', r'#.date = new Date(#)', receiver,
406 receiver.millisecondsSinceEpoch); 406 receiver.millisecondsSinceEpoch);
407 } 407 }
408 return JS('var', r'#.date', receiver); 408 return JS('var', r'#.date', receiver);
409 } 409 }
410 410
411 // The getters for date and time parts below add a positive integer to ensure 411 // The getters for date and time parts below add a positive integer to ensure
412 // that the result is really an integer, because the JavaScript implementation 412 // that the result is really an integer, because the JavaScript implementation
413 // may return -0.0 instead of 0. 413 // may return -0.0 instead of 0.
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // we have no way of telling the compiler yet, so it will generate an extra 864 // we have no way of telling the compiler yet, so it will generate an extra
865 // layer of indirection that wraps the SyncIterator. 865 // layer of indirection that wraps the SyncIterator.
866 _jsIterator() => JS('', '#(...#)', _generator, _args); 866 _jsIterator() => JS('', '#(...#)', _generator, _args);
867 867
868 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); 868 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator());
869 } 869 }
870 870
871 class BooleanConversionAssertionError extends AssertionError { 871 class BooleanConversionAssertionError extends AssertionError {
872 toString() => 'Failed assertion: boolean expression must not be null'; 872 toString() => 'Failed assertion: boolean expression must not be null';
873 } 873 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698