| OLD | NEW |
| 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 414 | 414 |
| 415 static getYear(receiver) { | 415 static getYear(DateTime receiver) { |
| 416 return (receiver.isUtc) | 416 return (receiver.isUtc) |
| 417 ? JS('int', r'(#.getUTCFullYear() + 0)', lazyAsJsDate(receiver)) | 417 ? JS('int', r'(#.getUTCFullYear() + 0)', lazyAsJsDate(receiver)) |
| 418 : JS('int', r'(#.getFullYear() + 0)', lazyAsJsDate(receiver)); | 418 : JS('int', r'(#.getFullYear() + 0)', lazyAsJsDate(receiver)); |
| 419 } | 419 } |
| 420 | 420 |
| 421 static getMonth(receiver) { | 421 static getMonth(DateTime receiver) { |
| 422 return (receiver.isUtc) | 422 return (receiver.isUtc) |
| 423 ? JS('int', r'#.getUTCMonth() + 1', lazyAsJsDate(receiver)) | 423 ? JS('int', r'#.getUTCMonth() + 1', lazyAsJsDate(receiver)) |
| 424 : JS('int', r'#.getMonth() + 1', lazyAsJsDate(receiver)); | 424 : JS('int', r'#.getMonth() + 1', lazyAsJsDate(receiver)); |
| 425 } | 425 } |
| 426 | 426 |
| 427 static getDay(receiver) { | 427 static getDay(DateTime receiver) { |
| 428 return (receiver.isUtc) | 428 return (receiver.isUtc) |
| 429 ? JS('int', r'(#.getUTCDate() + 0)', lazyAsJsDate(receiver)) | 429 ? JS('int', r'(#.getUTCDate() + 0)', lazyAsJsDate(receiver)) |
| 430 : JS('int', r'(#.getDate() + 0)', lazyAsJsDate(receiver)); | 430 : JS('int', r'(#.getDate() + 0)', lazyAsJsDate(receiver)); |
| 431 } | 431 } |
| 432 | 432 |
| 433 static getHours(receiver) { | 433 static getHours(DateTime receiver) { |
| 434 return (receiver.isUtc) | 434 return (receiver.isUtc) |
| 435 ? JS('int', r'(#.getUTCHours() + 0)', lazyAsJsDate(receiver)) | 435 ? JS('int', r'(#.getUTCHours() + 0)', lazyAsJsDate(receiver)) |
| 436 : JS('int', r'(#.getHours() + 0)', lazyAsJsDate(receiver)); | 436 : JS('int', r'(#.getHours() + 0)', lazyAsJsDate(receiver)); |
| 437 } | 437 } |
| 438 | 438 |
| 439 static getMinutes(receiver) { | 439 static getMinutes(DateTime receiver) { |
| 440 return (receiver.isUtc) | 440 return (receiver.isUtc) |
| 441 ? JS('int', r'(#.getUTCMinutes() + 0)', lazyAsJsDate(receiver)) | 441 ? JS('int', r'(#.getUTCMinutes() + 0)', lazyAsJsDate(receiver)) |
| 442 : JS('int', r'(#.getMinutes() + 0)', lazyAsJsDate(receiver)); | 442 : JS('int', r'(#.getMinutes() + 0)', lazyAsJsDate(receiver)); |
| 443 } | 443 } |
| 444 | 444 |
| 445 static getSeconds(receiver) { | 445 static getSeconds(DateTime receiver) { |
| 446 return (receiver.isUtc) | 446 return (receiver.isUtc) |
| 447 ? JS('int', r'(#.getUTCSeconds() + 0)', lazyAsJsDate(receiver)) | 447 ? JS('int', r'(#.getUTCSeconds() + 0)', lazyAsJsDate(receiver)) |
| 448 : JS('int', r'(#.getSeconds() + 0)', lazyAsJsDate(receiver)); | 448 : JS('int', r'(#.getSeconds() + 0)', lazyAsJsDate(receiver)); |
| 449 } | 449 } |
| 450 | 450 |
| 451 static getMilliseconds(receiver) { | 451 static getMilliseconds(DateTime receiver) { |
| 452 return (receiver.isUtc) | 452 return (receiver.isUtc) |
| 453 ? JS('int', r'(#.getUTCMilliseconds() + 0)', lazyAsJsDate(receiver)) | 453 ? JS('int', r'(#.getUTCMilliseconds() + 0)', lazyAsJsDate(receiver)) |
| 454 : JS('int', r'(#.getMilliseconds() + 0)', lazyAsJsDate(receiver)); | 454 : JS('int', r'(#.getMilliseconds() + 0)', lazyAsJsDate(receiver)); |
| 455 } | 455 } |
| 456 | 456 |
| 457 static getWeekday(receiver) { | 457 static getWeekday(DateTime receiver) { |
| 458 int weekday = (receiver.isUtc) | 458 int weekday = (receiver.isUtc) |
| 459 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver)) | 459 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver)) |
| 460 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver)); | 460 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver)); |
| 461 // Adjust by one because JS weeks start on Sunday. | 461 // Adjust by one because JS weeks start on Sunday. |
| 462 return (weekday + 6) % 7 + 1; | 462 return (weekday + 6) % 7 + 1; |
| 463 } | 463 } |
| 464 | 464 |
| 465 static valueFromDateString(str) { | 465 static valueFromDateString(str) { |
| 466 if (str is !String) throw argumentErrorValue(str); | 466 if (str is !String) throw argumentErrorValue(str); |
| 467 var value = JS('num', r'Date.parse(#)', str); | 467 var value = JS('num', r'Date.parse(#)', str); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| OLD | NEW |