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

Side by Side Diff: src/runtime.cc

Issue 9572008: Implement date library functions in C++. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Bug fixes. 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22 matching lines...) Expand all
33 #include "api.h" 33 #include "api.h"
34 #include "arguments.h" 34 #include "arguments.h"
35 #include "bootstrapper.h" 35 #include "bootstrapper.h"
36 #include "codegen.h" 36 #include "codegen.h"
37 #include "compilation-cache.h" 37 #include "compilation-cache.h"
38 #include "compiler.h" 38 #include "compiler.h"
39 #include "cpu.h" 39 #include "cpu.h"
40 #include "dateparser-inl.h" 40 #include "dateparser-inl.h"
41 #include "debug.h" 41 #include "debug.h"
42 #include "deoptimizer.h" 42 #include "deoptimizer.h"
43 #include "date.h"
43 #include "execution.h" 44 #include "execution.h"
44 #include "global-handles.h" 45 #include "global-handles.h"
45 #include "isolate-inl.h" 46 #include "isolate-inl.h"
46 #include "jsregexp.h" 47 #include "jsregexp.h"
47 #include "json-parser.h" 48 #include "json-parser.h"
48 #include "liveedit.h" 49 #include "liveedit.h"
49 #include "liveobjectlist-inl.h" 50 #include "liveobjectlist-inl.h"
50 #include "misc-intrinsics.h" 51 #include "misc-intrinsics.h"
51 #include "parser.h" 52 #include "parser.h"
52 #include "platform.h" 53 #include "platform.h"
(...skipping 7450 matching lines...) Expand 10 before | Expand all | Expand 10 after
7503 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { 7504 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) {
7504 NoHandleAllocation ha; 7505 NoHandleAllocation ha;
7505 ASSERT(args.length() == 1); 7506 ASSERT(args.length() == 1);
7506 isolate->counters()->math_tan()->Increment(); 7507 isolate->counters()->math_tan()->Increment();
7507 7508
7508 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7509 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7509 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x); 7510 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
7510 } 7511 }
7511 7512
7512 7513
7513 static int MakeDay(int year, int month) {
7514 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
7515 181, 212, 243, 273, 304, 334};
7516 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
7517 182, 213, 244, 274, 305, 335};
7518
7519 year += month / 12;
7520 month %= 12;
7521 if (month < 0) {
7522 year--;
7523 month += 12;
7524 }
7525
7526 ASSERT(month >= 0);
7527 ASSERT(month < 12);
7528
7529 // year_delta is an arbitrary number such that:
7530 // a) year_delta = -1 (mod 400)
7531 // b) year + year_delta > 0 for years in the range defined by
7532 // ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of
7533 // Jan 1 1970. This is required so that we don't run into integer
7534 // division of negative numbers.
7535 // c) there shouldn't be an overflow for 32-bit integers in the following
7536 // operations.
7537 static const int year_delta = 399999;
7538 static const int base_day = 365 * (1970 + year_delta) +
7539 (1970 + year_delta) / 4 -
7540 (1970 + year_delta) / 100 +
7541 (1970 + year_delta) / 400;
7542
7543 int year1 = year + year_delta;
7544 int day_from_year = 365 * year1 +
7545 year1 / 4 -
7546 year1 / 100 +
7547 year1 / 400 -
7548 base_day;
7549
7550 if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
7551 return day_from_year + day_from_month[month];
7552 }
7553
7554 return day_from_year + day_from_month_leap[month];
7555 }
7556
7557
7558 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { 7514 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) {
7559 NoHandleAllocation ha; 7515 NoHandleAllocation ha;
7560 ASSERT(args.length() == 2); 7516 ASSERT(args.length() == 2);
7561 7517
7562 CONVERT_SMI_ARG_CHECKED(year, 0); 7518 CONVERT_SMI_ARG_CHECKED(year, 0);
7563 CONVERT_SMI_ARG_CHECKED(month, 1); 7519 CONVERT_SMI_ARG_CHECKED(month, 1);
7564 7520
7565 return Smi::FromInt(MakeDay(year, month)); 7521 return Smi::FromInt(isolate->date_cache()->DaysFromYearMonth(year, month));
7566 } 7522 }
7567 7523
7568 7524
7569 static const int kDays4Years[] = {0, 365, 2 * 365, 3 * 365 + 1}; 7525 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateSetValue) {
7570 static const int kDaysIn4Years = 4 * 365 + 1; 7526 HandleScope scope(isolate);
7571 static const int kDaysIn100Years = 25 * kDaysIn4Years - 1; 7527 ASSERT(args.length() == 3);
7572 static const int kDaysIn400Years = 4 * kDaysIn100Years + 1;
7573 static const int kDays1970to2000 = 30 * 365 + 7;
7574 static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years -
7575 kDays1970to2000;
7576 static const int kYearsOffset = 400000;
7577 7528
7578 static const char kDayInYear[] = { 7529 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 0);
7579 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7530 CONVERT_DOUBLE_ARG_CHECKED(time, 1);
7580 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7531 CONVERT_SMI_ARG_CHECKED(is_utc, 2);
7581 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7582 22, 23, 24, 25, 26, 27, 28,
7583 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7584 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7585 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7586 22, 23, 24, 25, 26, 27, 28, 29, 30,
7587 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7588 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7589 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7590 22, 23, 24, 25, 26, 27, 28, 29, 30,
7591 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7592 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7593 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7594 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7595 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7596 22, 23, 24, 25, 26, 27, 28, 29, 30,
7597 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7598 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7599 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7600 22, 23, 24, 25, 26, 27, 28, 29, 30,
7601 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7602 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7603 7532
7604 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7533 DateCache* date_cache = isolate->date_cache();
7605 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7606 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7607 22, 23, 24, 25, 26, 27, 28,
7608 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7609 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7610 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7611 22, 23, 24, 25, 26, 27, 28, 29, 30,
7612 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7613 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7614 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7615 22, 23, 24, 25, 26, 27, 28, 29, 30,
7616 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7617 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7618 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7619 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7620 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7621 22, 23, 24, 25, 26, 27, 28, 29, 30,
7622 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7623 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7624 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7625 22, 23, 24, 25, 26, 27, 28, 29, 30,
7626 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7627 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7628 7534
7629 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7535 Object* value = NULL;
7630 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7536 bool is_value_nan = false;
7631 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7537 if (isnan(time)) {
7632 22, 23, 24, 25, 26, 27, 28, 29, 7538 value = isolate->heap()->nan_value();
7633 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7539 is_value_nan = true;
7634 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7540 } else {
7635 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7541 time = is_utc ? time : date_cache->ToUTC(time);
7636 22, 23, 24, 25, 26, 27, 28, 29, 30, 7542 if (time < -DateCache::kMaxTimeInMs ||
7637 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7543 time > DateCache::kMaxTimeInMs) {
7638 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7544 value = isolate->heap()->nan_value();
7639 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7545 is_value_nan = true;
rossberg 2012/03/06 15:55:50 Indentation.
ulan 2012/03/07 10:55:21 Done.
7640 22, 23, 24, 25, 26, 27, 28, 29, 30, 7546 } else {
7641 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7547 MaybeObject* maybe_result =
7642 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7548 isolate->heap()->AllocateHeapNumber(DoubleToInteger(time));
rossberg 2012/03/06 15:55:50 If is_utc is true, this allocation seems redundant
ulan 2012/03/07 10:55:21 Unfortunately we need to truncate the time (Double
7643 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7549 if (!maybe_result->ToObject(&value)) return maybe_result;
7644 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7550 }
7645 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7551 }
7646 22, 23, 24, 25, 26, 27, 28, 29, 30, 7552 date->SetValue(value, is_value_nan);
rossberg 2012/03/06 15:55:50 Why do you need the extra flag? Can't the function
ulan 2012/03/07 10:55:21 Saving one isnan computation.
7647 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7553 return *date;
7648 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7649 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7650 22, 23, 24, 25, 26, 27, 28, 29, 30,
7651 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7652 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7653
7654 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7655 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7656 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7657 22, 23, 24, 25, 26, 27, 28,
7658 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7659 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7660 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7661 22, 23, 24, 25, 26, 27, 28, 29, 30,
7662 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7663 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7664 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7665 22, 23, 24, 25, 26, 27, 28, 29, 30,
7666 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7667 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7668 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7669 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7670 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7671 22, 23, 24, 25, 26, 27, 28, 29, 30,
7672 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7673 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7674 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7675 22, 23, 24, 25, 26, 27, 28, 29, 30,
7676 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7677 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
7678
7679 static const char kMonthInYear[] = {
7680 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7681 0, 0, 0, 0, 0, 0,
7682 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7683 1, 1, 1,
7684 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7685 2, 2, 2, 2, 2, 2,
7686 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
7687 3, 3, 3, 3, 3,
7688 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7689 4, 4, 4, 4, 4, 4,
7690 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7691 5, 5, 5, 5, 5,
7692 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7693 6, 6, 6, 6, 6, 6,
7694 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7695 7, 7, 7, 7, 7, 7,
7696 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7697 8, 8, 8, 8, 8,
7698 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7699 9, 9, 9, 9, 9, 9,
7700 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7701 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7702 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7703 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7704
7705 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7706 0, 0, 0, 0, 0, 0,
7707 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7708 1, 1, 1,
7709 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7710 2, 2, 2, 2, 2, 2,
7711 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
7712 3, 3, 3, 3, 3,
7713 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7714 4, 4, 4, 4, 4, 4,
7715 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7716 5, 5, 5, 5, 5,
7717 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7718 6, 6, 6, 6, 6, 6,
7719 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7720 7, 7, 7, 7, 7, 7,
7721 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7722 8, 8, 8, 8, 8,
7723 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7724 9, 9, 9, 9, 9, 9,
7725 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7726 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7727 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7728 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7729
7730 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7731 0, 0, 0, 0, 0, 0,
7732 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7733 1, 1, 1, 1,
7734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7735 2, 2, 2, 2, 2, 2,
7736 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
7737 3, 3, 3, 3, 3,
7738 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7739 4, 4, 4, 4, 4, 4,
7740 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7741 5, 5, 5, 5, 5,
7742 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7743 6, 6, 6, 6, 6, 6,
7744 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7745 7, 7, 7, 7, 7, 7,
7746 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7747 8, 8, 8, 8, 8,
7748 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7749 9, 9, 9, 9, 9, 9,
7750 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7751 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7752 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7753 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7754
7755 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7756 0, 0, 0, 0, 0, 0,
7757 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7758 1, 1, 1,
7759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7760 2, 2, 2, 2, 2, 2,
7761 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
7762 3, 3, 3, 3, 3,
7763 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7764 4, 4, 4, 4, 4, 4,
7765 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7766 5, 5, 5, 5, 5,
7767 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7768 6, 6, 6, 6, 6, 6,
7769 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7770 7, 7, 7, 7, 7, 7,
7771 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7772 8, 8, 8, 8, 8,
7773 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7774 9, 9, 9, 9, 9, 9,
7775 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7776 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7777 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7778 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11};
7779
7780
7781 // This function works for dates from 1970 to 2099.
7782 static inline void DateYMDFromTimeAfter1970(int date,
7783 int& year, int& month, int& day) {
7784 #ifdef DEBUG
7785 int save_date = date; // Need this for ASSERT in the end.
7786 #endif
7787
7788 year = 1970 + (4 * date + 2) / kDaysIn4Years;
7789 date %= kDaysIn4Years;
7790
7791 month = kMonthInYear[date];
7792 day = kDayInYear[date];
7793
7794 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7795 } 7554 }
7796 7555
7797 7556
7798 static inline void DateYMDFromTimeSlow(int date,
7799 int& year, int& month, int& day) {
7800 #ifdef DEBUG
7801 int save_date = date; // Need this for ASSERT in the end.
7802 #endif
7803
7804 date += kDaysOffset;
7805 year = 400 * (date / kDaysIn400Years) - kYearsOffset;
7806 date %= kDaysIn400Years;
7807
7808 ASSERT(MakeDay(year, 0) + date == save_date);
7809
7810 date--;
7811 int yd1 = date / kDaysIn100Years;
7812 date %= kDaysIn100Years;
7813 year += 100 * yd1;
7814
7815 date++;
7816 int yd2 = date / kDaysIn4Years;
7817 date %= kDaysIn4Years;
7818 year += 4 * yd2;
7819
7820 date--;
7821 int yd3 = date / 365;
7822 date %= 365;
7823 year += yd3;
7824
7825 bool is_leap = (!yd1 || yd2) && !yd3;
7826
7827 ASSERT(date >= -1);
7828 ASSERT(is_leap || (date >= 0));
7829 ASSERT((date < 365) || (is_leap && (date < 366)));
7830 ASSERT(is_leap == ((year % 4 == 0) && (year % 100 || (year % 400 == 0))));
7831 ASSERT(is_leap || ((MakeDay(year, 0) + date) == save_date));
7832 ASSERT(!is_leap || ((MakeDay(year, 0) + date + 1) == save_date));
7833
7834 if (is_leap) {
7835 day = kDayInYear[2*365 + 1 + date];
7836 month = kMonthInYear[2*365 + 1 + date];
7837 } else {
7838 day = kDayInYear[date];
7839 month = kMonthInYear[date];
7840 }
7841
7842 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7843 }
7844
7845
7846 static inline void DateYMDFromTime(int date,
7847 int& year, int& month, int& day) {
7848 if (date >= 0 && date < 32 * kDaysIn4Years) {
7849 DateYMDFromTimeAfter1970(date, year, month, day);
7850 } else {
7851 DateYMDFromTimeSlow(date, year, month, day);
7852 }
7853 }
7854
7855
7856 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateYMDFromTime) {
7857 NoHandleAllocation ha;
7858 ASSERT(args.length() == 2);
7859
7860 CONVERT_DOUBLE_ARG_CHECKED(t, 0);
7861 CONVERT_ARG_CHECKED(JSArray, res_array, 1);
7862
7863 int year, month, day;
7864 DateYMDFromTime(static_cast<int>(floor(t / 86400000)), year, month, day);
7865
7866 FixedArrayBase* elms_base = FixedArrayBase::cast(res_array->elements());
7867 RUNTIME_ASSERT(elms_base->length() == 3);
7868 RUNTIME_ASSERT(res_array->HasFastTypeElements());
7869
7870 MaybeObject* maybe = res_array->EnsureWritableFastElements();
7871 if (maybe->IsFailure()) return maybe;
7872 FixedArray* elms = FixedArray::cast(res_array->elements());
7873 elms->set(0, Smi::FromInt(year));
7874 elms->set(1, Smi::FromInt(month));
7875 elms->set(2, Smi::FromInt(day));
7876
7877 return isolate->heap()->undefined_value();
7878 }
7879
7880
7881 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewArgumentsFast) { 7557 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewArgumentsFast) {
7882 HandleScope scope(isolate); 7558 HandleScope scope(isolate);
7883 ASSERT(args.length() == 3); 7559 ASSERT(args.length() == 3);
7884 7560
7885 Handle<JSFunction> callee = args.at<JSFunction>(0); 7561 Handle<JSFunction> callee = args.at<JSFunction>(0);
7886 Object** parameters = reinterpret_cast<Object**>(args[1]); 7562 Object** parameters = reinterpret_cast<Object**>(args[1]);
7887 const int argument_count = Smi::cast(args[2])->value(); 7563 const int argument_count = Smi::cast(args[2])->value();
7888 7564
7889 Handle<JSObject> result = 7565 Handle<JSObject> result =
7890 isolate->factory()->NewArgumentsObject(callee, argument_count); 7566 isolate->factory()->NewArgumentsObject(callee, argument_count);
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
9343 return isolate->heap()->null_value(); 9019 return isolate->heap()->null_value();
9344 } 9020 }
9345 } 9021 }
9346 9022
9347 9023
9348 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) { 9024 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) {
9349 NoHandleAllocation ha; 9025 NoHandleAllocation ha;
9350 ASSERT(args.length() == 1); 9026 ASSERT(args.length() == 1);
9351 9027
9352 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9028 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9353 const char* zone = OS::LocalTimezone(x); 9029 int64_t time = isolate->date_cache()->EquivalentTime(static_cast<int64_t>(x));
9030 const char* zone = OS::LocalTimezone(static_cast<double>(time));
rossberg 2012/03/06 15:55:50 Do these conversions (here and below) actually req
ulan 2012/03/07 10:55:21 Done.
9354 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone)); 9031 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone));
9355 } 9032 }
9356 9033
9357 9034
9358 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimeOffset) { 9035 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateToUTC) {
9359 NoHandleAllocation ha;
9360 ASSERT(args.length() == 0);
9361
9362 return isolate->heap()->NumberFromDouble(OS::LocalTimeOffset());
9363 }
9364
9365
9366 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateDaylightSavingsOffset) {
9367 NoHandleAllocation ha; 9036 NoHandleAllocation ha;
9368 ASSERT(args.length() == 1); 9037 ASSERT(args.length() == 1);
9369 9038
9370 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9039 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9371 return isolate->heap()->NumberFromDouble(OS::DaylightSavingsOffset(x)); 9040 int64_t time_ms = isolate->date_cache()->ToUTC(static_cast<int64_t>(x));
9041
9042 return isolate->heap()->NumberFromDouble(static_cast<double>(time_ms));
9372 } 9043 }
9373 9044
9374 9045
9375 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) { 9046 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) {
9376 ASSERT(args.length() == 1); 9047 ASSERT(args.length() == 1);
9377 Object* global = args[0]; 9048 Object* global = args[0];
9378 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); 9049 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value();
9379 return JSGlobalObject::cast(global)->global_receiver(); 9050 return JSGlobalObject::cast(global)->global_receiver();
9380 } 9051 }
9381 9052
(...skipping 4239 matching lines...) Expand 10 before | Expand all | Expand 10 after
13621 // Handle last resort GC and make sure to allow future allocations 13292 // Handle last resort GC and make sure to allow future allocations
13622 // to grow the heap without causing GCs (if possible). 13293 // to grow the heap without causing GCs (if possible).
13623 isolate->counters()->gc_last_resort_from_js()->Increment(); 13294 isolate->counters()->gc_last_resort_from_js()->Increment();
13624 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13295 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13625 "Runtime::PerformGC"); 13296 "Runtime::PerformGC");
13626 } 13297 }
13627 } 13298 }
13628 13299
13629 13300
13630 } } // namespace v8::internal 13301 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698