Skip to content

Commit 8096791

Browse files
Jaideep Bajwabnoordhuis
authored andcommitted
deps: cherry-pick fa4ec9f from V8 upstream
Original commit message: [date] Refactor PosixTimezoneCache for different OS Follow up on https://codereview.chromium.org/2740353002. Created PosixDefaultTimezoneCache which is a subclass of PosixTimezoneCache containing definition of LocalTimezone and LocalTimeOffset which is separate for different OS. [email protected], [email protected] BUG=v8:6578 LOG=N Change-Id: I58342893aeefe79ac50e1df041d614fc473f15bf Reviewed-on: https://chromium-review.googlesource.com/568686 Reviewed-by: Daniel Ehrenberg <[email protected]> Commit-Queue: Jaideep Bajwa <[email protected]> Cr-Commit-Position: refs/heads/master@{#46604} PR-URL: #14608 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a0895ed commit 8096791

12 files changed

+88
-30
lines changed

deps/v8/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,8 @@ v8_component("v8_libbase") {
25072507

25082508
if (is_posix) {
25092509
sources += [
2510+
"src/base/platform/platform-posix-time.cc",
2511+
"src/base/platform/platform-posix-time.h",
25102512
"src/base/platform/platform-posix.cc",
25112513
"src/base/platform/platform-posix.h",
25122514
]

deps/v8/include/v8-version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// system so their names cannot be changed without changing the scripts.
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 0
13-
#define V8_BUILD_NUMBER 286
14-
#define V8_PATCH_LEVEL 52
13+
#define V8_BUILD_NUMBER 287
14+
#define V8_PATCH_LEVEL 53
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/base/platform/platform-freebsd.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
#undef MAP_TYPE
3030

3131
#include "src/base/macros.h"
32+
#include "src/base/platform/platform-posix-time.h"
3233
#include "src/base/platform/platform-posix.h"
3334
#include "src/base/platform/platform.h"
3435

3536
namespace v8 {
3637
namespace base {
3738

38-
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
39+
TimezoneCache* OS::CreateTimezoneCache() {
40+
return new PosixDefaultTimezoneCache();
41+
}
3942

4043
void* OS::Allocate(const size_t requested, size_t* allocated,
4144
OS::MemoryPermission access) {

deps/v8/src/base/platform/platform-linux.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#undef MAP_TYPE
4545

4646
#include "src/base/macros.h"
47+
#include "src/base/platform/platform-posix-time.h"
4748
#include "src/base/platform/platform-posix.h"
4849
#include "src/base/platform/platform.h"
4950

@@ -92,7 +93,9 @@ bool OS::ArmUsingHardFloat() {
9293

9394
#endif // def __arm__
9495

95-
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
96+
TimezoneCache* OS::CreateTimezoneCache() {
97+
return new PosixDefaultTimezoneCache();
98+
}
9699

97100
void* OS::Allocate(const size_t requested, size_t* allocated,
98101
OS::MemoryPermission access) {

deps/v8/src/base/platform/platform-macos.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
#undef MAP_TYPE
3737

3838
#include "src/base/macros.h"
39+
#include "src/base/platform/platform-posix-time.h"
3940
#include "src/base/platform/platform-posix.h"
4041
#include "src/base/platform/platform.h"
4142

42-
4343
namespace v8 {
4444
namespace base {
4545

@@ -97,7 +97,9 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
9797
void OS::SignalCodeMovingGC() {
9898
}
9999

100-
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
100+
TimezoneCache* OS::CreateTimezoneCache() {
101+
return new PosixDefaultTimezoneCache();
102+
}
101103

102104
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
103105

deps/v8/src/base/platform/platform-openbsd.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727
#undef MAP_TYPE
2828

2929
#include "src/base/macros.h"
30+
#include "src/base/platform/platform-posix-time.h"
3031
#include "src/base/platform/platform-posix.h"
3132
#include "src/base/platform/platform.h"
3233

3334
namespace v8 {
3435
namespace base {
3536

36-
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
37+
TimezoneCache* OS::CreateTimezoneCache() {
38+
return new PosixDefaultTimezoneCache();
39+
}
3740

3841
void* OS::Allocate(const size_t requested, size_t* allocated,
3942
OS::MemoryPermission access) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <cmath>
6+
7+
#include "src/base/platform/platform-posix-time.h"
8+
9+
namespace v8 {
10+
namespace base {
11+
12+
const char* PosixDefaultTimezoneCache::LocalTimezone(double time) {
13+
if (std::isnan(time)) return "";
14+
time_t tv = static_cast<time_t>(std::floor(time / msPerSecond));
15+
struct tm tm;
16+
struct tm* t = localtime_r(&tv, &tm);
17+
if (!t || !t->tm_zone) return "";
18+
return t->tm_zone;
19+
}
20+
21+
double PosixDefaultTimezoneCache::LocalTimeOffset() {
22+
time_t tv = time(NULL);
23+
struct tm tm;
24+
struct tm* t = localtime_r(&tv, &tm);
25+
// tm_gmtoff includes any daylight savings offset, so subtract it.
26+
return static_cast<double>(t->tm_gmtoff * msPerSecond -
27+
(t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
28+
}
29+
30+
} // namespace base
31+
} // namespace v8
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "src/base/platform/platform-posix.h"
6+
7+
namespace v8 {
8+
namespace base {
9+
10+
class PosixDefaultTimezoneCache : public PosixTimezoneCache {
11+
public:
12+
const char* LocalTimezone(double time_ms) override;
13+
double LocalTimeOffset() override;
14+
15+
~PosixDefaultTimezoneCache() override {}
16+
};
17+
18+
} // namespace base
19+
} // namespace v8

deps/v8/src/base/platform/platform-posix.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,26 +388,6 @@ double OS::TimeCurrentMillis() {
388388
return Time::Now().ToJsTime();
389389
}
390390

391-
#if !V8_OS_AIX && !V8_OS_SOLARIS && !V8_OS_CYGWIN
392-
const char* PosixTimezoneCache::LocalTimezone(double time) {
393-
if (std::isnan(time)) return "";
394-
time_t tv = static_cast<time_t>(std::floor(time / msPerSecond));
395-
struct tm tm;
396-
struct tm* t = localtime_r(&tv, &tm);
397-
if (!t || !t->tm_zone) return "";
398-
return t->tm_zone;
399-
}
400-
401-
double PosixTimezoneCache::LocalTimeOffset() {
402-
time_t tv = time(NULL);
403-
struct tm tm;
404-
struct tm* t = localtime_r(&tv, &tm);
405-
// tm_gmtoff includes any daylight savings offset, so subtract it.
406-
return static_cast<double>(t->tm_gmtoff * msPerSecond -
407-
(t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
408-
}
409-
#endif
410-
411391
double PosixTimezoneCache::DaylightSavingsOffset(double time) {
412392
if (std::isnan(time)) return std::numeric_limits<double>::quiet_NaN();
413393
time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));

deps/v8/src/base/platform/platform-posix.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ namespace base {
1313

1414
class PosixTimezoneCache : public TimezoneCache {
1515
public:
16-
const char* LocalTimezone(double time_ms) override;
1716
double DaylightSavingsOffset(double time_ms) override;
18-
double LocalTimeOffset() override;
1917
void Clear() override {}
2018
~PosixTimezoneCache() override {}
2119

0 commit comments

Comments
 (0)