Chromium Code Reviews| 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 default: | |
| 13207 ASSERT(index == kSecond); | |
|
rossberg
2012/03/06 15:55:50
I think in other places we tend to use a regular c
ulan
2012/03/07 10:55:21
Done.
| |
| 13208 return sec(); | |
| 13209 } | |
| 13210 } | |
| 13211 | |
| 13212 if (index >= kFirstUTCField) { | |
| 13213 return GetUTCField(index, value()->Number(), date_cache); | |
| 13214 } | |
| 13215 | |
| 13216 double time = value()->Number(); | |
| 13217 if (isnan(time)) return GetIsolate()->heap()->nan_value(); | |
| 13218 | |
| 13219 int64_t local_time_ms = static_cast<int64_t>(date_cache->ToLocal(time)); | |
| 13220 int days = DateCache::DaysFromTime(local_time_ms); | |
| 13221 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); | |
| 13222 | |
| 13223 if (index == kMillisecond) return Smi::FromInt(time_in_day_ms % 1000); | |
|
rossberg
2012/03/06 15:55:50
Maybe consider using another 'switch' here for cla
ulan
2012/03/07 10:55:21
Moved the "days" case up, now only two cases are l
| |
| 13224 if (index == kDays) return Smi::FromInt(days); | |
|
rossberg
2012/03/06 15:55:50
You could move this up before computing time_in_da
ulan
2012/03/07 10:55:21
Done.
| |
| 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 int days = DateCache::DaysFromTime(time_ms); | |
|
rossberg
2012/03/06 15:55:50
You can move this after the kTimezoneOffset case.
ulan
2012/03/07 10:55:21
Done.
| |
| 13239 | |
| 13240 if (index == kTimezoneOffset) { | |
| 13241 int64_t time_ms = static_cast<int64_t>(value); | |
| 13242 return Smi::FromInt(date_cache->TimezoneOffset(time_ms)); | |
| 13243 } | |
| 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); | |
|
rossberg
2012/03/06 15:55:50
Perhaps use a switch here.
ulan
2012/03/07 10:55:21
I am not sure, just three cases.
| |
| 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 default: | |
| 13264 ASSERT(index == kTimeInDayUTC); | |
|
rossberg
2012/03/06 15:55:50
See above, consider using an unreachable default.
ulan
2012/03/07 10:55:21
Done.
| |
| 13265 return Smi::FromInt(time_in_day_ms); | |
| 13266 } | |
| 13267 | |
| 13268 UNREACHABLE(); | |
| 13269 return NULL; | |
| 13270 } | |
| 13271 | |
| 13272 | |
| 13273 void JSDate::SetValue(Object* value, bool is_value_nan) { | |
| 13274 set_value(value); | |
| 13275 if (is_value_nan) { | |
| 13276 HeapNumber* nan = GetIsolate()->heap()->nan_value(); | |
| 13277 set_cache_stamp(nan, SKIP_WRITE_BARRIER); | |
| 13278 set_year(nan, SKIP_WRITE_BARRIER); | |
| 13279 set_month(nan, SKIP_WRITE_BARRIER); | |
| 13280 set_day(nan, SKIP_WRITE_BARRIER); | |
| 13281 set_hour(nan, SKIP_WRITE_BARRIER); | |
| 13282 set_min(nan, SKIP_WRITE_BARRIER); | |
| 13283 set_sec(nan, SKIP_WRITE_BARRIER); | |
| 13284 set_weekday(nan, SKIP_WRITE_BARRIER); | |
| 13285 } else { | |
| 13286 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); | |
| 13287 } | |
| 13288 } | |
| 13289 | |
| 13290 | |
| 13291 void JSDate::SetLocalFields(int64_t local_time_ms, DateCache* date_cache) { | |
| 13292 int days, time_in_day_ms, year, month, day, weekday, hour, min, sec; | |
|
rossberg
2012/03/06 15:55:50
Avoid uninitialized declarations if you can (like
ulan
2012/03/07 10:55:21
Done.
| |
| 13293 days = DateCache::DaysFromTime(local_time_ms); | |
| 13294 time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); | |
| 13295 date_cache->YearMonthDayFromDays(days, &year, &month, &day); | |
| 13296 weekday = date_cache->Weekday(days); | |
| 13297 hour = time_in_day_ms / (60 * 60 * 1000); | |
| 13298 min = (time_in_day_ms / (60 * 1000)) % 60; | |
| 13299 sec = (time_in_day_ms / 1000) % 60; | |
| 13300 set_cache_stamp(date_cache->stamp()); | |
| 13301 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | |
| 13302 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | |
| 13303 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | |
| 13304 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | |
| 13305 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | |
| 13306 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | |
| 13307 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | |
| 13308 } | |
| 13309 | |
| 13178 } } // namespace v8::internal | 13310 } } // namespace v8::internal |
| OLD | NEW |