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

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: Rebase 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
« no previous file with comments | « src/runtime.h ('k') | src/serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7482 matching lines...) Expand 10 before | Expand all | Expand 10 after
7535 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { 7536 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) {
7536 NoHandleAllocation ha; 7537 NoHandleAllocation ha;
7537 ASSERT(args.length() == 1); 7538 ASSERT(args.length() == 1);
7538 isolate->counters()->math_tan()->Increment(); 7539 isolate->counters()->math_tan()->Increment();
7539 7540
7540 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7541 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7541 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x); 7542 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
7542 } 7543 }
7543 7544
7544 7545
7545 static int MakeDay(int year, int month) {
7546 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
7547 181, 212, 243, 273, 304, 334};
7548 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
7549 182, 213, 244, 274, 305, 335};
7550
7551 year += month / 12;
7552 month %= 12;
7553 if (month < 0) {
7554 year--;
7555 month += 12;
7556 }
7557
7558 ASSERT(month >= 0);
7559 ASSERT(month < 12);
7560
7561 // year_delta is an arbitrary number such that:
7562 // a) year_delta = -1 (mod 400)
7563 // b) year + year_delta > 0 for years in the range defined by
7564 // ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of
7565 // Jan 1 1970. This is required so that we don't run into integer
7566 // division of negative numbers.
7567 // c) there shouldn't be an overflow for 32-bit integers in the following
7568 // operations.
7569 static const int year_delta = 399999;
7570 static const int base_day = 365 * (1970 + year_delta) +
7571 (1970 + year_delta) / 4 -
7572 (1970 + year_delta) / 100 +
7573 (1970 + year_delta) / 400;
7574
7575 int year1 = year + year_delta;
7576 int day_from_year = 365 * year1 +
7577 year1 / 4 -
7578 year1 / 100 +
7579 year1 / 400 -
7580 base_day;
7581
7582 if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
7583 return day_from_year + day_from_month[month];
7584 }
7585
7586 return day_from_year + day_from_month_leap[month];
7587 }
7588
7589
7590 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { 7546 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) {
7591 NoHandleAllocation ha; 7547 NoHandleAllocation ha;
7592 ASSERT(args.length() == 2); 7548 ASSERT(args.length() == 2);
7593 7549
7594 CONVERT_SMI_ARG_CHECKED(year, 0); 7550 CONVERT_SMI_ARG_CHECKED(year, 0);
7595 CONVERT_SMI_ARG_CHECKED(month, 1); 7551 CONVERT_SMI_ARG_CHECKED(month, 1);
7596 7552
7597 return Smi::FromInt(MakeDay(year, month)); 7553 return Smi::FromInt(isolate->date_cache()->DaysFromYearMonth(year, month));
7598 } 7554 }
7599 7555
7600 7556
7601 static const int kDays4Years[] = {0, 365, 2 * 365, 3 * 365 + 1}; 7557 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateSetValue) {
7602 static const int kDaysIn4Years = 4 * 365 + 1; 7558 HandleScope scope(isolate);
7603 static const int kDaysIn100Years = 25 * kDaysIn4Years - 1; 7559 ASSERT(args.length() == 3);
7604 static const int kDaysIn400Years = 4 * kDaysIn100Years + 1;
7605 static const int kDays1970to2000 = 30 * 365 + 7;
7606 static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years -
7607 kDays1970to2000;
7608 static const int kYearsOffset = 400000;
7609 7560
7610 static const char kDayInYear[] = { 7561 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 0);
7611 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7562 CONVERT_DOUBLE_ARG_CHECKED(time, 1);
7612 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7563 CONVERT_SMI_ARG_CHECKED(is_utc, 2);
7613 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7614 22, 23, 24, 25, 26, 27, 28,
7615 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7616 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7617 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7618 22, 23, 24, 25, 26, 27, 28, 29, 30,
7619 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7620 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7621 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7622 22, 23, 24, 25, 26, 27, 28, 29, 30,
7623 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7624 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7625 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7626 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7627 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7628 22, 23, 24, 25, 26, 27, 28, 29, 30,
7629 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7630 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7631 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7632 22, 23, 24, 25, 26, 27, 28, 29, 30,
7633 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7634 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7635 7564
7636 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7565 DateCache* date_cache = isolate->date_cache();
7637 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7638 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7639 22, 23, 24, 25, 26, 27, 28,
7640 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7641 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7642 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7643 22, 23, 24, 25, 26, 27, 28, 29, 30,
7644 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7645 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7646 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7647 22, 23, 24, 25, 26, 27, 28, 29, 30,
7648 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7649 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7650 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7651 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7652 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7653 22, 23, 24, 25, 26, 27, 28, 29, 30,
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, 29, 30,
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 7566
7661 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7567 Object* value = NULL;
7662 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7568 bool is_value_nan = false;
7663 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7569 if (isnan(time)) {
7664 22, 23, 24, 25, 26, 27, 28, 29, 7570 value = isolate->heap()->nan_value();
7665 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7571 is_value_nan = true;
7666 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7572 } else {
7667 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7573 time = is_utc ? time : date_cache->ToUTC(time);
7668 22, 23, 24, 25, 26, 27, 28, 29, 30, 7574 if (time < -DateCache::kMaxTimeInMs ||
7669 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7575 time > DateCache::kMaxTimeInMs) {
7670 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7576 value = isolate->heap()->nan_value();
7671 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7577 is_value_nan = true;
7672 22, 23, 24, 25, 26, 27, 28, 29, 30, 7578 } else {
7673 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7579 MaybeObject* maybe_result =
7674 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7580 isolate->heap()->AllocateHeapNumber(DoubleToInteger(time));
7675 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7581 if (!maybe_result->ToObject(&value)) return maybe_result;
7676 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 7582 }
7677 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7583 }
7678 22, 23, 24, 25, 26, 27, 28, 29, 30, 7584 date->SetValue(value, is_value_nan);
7679 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7585 return *date;
7680 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7681 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7682 22, 23, 24, 25, 26, 27, 28, 29, 30,
7683 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7684 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7685
7686 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7687 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7688 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7689 22, 23, 24, 25, 26, 27, 28,
7690 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7691 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7692 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7693 22, 23, 24, 25, 26, 27, 28, 29, 30,
7694 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7695 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7696 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7697 22, 23, 24, 25, 26, 27, 28, 29, 30,
7698 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7699 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7700 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7701 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7702 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7703 22, 23, 24, 25, 26, 27, 28, 29, 30,
7704 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7705 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
7706 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7707 22, 23, 24, 25, 26, 27, 28, 29, 30,
7708 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
7709 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
7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8, 8, 8, 8, 8,
7755 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,
7756 9, 9, 9, 9, 9, 9,
7757 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7758 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7759 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7760 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7761
7762 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,
7763 0, 0, 0, 0, 0, 0,
7764 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,
7765 1, 1, 1, 1,
7766 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,
7767 2, 2, 2, 2, 2, 2,
7768 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,
7769 3, 3, 3, 3, 3,
7770 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,
7771 4, 4, 4, 4, 4, 4,
7772 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,
7773 5, 5, 5, 5, 5,
7774 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,
7775 6, 6, 6, 6, 6, 6,
7776 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,
7777 7, 7, 7, 7, 7, 7,
7778 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,
7779 8, 8, 8, 8, 8,
7780 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,
7781 9, 9, 9, 9, 9, 9,
7782 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7783 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7784 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7785 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7786
7787 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,
7788 0, 0, 0, 0, 0, 0,
7789 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,
7790 1, 1, 1,
7791 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,
7792 2, 2, 2, 2, 2, 2,
7793 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,
7794 3, 3, 3, 3, 3,
7795 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,
7796 4, 4, 4, 4, 4, 4,
7797 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,
7798 5, 5, 5, 5, 5,
7799 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,
7800 6, 6, 6, 6, 6, 6,
7801 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,
7802 7, 7, 7, 7, 7, 7,
7803 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,
7804 8, 8, 8, 8, 8,
7805 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,
7806 9, 9, 9, 9, 9, 9,
7807 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7808 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
7809 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7810 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11};
7811
7812
7813 // This function works for dates from 1970 to 2099.
7814 static inline void DateYMDFromTimeAfter1970(int date,
7815 int& year, int& month, int& day) {
7816 #ifdef DEBUG
7817 int save_date = date; // Need this for ASSERT in the end.
7818 #endif
7819
7820 year = 1970 + (4 * date + 2) / kDaysIn4Years;
7821 date %= kDaysIn4Years;
7822
7823 month = kMonthInYear[date];
7824 day = kDayInYear[date];
7825
7826 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7827 } 7586 }
7828 7587
7829 7588
7830 static inline void DateYMDFromTimeSlow(int date,
7831 int& year, int& month, int& day) {
7832 #ifdef DEBUG
7833 int save_date = date; // Need this for ASSERT in the end.
7834 #endif
7835
7836 date += kDaysOffset;
7837 year = 400 * (date / kDaysIn400Years) - kYearsOffset;
7838 date %= kDaysIn400Years;
7839
7840 ASSERT(MakeDay(year, 0) + date == save_date);
7841
7842 date--;
7843 int yd1 = date / kDaysIn100Years;
7844 date %= kDaysIn100Years;
7845 year += 100 * yd1;
7846
7847 date++;
7848 int yd2 = date / kDaysIn4Years;
7849 date %= kDaysIn4Years;
7850 year += 4 * yd2;
7851
7852 date--;
7853 int yd3 = date / 365;
7854 date %= 365;
7855 year += yd3;
7856
7857 bool is_leap = (!yd1 || yd2) && !yd3;
7858
7859 ASSERT(date >= -1);
7860 ASSERT(is_leap || (date >= 0));
7861 ASSERT((date < 365) || (is_leap && (date < 366)));
7862 ASSERT(is_leap == ((year % 4 == 0) && (year % 100 || (year % 400 == 0))));
7863 ASSERT(is_leap || ((MakeDay(year, 0) + date) == save_date));
7864 ASSERT(!is_leap || ((MakeDay(year, 0) + date + 1) == save_date));
7865
7866 if (is_leap) {
7867 day = kDayInYear[2*365 + 1 + date];
7868 month = kMonthInYear[2*365 + 1 + date];
7869 } else {
7870 day = kDayInYear[date];
7871 month = kMonthInYear[date];
7872 }
7873
7874 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7875 }
7876
7877
7878 static inline void DateYMDFromTime(int date,
7879 int& year, int& month, int& day) {
7880 if (date >= 0 && date < 32 * kDaysIn4Years) {
7881 DateYMDFromTimeAfter1970(date, year, month, day);
7882 } else {
7883 DateYMDFromTimeSlow(date, year, month, day);
7884 }
7885 }
7886
7887
7888 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateYMDFromTime) {
7889 NoHandleAllocation ha;
7890 ASSERT(args.length() == 2);
7891
7892 CONVERT_DOUBLE_ARG_CHECKED(t, 0);
7893 CONVERT_ARG_CHECKED(JSArray, res_array, 1);
7894
7895 int year, month, day;
7896 DateYMDFromTime(static_cast<int>(floor(t / 86400000)), year, month, day);
7897
7898 FixedArrayBase* elms_base = FixedArrayBase::cast(res_array->elements());
7899 RUNTIME_ASSERT(elms_base->length() == 3);
7900 RUNTIME_ASSERT(res_array->HasFastTypeElements());
7901
7902 MaybeObject* maybe = res_array->EnsureWritableFastElements();
7903 if (maybe->IsFailure()) return maybe;
7904 FixedArray* elms = FixedArray::cast(res_array->elements());
7905 elms->set(0, Smi::FromInt(year));
7906 elms->set(1, Smi::FromInt(month));
7907 elms->set(2, Smi::FromInt(day));
7908
7909 return isolate->heap()->undefined_value();
7910 }
7911
7912
7913 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewArgumentsFast) { 7589 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewArgumentsFast) {
7914 HandleScope scope(isolate); 7590 HandleScope scope(isolate);
7915 ASSERT(args.length() == 3); 7591 ASSERT(args.length() == 3);
7916 7592
7917 Handle<JSFunction> callee = args.at<JSFunction>(0); 7593 Handle<JSFunction> callee = args.at<JSFunction>(0);
7918 Object** parameters = reinterpret_cast<Object**>(args[1]); 7594 Object** parameters = reinterpret_cast<Object**>(args[1]);
7919 const int argument_count = Smi::cast(args[2])->value(); 7595 const int argument_count = Smi::cast(args[2])->value();
7920 7596
7921 Handle<JSObject> result = 7597 Handle<JSObject> result =
7922 isolate->factory()->NewArgumentsObject(callee, argument_count); 7598 isolate->factory()->NewArgumentsObject(callee, argument_count);
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
9375 return isolate->heap()->null_value(); 9051 return isolate->heap()->null_value();
9376 } 9052 }
9377 } 9053 }
9378 9054
9379 9055
9380 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) { 9056 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimezone) {
9381 NoHandleAllocation ha; 9057 NoHandleAllocation ha;
9382 ASSERT(args.length() == 1); 9058 ASSERT(args.length() == 1);
9383 9059
9384 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9060 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9385 const char* zone = OS::LocalTimezone(x); 9061 int64_t time = isolate->date_cache()->EquivalentTime(static_cast<int64_t>(x));
9062 const char* zone = OS::LocalTimezone(time);
9386 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone)); 9063 return isolate->heap()->AllocateStringFromUtf8(CStrVector(zone));
9387 } 9064 }
9388 9065
9389 9066
9390 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateLocalTimeOffset) { 9067 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateToUTC) {
9391 NoHandleAllocation ha;
9392 ASSERT(args.length() == 0);
9393
9394 return isolate->heap()->NumberFromDouble(OS::LocalTimeOffset());
9395 }
9396
9397
9398 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateDaylightSavingsOffset) {
9399 NoHandleAllocation ha; 9068 NoHandleAllocation ha;
9400 ASSERT(args.length() == 1); 9069 ASSERT(args.length() == 1);
9401 9070
9402 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 9071 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
9403 return isolate->heap()->NumberFromDouble(OS::DaylightSavingsOffset(x)); 9072 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x));
9073
9074 return isolate->heap()->NumberFromDouble(time);
9404 } 9075 }
9405 9076
9406 9077
9407 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) { 9078 RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalReceiver) {
9408 ASSERT(args.length() == 1); 9079 ASSERT(args.length() == 1);
9409 Object* global = args[0]; 9080 Object* global = args[0];
9410 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value(); 9081 if (!global->IsJSGlobalObject()) return isolate->heap()->null_value();
9411 return JSGlobalObject::cast(global)->global_receiver(); 9082 return JSGlobalObject::cast(global)->global_receiver();
9412 } 9083 }
9413 9084
(...skipping 4231 matching lines...) Expand 10 before | Expand all | Expand 10 after
13645 // Handle last resort GC and make sure to allow future allocations 13316 // Handle last resort GC and make sure to allow future allocations
13646 // to grow the heap without causing GCs (if possible). 13317 // to grow the heap without causing GCs (if possible).
13647 isolate->counters()->gc_last_resort_from_js()->Increment(); 13318 isolate->counters()->gc_last_resort_from_js()->Increment();
13648 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13319 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13649 "Runtime::PerformGC"); 13320 "Runtime::PerformGC");
13650 } 13321 }
13651 } 13322 }
13652 13323
13653 13324
13654 } } // namespace v8::internal 13325 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698