OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "api.h" | 30 #include "api.h" |
31 #include "arguments.h" | 31 #include "arguments.h" |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "codegen.h" | 33 #include "codegen.h" |
34 #include "debug.h" | 34 #include "debug.h" |
35 #include "deoptimizer.h" | 35 #include "deoptimizer.h" |
| 36 #include "date.h" |
36 #include "elements.h" | 37 #include "elements.h" |
37 #include "execution.h" | 38 #include "execution.h" |
38 #include "full-codegen.h" | 39 #include "full-codegen.h" |
39 #include "hydrogen.h" | 40 #include "hydrogen.h" |
40 #include "objects-inl.h" | 41 #include "objects-inl.h" |
41 #include "objects-visiting.h" | 42 #include "objects-visiting.h" |
42 #include "objects-visiting-inl.h" | 43 #include "objects-visiting-inl.h" |
43 #include "macro-assembler.h" | 44 #include "macro-assembler.h" |
44 #include "mark-compact.h" | 45 #include "mark-compact.h" |
45 #include "safepoint-table.h" | 46 #include "safepoint-table.h" |
(...skipping 12917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12963 // No break point. | 12964 // No break point. |
12964 if (break_point_objects()->IsUndefined()) return 0; | 12965 if (break_point_objects()->IsUndefined()) return 0; |
12965 // Single break point. | 12966 // Single break point. |
12966 if (!break_point_objects()->IsFixedArray()) return 1; | 12967 if (!break_point_objects()->IsFixedArray()) return 1; |
12967 // Multiple break points. | 12968 // Multiple break points. |
12968 return FixedArray::cast(break_point_objects())->length(); | 12969 return FixedArray::cast(break_point_objects())->length(); |
12969 } | 12970 } |
12970 #endif // ENABLE_DEBUGGER_SUPPORT | 12971 #endif // ENABLE_DEBUGGER_SUPPORT |
12971 | 12972 |
12972 | 12973 |
| 12974 MaybeObject* JSDate::GetField(Object* object, Smi* index) { |
| 12975 return JSDate::cast(object)->DoGetField( |
| 12976 static_cast<FieldIndex>(index->value())); |
| 12977 } |
| 12978 |
| 12979 |
| 12980 Object* JSDate::DoGetField(FieldIndex index) { |
| 12981 ASSERT(index != kDateValue); |
| 12982 |
| 12983 DateCache* date_cache = GetIsolate()->date_cache(); |
| 12984 |
| 12985 if (index < kFirstUncachedField) { |
| 12986 Object* stamp = cache_stamp(); |
| 12987 if (stamp != date_cache->stamp() && stamp->IsSmi()) { |
| 12988 // Since the stamp is not NaN, the value is also not NaN. |
| 12989 int64_t local_time_ms = |
| 12990 static_cast<int64_t>(date_cache->ToLocal(value()->Number())); |
| 12991 SetLocalFields(local_time_ms, date_cache); |
| 12992 } |
| 12993 switch (index) { |
| 12994 case kYear: return year(); |
| 12995 case kMonth: return month(); |
| 12996 case kDay: return day(); |
| 12997 case kWeekday: return weekday(); |
| 12998 case kHour: return hour(); |
| 12999 case kMinute: return min(); |
| 13000 case kSecond: return sec(); |
| 13001 default: UNREACHABLE(); |
| 13002 } |
| 13003 } |
| 13004 |
| 13005 if (index >= kFirstUTCField) { |
| 13006 return GetUTCField(index, value()->Number(), date_cache); |
| 13007 } |
| 13008 |
| 13009 double time = value()->Number(); |
| 13010 if (isnan(time)) return GetIsolate()->heap()->nan_value(); |
| 13011 |
| 13012 int64_t local_time_ms = static_cast<int64_t>(date_cache->ToLocal(time)); |
| 13013 int days = DateCache::DaysFromTime(local_time_ms); |
| 13014 |
| 13015 if (index == kDays) return Smi::FromInt(days); |
| 13016 |
| 13017 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); |
| 13018 if (index == kMillisecond) return Smi::FromInt(time_in_day_ms % 1000); |
| 13019 ASSERT(index == kTimeInDay); |
| 13020 return Smi::FromInt(time_in_day_ms); |
| 13021 } |
| 13022 |
| 13023 |
| 13024 Object* JSDate::GetUTCField(FieldIndex index, |
| 13025 double value, |
| 13026 DateCache* date_cache) { |
| 13027 ASSERT(index >= kFirstUTCField); |
| 13028 |
| 13029 if (isnan(value)) return GetIsolate()->heap()->nan_value(); |
| 13030 |
| 13031 int64_t time_ms = static_cast<int64_t>(value); |
| 13032 |
| 13033 if (index == kTimezoneOffset) { |
| 13034 return Smi::FromInt(date_cache->TimezoneOffset(time_ms)); |
| 13035 } |
| 13036 |
| 13037 int days = DateCache::DaysFromTime(time_ms); |
| 13038 |
| 13039 if (index == kWeekdayUTC) return Smi::FromInt(date_cache->Weekday(days)); |
| 13040 |
| 13041 if (index <= kDayUTC) { |
| 13042 int year, month, day; |
| 13043 date_cache->YearMonthDayFromDays(days, &year, &month, &day); |
| 13044 if (index == kYearUTC) return Smi::FromInt(year); |
| 13045 if (index == kMonthUTC) return Smi::FromInt(month); |
| 13046 ASSERT(index == kDayUTC); |
| 13047 return Smi::FromInt(day); |
| 13048 } |
| 13049 |
| 13050 int time_in_day_ms = DateCache::TimeInDay(time_ms, days); |
| 13051 switch (index) { |
| 13052 case kHourUTC: return Smi::FromInt(time_in_day_ms / (60 * 60 * 1000)); |
| 13053 case kMinuteUTC: return Smi::FromInt((time_in_day_ms / (60 * 1000)) % 60); |
| 13054 case kSecondUTC: return Smi::FromInt((time_in_day_ms / 1000) % 60); |
| 13055 case kMillisecondUTC: return Smi::FromInt(time_in_day_ms % 1000); |
| 13056 case kDaysUTC: return Smi::FromInt(days); |
| 13057 case kTimeInDayUTC: return Smi::FromInt(time_in_day_ms); |
| 13058 default: UNREACHABLE(); |
| 13059 } |
| 13060 |
| 13061 UNREACHABLE(); |
| 13062 return NULL; |
| 13063 } |
| 13064 |
| 13065 |
| 13066 void JSDate::SetValue(Object* value, bool is_value_nan) { |
| 13067 set_value(value); |
| 13068 if (is_value_nan) { |
| 13069 HeapNumber* nan = GetIsolate()->heap()->nan_value(); |
| 13070 set_cache_stamp(nan, SKIP_WRITE_BARRIER); |
| 13071 set_year(nan, SKIP_WRITE_BARRIER); |
| 13072 set_month(nan, SKIP_WRITE_BARRIER); |
| 13073 set_day(nan, SKIP_WRITE_BARRIER); |
| 13074 set_hour(nan, SKIP_WRITE_BARRIER); |
| 13075 set_min(nan, SKIP_WRITE_BARRIER); |
| 13076 set_sec(nan, SKIP_WRITE_BARRIER); |
| 13077 set_weekday(nan, SKIP_WRITE_BARRIER); |
| 13078 } else { |
| 13079 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); |
| 13080 } |
| 13081 } |
| 13082 |
| 13083 |
| 13084 void JSDate::SetLocalFields(int64_t local_time_ms, DateCache* date_cache) { |
| 13085 int days = DateCache::DaysFromTime(local_time_ms); |
| 13086 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); |
| 13087 int year, month, day; |
| 13088 date_cache->YearMonthDayFromDays(days, &year, &month, &day); |
| 13089 int weekday = date_cache->Weekday(days); |
| 13090 int hour = time_in_day_ms / (60 * 60 * 1000); |
| 13091 int min = (time_in_day_ms / (60 * 1000)) % 60; |
| 13092 int sec = (time_in_day_ms / 1000) % 60; |
| 13093 set_cache_stamp(date_cache->stamp()); |
| 13094 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 13095 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 13096 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 13097 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 13098 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 13099 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 13100 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 13101 } |
| 13102 |
12973 } } // namespace v8::internal | 13103 } } // namespace v8::internal |
OLD | NEW |