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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 void MathSetup() { | 212 void MathSetup() { |
213 #ifdef _WIN64 | 213 #ifdef _WIN64 |
214 init_modulo_function(); | 214 init_modulo_function(); |
215 #endif | 215 #endif |
216 // fast_exp is initialized lazily. | 216 // fast_exp is initialized lazily. |
217 init_fast_sqrt_function(); | 217 init_fast_sqrt_function(); |
218 } | 218 } |
219 | 219 |
220 | 220 |
| 221 class TimezoneCache { |
| 222 public: |
| 223 TimezoneCache() : initialized_(false) { } |
| 224 |
| 225 void Clear() { |
| 226 initialized_ = false; |
| 227 } |
| 228 |
| 229 // Initialize timezone information. The timezone information is obtained from |
| 230 // windows. If we cannot get the timezone information we fall back to CET. |
| 231 void InitializeIfNeeded() { |
| 232 // Just return if timezone information has already been initialized. |
| 233 if (initialized_) return; |
| 234 |
| 235 // Initialize POSIX time zone data. |
| 236 _tzset(); |
| 237 // Obtain timezone information from operating system. |
| 238 memset(&tzinfo_, 0, sizeof(tzinfo_)); |
| 239 if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) { |
| 240 // If we cannot get timezone information we fall back to CET. |
| 241 tzinfo_.Bias = -60; |
| 242 tzinfo_.StandardDate.wMonth = 10; |
| 243 tzinfo_.StandardDate.wDay = 5; |
| 244 tzinfo_.StandardDate.wHour = 3; |
| 245 tzinfo_.StandardBias = 0; |
| 246 tzinfo_.DaylightDate.wMonth = 3; |
| 247 tzinfo_.DaylightDate.wDay = 5; |
| 248 tzinfo_.DaylightDate.wHour = 2; |
| 249 tzinfo_.DaylightBias = -60; |
| 250 } |
| 251 |
| 252 // Make standard and DST timezone names. |
| 253 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.StandardName, -1, |
| 254 std_tz_name_, kTzNameSize, NULL, NULL); |
| 255 std_tz_name_[kTzNameSize - 1] = '\0'; |
| 256 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.DaylightName, -1, |
| 257 dst_tz_name_, kTzNameSize, NULL, NULL); |
| 258 dst_tz_name_[kTzNameSize - 1] = '\0'; |
| 259 |
| 260 // If OS returned empty string or resource id (like "@tzres.dll,-211") |
| 261 // simply guess the name from the UTC bias of the timezone. |
| 262 // To properly resolve the resource identifier requires a library load, |
| 263 // which is not possible in a sandbox. |
| 264 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') { |
| 265 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1), |
| 266 "%s Standard Time", |
| 267 GuessTimezoneNameFromBias(tzinfo_.Bias)); |
| 268 } |
| 269 if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') { |
| 270 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1), |
| 271 "%s Daylight Time", |
| 272 GuessTimezoneNameFromBias(tzinfo_.Bias)); |
| 273 } |
| 274 // Timezone information initialized. |
| 275 initialized_ = true; |
| 276 } |
| 277 |
| 278 // Guess the name of the timezone from the bias. |
| 279 // The guess is very biased towards the northern hemisphere. |
| 280 const char* GuessTimezoneNameFromBias(int bias) { |
| 281 static const int kHour = 60; |
| 282 switch (-bias) { |
| 283 case -9*kHour: return "Alaska"; |
| 284 case -8*kHour: return "Pacific"; |
| 285 case -7*kHour: return "Mountain"; |
| 286 case -6*kHour: return "Central"; |
| 287 case -5*kHour: return "Eastern"; |
| 288 case -4*kHour: return "Atlantic"; |
| 289 case 0*kHour: return "GMT"; |
| 290 case +1*kHour: return "Central Europe"; |
| 291 case +2*kHour: return "Eastern Europe"; |
| 292 case +3*kHour: return "Russia"; |
| 293 case +5*kHour + 30: return "India"; |
| 294 case +8*kHour: return "China"; |
| 295 case +9*kHour: return "Japan"; |
| 296 case +12*kHour: return "New Zealand"; |
| 297 default: return "Local"; |
| 298 } |
| 299 } |
| 300 |
| 301 |
| 302 private: |
| 303 static const int kTzNameSize = 128; |
| 304 bool initialized_; |
| 305 char std_tz_name_[kTzNameSize]; |
| 306 char dst_tz_name_[kTzNameSize]; |
| 307 TIME_ZONE_INFORMATION tzinfo_; |
| 308 friend class Win32Time; |
| 309 }; |
| 310 |
| 311 |
221 // ---------------------------------------------------------------------------- | 312 // ---------------------------------------------------------------------------- |
222 // The Time class represents time on win32. A timestamp is represented as | 313 // The Time class represents time on win32. A timestamp is represented as |
223 // a 64-bit integer in 100 nanoseconds since January 1, 1601 (UTC). JavaScript | 314 // a 64-bit integer in 100 nanoseconds since January 1, 1601 (UTC). JavaScript |
224 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, | 315 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, |
225 // January 1, 1970. | 316 // January 1, 1970. |
226 | 317 |
227 class Win32Time { | 318 class Win32Time { |
228 public: | 319 public: |
229 // Constructors. | 320 // Constructors. |
230 Win32Time(); | 321 Win32Time(); |
231 explicit Win32Time(double jstime); | 322 explicit Win32Time(double jstime); |
232 Win32Time(int year, int mon, int day, int hour, int min, int sec); | 323 Win32Time(int year, int mon, int day, int hour, int min, int sec); |
233 | 324 |
234 // Convert timestamp to JavaScript representation. | 325 // Convert timestamp to JavaScript representation. |
235 double ToJSTime(); | 326 double ToJSTime(); |
236 | 327 |
237 // Set timestamp to current time. | 328 // Set timestamp to current time. |
238 void SetToCurrentTime(); | 329 void SetToCurrentTime(); |
239 | 330 |
240 // Returns the local timezone offset in milliseconds east of UTC. This is | 331 // Returns the local timezone offset in milliseconds east of UTC. This is |
241 // the number of milliseconds you must add to UTC to get local time, i.e. | 332 // the number of milliseconds you must add to UTC to get local time, i.e. |
242 // LocalOffset(CET) = 3600000 and LocalOffset(PST) = -28800000. This | 333 // LocalOffset(CET) = 3600000 and LocalOffset(PST) = -28800000. This |
243 // routine also takes into account whether daylight saving is effect | 334 // routine also takes into account whether daylight saving is effect |
244 // at the time. | 335 // at the time. |
245 int64_t LocalOffset(); | 336 int64_t LocalOffset(TimezoneCache* cache); |
246 | 337 |
247 // Returns the daylight savings time offset for the time in milliseconds. | 338 // Returns the daylight savings time offset for the time in milliseconds. |
248 int64_t DaylightSavingsOffset(); | 339 int64_t DaylightSavingsOffset(TimezoneCache* cache); |
249 | 340 |
250 // Returns a string identifying the current timezone for the | 341 // Returns a string identifying the current timezone for the |
251 // timestamp taking into account daylight saving. | 342 // timestamp taking into account daylight saving. |
252 char* LocalTimezone(); | 343 char* LocalTimezone(TimezoneCache* cache); |
253 | |
254 static void TimeZoneChanged() { tz_initialized_ = false; } | |
255 | 344 |
256 private: | 345 private: |
257 // Constants for time conversion. | 346 // Constants for time conversion. |
258 static const int64_t kTimeEpoc = 116444736000000000LL; | 347 static const int64_t kTimeEpoc = 116444736000000000LL; |
259 static const int64_t kTimeScaler = 10000; | 348 static const int64_t kTimeScaler = 10000; |
260 static const int64_t kMsPerMinute = 60000; | 349 static const int64_t kMsPerMinute = 60000; |
261 | 350 |
262 // Constants for timezone information. | 351 // Constants for timezone information. |
263 static const int kTzNameSize = 128; | |
264 static const bool kShortTzNames = false; | 352 static const bool kShortTzNames = false; |
265 | 353 |
266 // Timezone information. We need to have static buffers for the | |
267 // timezone names because we return pointers to these in | |
268 // LocalTimezone(). | |
269 static bool tz_initialized_; | |
270 static TIME_ZONE_INFORMATION tzinfo_; | |
271 static char std_tz_name_[kTzNameSize]; | |
272 static char dst_tz_name_[kTzNameSize]; | |
273 | |
274 // Initialize the timezone information (if not already done). | |
275 static void TzSet(); | |
276 | |
277 // Guess the name of the timezone from the bias. | |
278 static const char* GuessTimezoneNameFromBias(int bias); | |
279 | |
280 // Return whether or not daylight savings time is in effect at this time. | 354 // Return whether or not daylight savings time is in effect at this time. |
281 bool InDST(); | 355 bool InDST(TimezoneCache* cache); |
282 | 356 |
283 // Accessor for FILETIME representation. | 357 // Accessor for FILETIME representation. |
284 FILETIME& ft() { return time_.ft_; } | 358 FILETIME& ft() { return time_.ft_; } |
285 | 359 |
286 // Accessor for integer representation. | 360 // Accessor for integer representation. |
287 int64_t& t() { return time_.t_; } | 361 int64_t& t() { return time_.t_; } |
288 | 362 |
289 // Although win32 uses 64-bit integers for representing timestamps, | 363 // Although win32 uses 64-bit integers for representing timestamps, |
290 // these are packed into a FILETIME structure. The FILETIME structure | 364 // these are packed into a FILETIME structure. The FILETIME structure |
291 // is just a struct representing a 64-bit integer. The TimeStamp union | 365 // is just a struct representing a 64-bit integer. The TimeStamp union |
292 // allows access to both a FILETIME and an integer representation of | 366 // allows access to both a FILETIME and an integer representation of |
293 // the timestamp. | 367 // the timestamp. |
294 union TimeStamp { | 368 union TimeStamp { |
295 FILETIME ft_; | 369 FILETIME ft_; |
296 int64_t t_; | 370 int64_t t_; |
297 }; | 371 }; |
298 | 372 |
299 TimeStamp time_; | 373 TimeStamp time_; |
300 }; | 374 }; |
301 | 375 |
302 | 376 |
303 // Static variables. | |
304 bool Win32Time::tz_initialized_ = false; | |
305 TIME_ZONE_INFORMATION Win32Time::tzinfo_; | |
306 char Win32Time::std_tz_name_[kTzNameSize]; | |
307 char Win32Time::dst_tz_name_[kTzNameSize]; | |
308 | |
309 | |
310 // Initialize timestamp to start of epoc. | 377 // Initialize timestamp to start of epoc. |
311 Win32Time::Win32Time() { | 378 Win32Time::Win32Time() { |
312 t() = 0; | 379 t() = 0; |
313 } | 380 } |
314 | 381 |
315 | 382 |
316 // Initialize timestamp from a JavaScript timestamp. | 383 // Initialize timestamp from a JavaScript timestamp. |
317 Win32Time::Win32Time(double jstime) { | 384 Win32Time::Win32Time(double jstime) { |
318 t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc; | 385 t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc; |
319 } | 386 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 init_ticks = ticks_now = timeGetTime(); | 455 init_ticks = ticks_now = timeGetTime(); |
389 initialized = true; | 456 initialized = true; |
390 } | 457 } |
391 | 458 |
392 // Finally, compute the actual time. Why is this so hard. | 459 // Finally, compute the actual time. Why is this so hard. |
393 DWORD elapsed = ticks_now - init_ticks; | 460 DWORD elapsed = ticks_now - init_ticks; |
394 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); | 461 this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); |
395 } | 462 } |
396 | 463 |
397 | 464 |
398 // Guess the name of the timezone from the bias. | |
399 // The guess is very biased towards the northern hemisphere. | |
400 const char* Win32Time::GuessTimezoneNameFromBias(int bias) { | |
401 static const int kHour = 60; | |
402 switch (-bias) { | |
403 case -9*kHour: return "Alaska"; | |
404 case -8*kHour: return "Pacific"; | |
405 case -7*kHour: return "Mountain"; | |
406 case -6*kHour: return "Central"; | |
407 case -5*kHour: return "Eastern"; | |
408 case -4*kHour: return "Atlantic"; | |
409 case 0*kHour: return "GMT"; | |
410 case +1*kHour: return "Central Europe"; | |
411 case +2*kHour: return "Eastern Europe"; | |
412 case +3*kHour: return "Russia"; | |
413 case +5*kHour + 30: return "India"; | |
414 case +8*kHour: return "China"; | |
415 case +9*kHour: return "Japan"; | |
416 case +12*kHour: return "New Zealand"; | |
417 default: return "Local"; | |
418 } | |
419 } | |
420 | |
421 | |
422 // Initialize timezone information. The timezone information is obtained from | |
423 // windows. If we cannot get the timezone information we fall back to CET. | |
424 // Please notice that this code is not thread-safe. | |
425 void Win32Time::TzSet() { | |
426 // Just return if timezone information has already been initialized. | |
427 if (tz_initialized_) return; | |
428 | |
429 // Initialize POSIX time zone data. | |
430 _tzset(); | |
431 // Obtain timezone information from operating system. | |
432 memset(&tzinfo_, 0, sizeof(tzinfo_)); | |
433 if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) { | |
434 // If we cannot get timezone information we fall back to CET. | |
435 tzinfo_.Bias = -60; | |
436 tzinfo_.StandardDate.wMonth = 10; | |
437 tzinfo_.StandardDate.wDay = 5; | |
438 tzinfo_.StandardDate.wHour = 3; | |
439 tzinfo_.StandardBias = 0; | |
440 tzinfo_.DaylightDate.wMonth = 3; | |
441 tzinfo_.DaylightDate.wDay = 5; | |
442 tzinfo_.DaylightDate.wHour = 2; | |
443 tzinfo_.DaylightBias = -60; | |
444 } | |
445 | |
446 // Make standard and DST timezone names. | |
447 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.StandardName, -1, | |
448 std_tz_name_, kTzNameSize, NULL, NULL); | |
449 std_tz_name_[kTzNameSize - 1] = '\0'; | |
450 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.DaylightName, -1, | |
451 dst_tz_name_, kTzNameSize, NULL, NULL); | |
452 dst_tz_name_[kTzNameSize - 1] = '\0'; | |
453 | |
454 // If OS returned empty string or resource id (like "@tzres.dll,-211") | |
455 // simply guess the name from the UTC bias of the timezone. | |
456 // To properly resolve the resource identifier requires a library load, | |
457 // which is not possible in a sandbox. | |
458 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') { | |
459 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1), | |
460 "%s Standard Time", | |
461 GuessTimezoneNameFromBias(tzinfo_.Bias)); | |
462 } | |
463 if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') { | |
464 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1), | |
465 "%s Daylight Time", | |
466 GuessTimezoneNameFromBias(tzinfo_.Bias)); | |
467 } | |
468 | |
469 // Timezone information initialized. | |
470 tz_initialized_ = true; | |
471 } | |
472 | |
473 | |
474 // Return the local timezone offset in milliseconds east of UTC. This | 465 // Return the local timezone offset in milliseconds east of UTC. This |
475 // takes into account whether daylight saving is in effect at the time. | 466 // takes into account whether daylight saving is in effect at the time. |
476 // Only times in the 32-bit Unix range may be passed to this function. | 467 // Only times in the 32-bit Unix range may be passed to this function. |
477 // Also, adding the time-zone offset to the input must not overflow. | 468 // Also, adding the time-zone offset to the input must not overflow. |
478 // The function EquivalentTime() in date.js guarantees this. | 469 // The function EquivalentTime() in date.js guarantees this. |
479 int64_t Win32Time::LocalOffset() { | 470 int64_t Win32Time::LocalOffset(TimezoneCache* cache) { |
480 // Initialize timezone information, if needed. | 471 cache->InitializeIfNeeded(); |
481 TzSet(); | |
482 | 472 |
483 Win32Time rounded_to_second(*this); | 473 Win32Time rounded_to_second(*this); |
484 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler * | 474 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler * |
485 1000 * kTimeScaler; | 475 1000 * kTimeScaler; |
486 // Convert to local time using POSIX localtime function. | 476 // Convert to local time using POSIX localtime function. |
487 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime() | 477 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime() |
488 // very slow. Other browsers use localtime(). | 478 // very slow. Other browsers use localtime(). |
489 | 479 |
490 // Convert from JavaScript milliseconds past 1/1/1970 0:00:00 to | 480 // Convert from JavaScript milliseconds past 1/1/1970 0:00:00 to |
491 // POSIX seconds past 1/1/1970 0:00:00. | 481 // POSIX seconds past 1/1/1970 0:00:00. |
492 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000; | 482 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000; |
493 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) { | 483 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) { |
494 return 0; | 484 return 0; |
495 } | 485 } |
496 // Because _USE_32BIT_TIME_T is defined, time_t is a 32-bit int. | 486 // Because _USE_32BIT_TIME_T is defined, time_t is a 32-bit int. |
497 time_t posix_time = static_cast<time_t>(unchecked_posix_time); | 487 time_t posix_time = static_cast<time_t>(unchecked_posix_time); |
498 | 488 |
499 // Convert to local time, as struct with fields for day, hour, year, etc. | 489 // Convert to local time, as struct with fields for day, hour, year, etc. |
500 tm posix_local_time_struct; | 490 tm posix_local_time_struct; |
501 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; | 491 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; |
502 | 492 |
503 if (posix_local_time_struct.tm_isdst > 0) { | 493 if (posix_local_time_struct.tm_isdst > 0) { |
504 return (tzinfo_.Bias + tzinfo_.DaylightBias) * -kMsPerMinute; | 494 return (cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * -kMsPerMinute; |
505 } else if (posix_local_time_struct.tm_isdst == 0) { | 495 } else if (posix_local_time_struct.tm_isdst == 0) { |
506 return (tzinfo_.Bias + tzinfo_.StandardBias) * -kMsPerMinute; | 496 return (cache->tzinfo_.Bias + cache->tzinfo_.StandardBias) * -kMsPerMinute; |
507 } else { | 497 } else { |
508 return tzinfo_.Bias * -kMsPerMinute; | 498 return cache->tzinfo_.Bias * -kMsPerMinute; |
509 } | 499 } |
510 } | 500 } |
511 | 501 |
512 | 502 |
513 // Return whether or not daylight savings time is in effect at this time. | 503 // Return whether or not daylight savings time is in effect at this time. |
514 bool Win32Time::InDST() { | 504 bool Win32Time::InDST(TimezoneCache* cache) { |
515 // Initialize timezone information, if needed. | 505 cache->InitializeIfNeeded(); |
516 TzSet(); | |
517 | 506 |
518 // Determine if DST is in effect at the specified time. | 507 // Determine if DST is in effect at the specified time. |
519 bool in_dst = false; | 508 bool in_dst = false; |
520 if (tzinfo_.StandardDate.wMonth != 0 || tzinfo_.DaylightDate.wMonth != 0) { | 509 if (cache->tzinfo_.StandardDate.wMonth != 0 || |
| 510 cache->tzinfo_.DaylightDate.wMonth != 0) { |
521 // Get the local timezone offset for the timestamp in milliseconds. | 511 // Get the local timezone offset for the timestamp in milliseconds. |
522 int64_t offset = LocalOffset(); | 512 int64_t offset = LocalOffset(); |
523 | 513 |
524 // Compute the offset for DST. The bias parameters in the timezone info | 514 // Compute the offset for DST. The bias parameters in the timezone info |
525 // are specified in minutes. These must be converted to milliseconds. | 515 // are specified in minutes. These must be converted to milliseconds. |
526 int64_t dstofs = -(tzinfo_.Bias + tzinfo_.DaylightBias) * kMsPerMinute; | 516 int64_t dstofs = |
| 517 -(cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * kMsPerMinute; |
527 | 518 |
528 // If the local time offset equals the timezone bias plus the daylight | 519 // If the local time offset equals the timezone bias plus the daylight |
529 // bias then DST is in effect. | 520 // bias then DST is in effect. |
530 in_dst = offset == dstofs; | 521 in_dst = offset == dstofs; |
531 } | 522 } |
532 | 523 |
533 return in_dst; | 524 return in_dst; |
534 } | 525 } |
535 | 526 |
536 | 527 |
537 // Return the daylight savings time offset for this time. | 528 // Return the daylight savings time offset for this time. |
538 int64_t Win32Time::DaylightSavingsOffset() { | 529 int64_t Win32Time::DaylightSavingsOffset(TimezoneCache* cache) { |
539 return InDST() ? 60 * kMsPerMinute : 0; | 530 return InDST(cache) ? 60 * kMsPerMinute : 0; |
540 } | 531 } |
541 | 532 |
542 | 533 |
543 // Returns a string identifying the current timezone for the | 534 // Returns a string identifying the current timezone for the |
544 // timestamp taking into account daylight saving. | 535 // timestamp taking into account daylight saving. |
545 char* Win32Time::LocalTimezone() { | 536 char* Win32Time::LocalTimezone(TimezoneCache* cache) { |
546 // Return the standard or DST time zone name based on whether daylight | 537 // Return the standard or DST time zone name based on whether daylight |
547 // saving is in effect at the given time. | 538 // saving is in effect at the given time. |
548 return InDST() ? dst_tz_name_ : std_tz_name_; | 539 return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_; |
549 } | 540 } |
550 | 541 |
551 | 542 |
552 void OS::PostSetUp() { | 543 void OS::PostSetUp() { |
553 // Math functions depend on CPU features therefore they are initialized after | 544 // Math functions depend on CPU features therefore they are initialized after |
554 // CPU. | 545 // CPU. |
555 MathSetup(); | 546 MathSetup(); |
556 #if V8_TARGET_ARCH_IA32 | 547 #if V8_TARGET_ARCH_IA32 |
557 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 548 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
558 if (generated_memmove != NULL) { | 549 if (generated_memmove != NULL) { |
(...skipping 22 matching lines...) Expand all Loading... |
581 } | 572 } |
582 | 573 |
583 | 574 |
584 // Returns current time as the number of milliseconds since | 575 // Returns current time as the number of milliseconds since |
585 // 00:00:00 UTC, January 1, 1970. | 576 // 00:00:00 UTC, January 1, 1970. |
586 double OS::TimeCurrentMillis() { | 577 double OS::TimeCurrentMillis() { |
587 return Time::Now().ToJsTime(); | 578 return Time::Now().ToJsTime(); |
588 } | 579 } |
589 | 580 |
590 | 581 |
| 582 TimezoneCache* OS::CreateTimezoneCache() { |
| 583 return new TimezoneCache(); |
| 584 } |
| 585 |
| 586 |
| 587 void OS::DisposeTimezoneCache(TimezoneCache* cache) { |
| 588 delete cache; |
| 589 } |
| 590 |
| 591 |
| 592 void OS::ClearTimezoneCache(TimezoneCache* cache) { |
| 593 cache->Clear(); |
| 594 } |
| 595 |
| 596 |
591 // Returns a string identifying the current timezone taking into | 597 // Returns a string identifying the current timezone taking into |
592 // account daylight saving. | 598 // account daylight saving. |
593 const char* OS::LocalTimezone(double time) { | 599 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { |
594 return Win32Time(time).LocalTimezone(); | 600 return Win32Time(time).LocalTimezone(cache); |
595 } | 601 } |
596 | 602 |
597 | 603 |
598 // Returns the local time offset in milliseconds east of UTC without | 604 // Returns the local time offset in milliseconds east of UTC without |
599 // taking daylight savings time into account. | 605 // taking daylight savings time into account. |
600 double OS::LocalTimeOffset() { | 606 double OS::LocalTimeOffset(TimezoneCache* cache) { |
601 // Use current time, rounded to the millisecond. | 607 // Use current time, rounded to the millisecond. |
602 Win32Time t(TimeCurrentMillis()); | 608 Win32Time t(TimeCurrentMillis()); |
603 // Time::LocalOffset inlcudes any daylight savings offset, so subtract it. | 609 // Time::LocalOffset inlcudes any daylight savings offset, so subtract it. |
604 return static_cast<double>(t.LocalOffset() - t.DaylightSavingsOffset()); | 610 return static_cast<double>(t.LocalOffset(cache) - |
| 611 t.DaylightSavingsOffset(cache)); |
605 } | 612 } |
606 | 613 |
607 | 614 |
608 // Returns the daylight savings offset in milliseconds for the given | 615 // Returns the daylight savings offset in milliseconds for the given |
609 // time. | 616 // time. |
610 double OS::DaylightSavingsOffset(double time) { | 617 double OS::DaylightSavingsOffset(double time, TimezoneCache* cache) { |
611 int64_t offset = Win32Time(time).DaylightSavingsOffset(); | 618 int64_t offset = Win32Time(time).DaylightSavingsOffset(cache); |
612 return static_cast<double>(offset); | 619 return static_cast<double>(offset); |
613 } | 620 } |
614 | 621 |
615 | 622 |
616 void OS::TimeZoneChanged() { | |
617 Win32Time::TimeZoneChanged(); | |
618 } | |
619 | |
620 | |
621 int OS::GetLastError() { | 623 int OS::GetLastError() { |
622 return ::GetLastError(); | 624 return ::GetLastError(); |
623 } | 625 } |
624 | 626 |
625 | 627 |
626 int OS::GetCurrentProcessId() { | 628 int OS::GetCurrentProcessId() { |
627 return static_cast<int>(::GetCurrentProcessId()); | 629 return static_cast<int>(::GetCurrentProcessId()); |
628 } | 630 } |
629 | 631 |
630 | 632 |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 ASSERT(result); | 1513 ASSERT(result); |
1512 } | 1514 } |
1513 | 1515 |
1514 | 1516 |
1515 | 1517 |
1516 void Thread::YieldCPU() { | 1518 void Thread::YieldCPU() { |
1517 Sleep(0); | 1519 Sleep(0); |
1518 } | 1520 } |
1519 | 1521 |
1520 } } // namespace v8::internal | 1522 } } // namespace v8::internal |
OLD | NEW |