| 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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 accumulator->Put('>'); | 1106 accumulator->Put('>'); |
| 1106 } | 1107 } |
| 1107 return; | 1108 return; |
| 1108 } | 1109 } |
| 1109 | 1110 |
| 1110 | 1111 |
| 1111 void JSObject::JSObjectShortPrint(StringStream* accumulator) { | 1112 void JSObject::JSObjectShortPrint(StringStream* accumulator) { |
| 1112 switch (map()->instance_type()) { | 1113 switch (map()->instance_type()) { |
| 1113 case JS_ARRAY_TYPE: { | 1114 case JS_ARRAY_TYPE: { |
| 1114 double length = JSArray::cast(this)->length()->Number(); | 1115 double length = JSArray::cast(this)->length()->Number(); |
| 1115 accumulator->Add("<JS array[%u]>", static_cast<uint32_t>(length)); | 1116 accumulator->Add("<JS Array[%u]>", static_cast<uint32_t>(length)); |
| 1116 break; | 1117 break; |
| 1117 } | 1118 } |
| 1118 case JS_WEAK_MAP_TYPE: { | 1119 case JS_WEAK_MAP_TYPE: { |
| 1119 accumulator->Add("<JS WeakMap>"); | 1120 accumulator->Add("<JS WeakMap>"); |
| 1120 break; | 1121 break; |
| 1121 } | 1122 } |
| 1122 case JS_REGEXP_TYPE: { | 1123 case JS_REGEXP_TYPE: { |
| 1123 accumulator->Add("<JS RegExp>"); | 1124 accumulator->Add("<JS RegExp>"); |
| 1124 break; | 1125 break; |
| 1125 } | 1126 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 | 1377 |
| 1377 switch (type) { | 1378 switch (type) { |
| 1378 case FIXED_ARRAY_TYPE: | 1379 case FIXED_ARRAY_TYPE: |
| 1379 FixedArray::BodyDescriptor::IterateBody(this, object_size, v); | 1380 FixedArray::BodyDescriptor::IterateBody(this, object_size, v); |
| 1380 break; | 1381 break; |
| 1381 case FIXED_DOUBLE_ARRAY_TYPE: | 1382 case FIXED_DOUBLE_ARRAY_TYPE: |
| 1382 break; | 1383 break; |
| 1383 case JS_OBJECT_TYPE: | 1384 case JS_OBJECT_TYPE: |
| 1384 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: | 1385 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 1385 case JS_VALUE_TYPE: | 1386 case JS_VALUE_TYPE: |
| 1387 case JS_DATE_TYPE: |
| 1386 case JS_ARRAY_TYPE: | 1388 case JS_ARRAY_TYPE: |
| 1387 case JS_SET_TYPE: | 1389 case JS_SET_TYPE: |
| 1388 case JS_MAP_TYPE: | 1390 case JS_MAP_TYPE: |
| 1389 case JS_WEAK_MAP_TYPE: | 1391 case JS_WEAK_MAP_TYPE: |
| 1390 case JS_REGEXP_TYPE: | 1392 case JS_REGEXP_TYPE: |
| 1391 case JS_GLOBAL_PROXY_TYPE: | 1393 case JS_GLOBAL_PROXY_TYPE: |
| 1392 case JS_GLOBAL_OBJECT_TYPE: | 1394 case JS_GLOBAL_OBJECT_TYPE: |
| 1393 case JS_BUILTINS_OBJECT_TYPE: | 1395 case JS_BUILTINS_OBJECT_TYPE: |
| 1394 case JS_MESSAGE_OBJECT_TYPE: | 1396 case JS_MESSAGE_OBJECT_TYPE: |
| 1395 JSObject::BodyDescriptor::IterateBody(this, object_size, v); | 1397 JSObject::BodyDescriptor::IterateBody(this, object_size, v); |
| (...skipping 11772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13168 // No break point. | 13170 // No break point. |
| 13169 if (break_point_objects()->IsUndefined()) return 0; | 13171 if (break_point_objects()->IsUndefined()) return 0; |
| 13170 // Single break point. | 13172 // Single break point. |
| 13171 if (!break_point_objects()->IsFixedArray()) return 1; | 13173 if (!break_point_objects()->IsFixedArray()) return 1; |
| 13172 // Multiple break points. | 13174 // Multiple break points. |
| 13173 return FixedArray::cast(break_point_objects())->length(); | 13175 return FixedArray::cast(break_point_objects())->length(); |
| 13174 } | 13176 } |
| 13175 #endif // ENABLE_DEBUGGER_SUPPORT | 13177 #endif // ENABLE_DEBUGGER_SUPPORT |
| 13176 | 13178 |
| 13177 | 13179 |
| 13180 MaybeObject* JSDate::GetField(Object* object, Smi* index) { |
| 13181 return JSDate::cast(object)->DoGetField( |
| 13182 static_cast<FieldIndex>(index->value())); |
| 13183 } |
| 13184 |
| 13185 |
| 13186 Object* JSDate::DoGetField(FieldIndex index) { |
| 13187 ASSERT(index != kDateValue); |
| 13188 |
| 13189 DateCache* date_cache = GetIsolate()->date_cache(); |
| 13190 |
| 13191 if (index < kFirstUncachedField) { |
| 13192 Object* stamp = cache_stamp(); |
| 13193 if (stamp != date_cache->stamp() && stamp->IsSmi()) { |
| 13194 // Since the stamp is not NaN, the value is also not NaN. |
| 13195 int64_t local_time_ms = |
| 13196 static_cast<int64_t>(date_cache->ToLocal(value()->Number())); |
| 13197 SetLocalFields(local_time_ms, date_cache); |
| 13198 } |
| 13199 switch (index) { |
| 13200 case kYear: return year(); |
| 13201 case kMonth: return month(); |
| 13202 case kDay: return day(); |
| 13203 case kWeekday: return weekday(); |
| 13204 case kHour: return hour(); |
| 13205 case kMinute: return min(); |
| 13206 case kSecond: return sec(); |
| 13207 default: UNREACHABLE(); |
| 13208 } |
| 13209 } |
| 13210 |
| 13211 if (index >= kFirstUTCField) { |
| 13212 return GetUTCField(index, value()->Number(), date_cache); |
| 13213 } |
| 13214 |
| 13215 double time = value()->Number(); |
| 13216 if (isnan(time)) return GetIsolate()->heap()->nan_value(); |
| 13217 |
| 13218 int64_t local_time_ms = static_cast<int64_t>(date_cache->ToLocal(time)); |
| 13219 int days = DateCache::DaysFromTime(local_time_ms); |
| 13220 |
| 13221 if (index == kDays) return Smi::FromInt(days); |
| 13222 |
| 13223 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); |
| 13224 if (index == kMillisecond) return Smi::FromInt(time_in_day_ms % 1000); |
| 13225 ASSERT(index == kTimeInDay); |
| 13226 return Smi::FromInt(time_in_day_ms); |
| 13227 } |
| 13228 |
| 13229 |
| 13230 Object* JSDate::GetUTCField(FieldIndex index, |
| 13231 double value, |
| 13232 DateCache* date_cache) { |
| 13233 ASSERT(index >= kFirstUTCField); |
| 13234 |
| 13235 if (isnan(value)) return GetIsolate()->heap()->nan_value(); |
| 13236 |
| 13237 int64_t time_ms = static_cast<int64_t>(value); |
| 13238 |
| 13239 if (index == kTimezoneOffset) { |
| 13240 return Smi::FromInt(date_cache->TimezoneOffset(time_ms)); |
| 13241 } |
| 13242 |
| 13243 int days = DateCache::DaysFromTime(time_ms); |
| 13244 |
| 13245 if (index == kWeekdayUTC) return Smi::FromInt(date_cache->Weekday(days)); |
| 13246 |
| 13247 if (index <= kDayUTC) { |
| 13248 int year, month, day; |
| 13249 date_cache->YearMonthDayFromDays(days, &year, &month, &day); |
| 13250 if (index == kYearUTC) return Smi::FromInt(year); |
| 13251 if (index == kMonthUTC) return Smi::FromInt(month); |
| 13252 ASSERT(index == kDayUTC); |
| 13253 return Smi::FromInt(day); |
| 13254 } |
| 13255 |
| 13256 int time_in_day_ms = DateCache::TimeInDay(time_ms, days); |
| 13257 switch (index) { |
| 13258 case kHourUTC: return Smi::FromInt(time_in_day_ms / (60 * 60 * 1000)); |
| 13259 case kMinuteUTC: return Smi::FromInt((time_in_day_ms / (60 * 1000)) % 60); |
| 13260 case kSecondUTC: return Smi::FromInt((time_in_day_ms / 1000) % 60); |
| 13261 case kMillisecondUTC: return Smi::FromInt(time_in_day_ms % 1000); |
| 13262 case kDaysUTC: return Smi::FromInt(days); |
| 13263 case kTimeInDayUTC: return Smi::FromInt(time_in_day_ms); |
| 13264 default: UNREACHABLE(); |
| 13265 } |
| 13266 |
| 13267 UNREACHABLE(); |
| 13268 return NULL; |
| 13269 } |
| 13270 |
| 13271 |
| 13272 void JSDate::SetValue(Object* value, bool is_value_nan) { |
| 13273 set_value(value); |
| 13274 if (is_value_nan) { |
| 13275 HeapNumber* nan = GetIsolate()->heap()->nan_value(); |
| 13276 set_cache_stamp(nan, SKIP_WRITE_BARRIER); |
| 13277 set_year(nan, SKIP_WRITE_BARRIER); |
| 13278 set_month(nan, SKIP_WRITE_BARRIER); |
| 13279 set_day(nan, SKIP_WRITE_BARRIER); |
| 13280 set_hour(nan, SKIP_WRITE_BARRIER); |
| 13281 set_min(nan, SKIP_WRITE_BARRIER); |
| 13282 set_sec(nan, SKIP_WRITE_BARRIER); |
| 13283 set_weekday(nan, SKIP_WRITE_BARRIER); |
| 13284 } else { |
| 13285 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); |
| 13286 } |
| 13287 } |
| 13288 |
| 13289 |
| 13290 void JSDate::SetLocalFields(int64_t local_time_ms, DateCache* date_cache) { |
| 13291 int days = DateCache::DaysFromTime(local_time_ms); |
| 13292 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); |
| 13293 int year, month, day; |
| 13294 date_cache->YearMonthDayFromDays(days, &year, &month, &day); |
| 13295 int weekday = date_cache->Weekday(days); |
| 13296 int hour = time_in_day_ms / (60 * 60 * 1000); |
| 13297 int min = (time_in_day_ms / (60 * 1000)) % 60; |
| 13298 int sec = (time_in_day_ms / 1000) % 60; |
| 13299 set_cache_stamp(date_cache->stamp()); |
| 13300 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 13301 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 13302 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 13303 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 13304 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 13305 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 13306 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 13307 } |
| 13308 |
| 13178 } } // namespace v8::internal | 13309 } } // namespace v8::internal |
| OLD | NEW |