| 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 | 344 |
| 254 private: | 345 private: |
| 255 // Constants for time conversion. | 346 // Constants for time conversion. |
| 256 static const int64_t kTimeEpoc = 116444736000000000LL; | 347 static const int64_t kTimeEpoc = 116444736000000000LL; |
| 257 static const int64_t kTimeScaler = 10000; | 348 static const int64_t kTimeScaler = 10000; |
| 258 static const int64_t kMsPerMinute = 60000; | 349 static const int64_t kMsPerMinute = 60000; |
| 259 | 350 |
| 260 // Constants for timezone information. | 351 // Constants for timezone information. |
| 261 static const int kTzNameSize = 128; | |
| 262 static const bool kShortTzNames = false; | 352 static const bool kShortTzNames = false; |
| 263 | 353 |
| 264 // Timezone information. We need to have static buffers for the | |
| 265 // timezone names because we return pointers to these in | |
| 266 // LocalTimezone(). | |
| 267 static bool tz_initialized_; | |
| 268 static TIME_ZONE_INFORMATION tzinfo_; | |
| 269 static char std_tz_name_[kTzNameSize]; | |
| 270 static char dst_tz_name_[kTzNameSize]; | |
| 271 | |
| 272 // Initialize the timezone information (if not already done). | |
| 273 static void TzSet(); | |
| 274 | |
| 275 // Guess the name of the timezone from the bias. | |
| 276 static const char* GuessTimezoneNameFromBias(int bias); | |
| 277 | |
| 278 // 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. |
| 279 bool InDST(); | 355 bool InDST(TimezoneCache* cache); |
| 280 | 356 |
| 281 // Accessor for FILETIME representation. | 357 // Accessor for FILETIME representation. |
| 282 FILETIME& ft() { return time_.ft_; } | 358 FILETIME& ft() { return time_.ft_; } |
| 283 | 359 |
| 284 // Accessor for integer representation. | 360 // Accessor for integer representation. |
| 285 int64_t& t() { return time_.t_; } | 361 int64_t& t() { return time_.t_; } |
| 286 | 362 |
| 287 // Although win32 uses 64-bit integers for representing timestamps, | 363 // Although win32 uses 64-bit integers for representing timestamps, |
| 288 // these are packed into a FILETIME structure. The FILETIME structure | 364 // these are packed into a FILETIME structure. The FILETIME structure |
| 289 // 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 |
| 290 // allows access to both a FILETIME and an integer representation of | 366 // allows access to both a FILETIME and an integer representation of |
| 291 // the timestamp. | 367 // the timestamp. |
| 292 union TimeStamp { | 368 union TimeStamp { |
| 293 FILETIME ft_; | 369 FILETIME ft_; |
| 294 int64_t t_; | 370 int64_t t_; |
| 295 }; | 371 }; |
| 296 | 372 |
| 297 TimeStamp time_; | 373 TimeStamp time_; |
| 298 }; | 374 }; |
| 299 | 375 |
| 300 | 376 |
| 301 // Static variables. | |
| 302 bool Win32Time::tz_initialized_ = false; | |
| 303 TIME_ZONE_INFORMATION Win32Time::tzinfo_; | |
| 304 char Win32Time::std_tz_name_[kTzNameSize]; | |
| 305 char Win32Time::dst_tz_name_[kTzNameSize]; | |
| 306 | |
| 307 | |
| 308 // Initialize timestamp to start of epoc. | 377 // Initialize timestamp to start of epoc. |
| 309 Win32Time::Win32Time() { | 378 Win32Time::Win32Time() { |
| 310 t() = 0; | 379 t() = 0; |
| 311 } | 380 } |
| 312 | 381 |
| 313 | 382 |
| 314 // Initialize timestamp from a JavaScript timestamp. | 383 // Initialize timestamp from a JavaScript timestamp. |
| 315 Win32Time::Win32Time(double jstime) { | 384 Win32Time::Win32Time(double jstime) { |
| 316 t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc; | 385 t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc; |
| 317 } | 386 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 init_ticks = ticks_now = timeGetTime(); | 455 init_ticks = ticks_now = timeGetTime(); |
| 387 initialized = true; | 456 initialized = true; |
| 388 } | 457 } |
| 389 | 458 |
| 390 // Finally, compute the actual time. Why is this so hard. | 459 // Finally, compute the actual time. Why is this so hard. |
| 391 DWORD elapsed = ticks_now - init_ticks; | 460 DWORD elapsed = ticks_now - init_ticks; |
| 392 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); |
| 393 } | 462 } |
| 394 | 463 |
| 395 | 464 |
| 396 // Guess the name of the timezone from the bias. | |
| 397 // The guess is very biased towards the northern hemisphere. | |
| 398 const char* Win32Time::GuessTimezoneNameFromBias(int bias) { | |
| 399 static const int kHour = 60; | |
| 400 switch (-bias) { | |
| 401 case -9*kHour: return "Alaska"; | |
| 402 case -8*kHour: return "Pacific"; | |
| 403 case -7*kHour: return "Mountain"; | |
| 404 case -6*kHour: return "Central"; | |
| 405 case -5*kHour: return "Eastern"; | |
| 406 case -4*kHour: return "Atlantic"; | |
| 407 case 0*kHour: return "GMT"; | |
| 408 case +1*kHour: return "Central Europe"; | |
| 409 case +2*kHour: return "Eastern Europe"; | |
| 410 case +3*kHour: return "Russia"; | |
| 411 case +5*kHour + 30: return "India"; | |
| 412 case +8*kHour: return "China"; | |
| 413 case +9*kHour: return "Japan"; | |
| 414 case +12*kHour: return "New Zealand"; | |
| 415 default: return "Local"; | |
| 416 } | |
| 417 } | |
| 418 | |
| 419 | |
| 420 // Initialize timezone information. The timezone information is obtained from | |
| 421 // windows. If we cannot get the timezone information we fall back to CET. | |
| 422 // Please notice that this code is not thread-safe. | |
| 423 void Win32Time::TzSet() { | |
| 424 // Just return if timezone information has already been initialized. | |
| 425 if (tz_initialized_) return; | |
| 426 | |
| 427 // Initialize POSIX time zone data. | |
| 428 _tzset(); | |
| 429 // Obtain timezone information from operating system. | |
| 430 memset(&tzinfo_, 0, sizeof(tzinfo_)); | |
| 431 if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) { | |
| 432 // If we cannot get timezone information we fall back to CET. | |
| 433 tzinfo_.Bias = -60; | |
| 434 tzinfo_.StandardDate.wMonth = 10; | |
| 435 tzinfo_.StandardDate.wDay = 5; | |
| 436 tzinfo_.StandardDate.wHour = 3; | |
| 437 tzinfo_.StandardBias = 0; | |
| 438 tzinfo_.DaylightDate.wMonth = 3; | |
| 439 tzinfo_.DaylightDate.wDay = 5; | |
| 440 tzinfo_.DaylightDate.wHour = 2; | |
| 441 tzinfo_.DaylightBias = -60; | |
| 442 } | |
| 443 | |
| 444 // Make standard and DST timezone names. | |
| 445 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.StandardName, -1, | |
| 446 std_tz_name_, kTzNameSize, NULL, NULL); | |
| 447 std_tz_name_[kTzNameSize - 1] = '\0'; | |
| 448 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.DaylightName, -1, | |
| 449 dst_tz_name_, kTzNameSize, NULL, NULL); | |
| 450 dst_tz_name_[kTzNameSize - 1] = '\0'; | |
| 451 | |
| 452 // If OS returned empty string or resource id (like "@tzres.dll,-211") | |
| 453 // simply guess the name from the UTC bias of the timezone. | |
| 454 // To properly resolve the resource identifier requires a library load, | |
| 455 // which is not possible in a sandbox. | |
| 456 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') { | |
| 457 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1), | |
| 458 "%s Standard Time", | |
| 459 GuessTimezoneNameFromBias(tzinfo_.Bias)); | |
| 460 } | |
| 461 if (dst_tz_name_[0] == '\0' || dst_tz_name_[0] == '@') { | |
| 462 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize - 1), | |
| 463 "%s Daylight Time", | |
| 464 GuessTimezoneNameFromBias(tzinfo_.Bias)); | |
| 465 } | |
| 466 | |
| 467 // Timezone information initialized. | |
| 468 tz_initialized_ = true; | |
| 469 } | |
| 470 | |
| 471 | |
| 472 // Return the local timezone offset in milliseconds east of UTC. This | 465 // Return the local timezone offset in milliseconds east of UTC. This |
| 473 // 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. |
| 474 // 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. |
| 475 // 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. |
| 476 // The function EquivalentTime() in date.js guarantees this. | 469 // The function EquivalentTime() in date.js guarantees this. |
| 477 int64_t Win32Time::LocalOffset() { | 470 int64_t Win32Time::LocalOffset(TimezoneCache* cache) { |
| 478 // Initialize timezone information, if needed. | 471 cache->InitializeIfNeeded(); |
| 479 TzSet(); | |
| 480 | 472 |
| 481 Win32Time rounded_to_second(*this); | 473 Win32Time rounded_to_second(*this); |
| 482 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler * | 474 rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler * |
| 483 1000 * kTimeScaler; | 475 1000 * kTimeScaler; |
| 484 // Convert to local time using POSIX localtime function. | 476 // Convert to local time using POSIX localtime function. |
| 485 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime() | 477 // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime() |
| 486 // very slow. Other browsers use localtime(). | 478 // very slow. Other browsers use localtime(). |
| 487 | 479 |
| 488 // 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 |
| 489 // POSIX seconds past 1/1/1970 0:00:00. | 481 // POSIX seconds past 1/1/1970 0:00:00. |
| 490 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000; | 482 double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000; |
| 491 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) { | 483 if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) { |
| 492 return 0; | 484 return 0; |
| 493 } | 485 } |
| 494 // 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. |
| 495 time_t posix_time = static_cast<time_t>(unchecked_posix_time); | 487 time_t posix_time = static_cast<time_t>(unchecked_posix_time); |
| 496 | 488 |
| 497 // 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. |
| 498 tm posix_local_time_struct; | 490 tm posix_local_time_struct; |
| 499 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; | 491 if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; |
| 500 | 492 |
| 501 if (posix_local_time_struct.tm_isdst > 0) { | 493 if (posix_local_time_struct.tm_isdst > 0) { |
| 502 return (tzinfo_.Bias + tzinfo_.DaylightBias) * -kMsPerMinute; | 494 return (cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * -kMsPerMinute; |
| 503 } else if (posix_local_time_struct.tm_isdst == 0) { | 495 } else if (posix_local_time_struct.tm_isdst == 0) { |
| 504 return (tzinfo_.Bias + tzinfo_.StandardBias) * -kMsPerMinute; | 496 return (cache->tzinfo_.Bias + cache->tzinfo_.StandardBias) * -kMsPerMinute; |
| 505 } else { | 497 } else { |
| 506 return tzinfo_.Bias * -kMsPerMinute; | 498 return cache->tzinfo_.Bias * -kMsPerMinute; |
| 507 } | 499 } |
| 508 } | 500 } |
| 509 | 501 |
| 510 | 502 |
| 511 // 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. |
| 512 bool Win32Time::InDST() { | 504 bool Win32Time::InDST(TimezoneCache* cache) { |
| 513 // Initialize timezone information, if needed. | 505 cache->InitializeIfNeeded(); |
| 514 TzSet(); | |
| 515 | 506 |
| 516 // Determine if DST is in effect at the specified time. | 507 // Determine if DST is in effect at the specified time. |
| 517 bool in_dst = false; | 508 bool in_dst = false; |
| 518 if (tzinfo_.StandardDate.wMonth != 0 || tzinfo_.DaylightDate.wMonth != 0) { | 509 if (cache->tzinfo_.StandardDate.wMonth != 0 || |
| 510 cache->tzinfo_.DaylightDate.wMonth != 0) { |
| 519 // Get the local timezone offset for the timestamp in milliseconds. | 511 // Get the local timezone offset for the timestamp in milliseconds. |
| 520 int64_t offset = LocalOffset(); | 512 int64_t offset = LocalOffset(cache); |
| 521 | 513 |
| 522 // 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 |
| 523 // are specified in minutes. These must be converted to milliseconds. | 515 // are specified in minutes. These must be converted to milliseconds. |
| 524 int64_t dstofs = -(tzinfo_.Bias + tzinfo_.DaylightBias) * kMsPerMinute; | 516 int64_t dstofs = |
| 517 -(cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * kMsPerMinute; |
| 525 | 518 |
| 526 // 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 |
| 527 // bias then DST is in effect. | 520 // bias then DST is in effect. |
| 528 in_dst = offset == dstofs; | 521 in_dst = offset == dstofs; |
| 529 } | 522 } |
| 530 | 523 |
| 531 return in_dst; | 524 return in_dst; |
| 532 } | 525 } |
| 533 | 526 |
| 534 | 527 |
| 535 // Return the daylight savings time offset for this time. | 528 // Return the daylight savings time offset for this time. |
| 536 int64_t Win32Time::DaylightSavingsOffset() { | 529 int64_t Win32Time::DaylightSavingsOffset(TimezoneCache* cache) { |
| 537 return InDST() ? 60 * kMsPerMinute : 0; | 530 return InDST(cache) ? 60 * kMsPerMinute : 0; |
| 538 } | 531 } |
| 539 | 532 |
| 540 | 533 |
| 541 // Returns a string identifying the current timezone for the | 534 // Returns a string identifying the current timezone for the |
| 542 // timestamp taking into account daylight saving. | 535 // timestamp taking into account daylight saving. |
| 543 char* Win32Time::LocalTimezone() { | 536 char* Win32Time::LocalTimezone(TimezoneCache* cache) { |
| 544 // 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 |
| 545 // saving is in effect at the given time. | 538 // saving is in effect at the given time. |
| 546 return InDST() ? dst_tz_name_ : std_tz_name_; | 539 return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_; |
| 547 } | 540 } |
| 548 | 541 |
| 549 | 542 |
| 550 void OS::PostSetUp() { | 543 void OS::PostSetUp() { |
| 551 // Math functions depend on CPU features therefore they are initialized after | 544 // Math functions depend on CPU features therefore they are initialized after |
| 552 // CPU. | 545 // CPU. |
| 553 MathSetup(); | 546 MathSetup(); |
| 554 #if V8_TARGET_ARCH_IA32 | 547 #if V8_TARGET_ARCH_IA32 |
| 555 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 548 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
| 556 if (generated_memmove != NULL) { | 549 if (generated_memmove != NULL) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 579 } | 572 } |
| 580 | 573 |
| 581 | 574 |
| 582 // Returns current time as the number of milliseconds since | 575 // Returns current time as the number of milliseconds since |
| 583 // 00:00:00 UTC, January 1, 1970. | 576 // 00:00:00 UTC, January 1, 1970. |
| 584 double OS::TimeCurrentMillis() { | 577 double OS::TimeCurrentMillis() { |
| 585 return Time::Now().ToJsTime(); | 578 return Time::Now().ToJsTime(); |
| 586 } | 579 } |
| 587 | 580 |
| 588 | 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 |
| 589 // Returns a string identifying the current timezone taking into | 597 // Returns a string identifying the current timezone taking into |
| 590 // account daylight saving. | 598 // account daylight saving. |
| 591 const char* OS::LocalTimezone(double time) { | 599 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { |
| 592 return Win32Time(time).LocalTimezone(); | 600 return Win32Time(time).LocalTimezone(cache); |
| 593 } | 601 } |
| 594 | 602 |
| 595 | 603 |
| 596 // Returns the local time offset in milliseconds east of UTC without | 604 // Returns the local time offset in milliseconds east of UTC without |
| 597 // taking daylight savings time into account. | 605 // taking daylight savings time into account. |
| 598 double OS::LocalTimeOffset() { | 606 double OS::LocalTimeOffset(TimezoneCache* cache) { |
| 599 // Use current time, rounded to the millisecond. | 607 // Use current time, rounded to the millisecond. |
| 600 Win32Time t(TimeCurrentMillis()); | 608 Win32Time t(TimeCurrentMillis()); |
| 601 // Time::LocalOffset inlcudes any daylight savings offset, so subtract it. | 609 // Time::LocalOffset inlcudes any daylight savings offset, so subtract it. |
| 602 return static_cast<double>(t.LocalOffset() - t.DaylightSavingsOffset()); | 610 return static_cast<double>(t.LocalOffset(cache) - |
| 611 t.DaylightSavingsOffset(cache)); |
| 603 } | 612 } |
| 604 | 613 |
| 605 | 614 |
| 606 // Returns the daylight savings offset in milliseconds for the given | 615 // Returns the daylight savings offset in milliseconds for the given |
| 607 // time. | 616 // time. |
| 608 double OS::DaylightSavingsOffset(double time) { | 617 double OS::DaylightSavingsOffset(double time, TimezoneCache* cache) { |
| 609 int64_t offset = Win32Time(time).DaylightSavingsOffset(); | 618 int64_t offset = Win32Time(time).DaylightSavingsOffset(cache); |
| 610 return static_cast<double>(offset); | 619 return static_cast<double>(offset); |
| 611 } | 620 } |
| 612 | 621 |
| 613 | 622 |
| 614 int OS::GetLastError() { | 623 int OS::GetLastError() { |
| 615 return ::GetLastError(); | 624 return ::GetLastError(); |
| 616 } | 625 } |
| 617 | 626 |
| 618 | 627 |
| 619 int OS::GetCurrentProcessId() { | 628 int OS::GetCurrentProcessId() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) != FILE_TYPE_UNKNOWN) | 664 GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) != FILE_TYPE_UNKNOWN) |
| 656 output_mode = CONSOLE; | 665 output_mode = CONSOLE; |
| 657 else | 666 else |
| 658 output_mode = ODS; | 667 output_mode = ODS; |
| 659 } | 668 } |
| 660 return output_mode == CONSOLE; | 669 return output_mode == CONSOLE; |
| 661 } | 670 } |
| 662 | 671 |
| 663 | 672 |
| 664 static void VPrintHelper(FILE* stream, const char* format, va_list args) { | 673 static void VPrintHelper(FILE* stream, const char* format, va_list args) { |
| 665 if (HasConsole()) { | 674 if ((stream == stdout || stream == stderr) && !HasConsole()) { |
| 666 vfprintf(stream, format, args); | |
| 667 } else { | |
| 668 // It is important to use safe print here in order to avoid | 675 // It is important to use safe print here in order to avoid |
| 669 // overflowing the buffer. We might truncate the output, but this | 676 // overflowing the buffer. We might truncate the output, but this |
| 670 // does not crash. | 677 // does not crash. |
| 671 EmbeddedVector<char, 4096> buffer; | 678 EmbeddedVector<char, 4096> buffer; |
| 672 OS::VSNPrintF(buffer, format, args); | 679 OS::VSNPrintF(buffer, format, args); |
| 673 OutputDebugStringA(buffer.start()); | 680 OutputDebugStringA(buffer.start()); |
| 681 } else { |
| 682 vfprintf(stream, format, args); |
| 674 } | 683 } |
| 675 } | 684 } |
| 676 | 685 |
| 677 | 686 |
| 678 FILE* OS::FOpen(const char* path, const char* mode) { | 687 FILE* OS::FOpen(const char* path, const char* mode) { |
| 679 FILE* result; | 688 FILE* result; |
| 680 if (fopen_s(&result, path, mode) == 0) { | 689 if (fopen_s(&result, path, mode) == 0) { |
| 681 return result; | 690 return result; |
| 682 } else { | 691 } else { |
| 683 return NULL; | 692 return NULL; |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 ASSERT(result); | 1513 ASSERT(result); |
| 1505 } | 1514 } |
| 1506 | 1515 |
| 1507 | 1516 |
| 1508 | 1517 |
| 1509 void Thread::YieldCPU() { | 1518 void Thread::YieldCPU() { |
| 1510 Sleep(0); | 1519 Sleep(0); |
| 1511 } | 1520 } |
| 1512 | 1521 |
| 1513 } } // namespace v8::internal | 1522 } } // namespace v8::internal |
| OLD | NEW |