Skip to content

Commit bfb97b7

Browse files
Jaideep BajwaMylesBorins
Jaideep Bajwa
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 1a2f749 commit bfb97b7

12 files changed

+88
-30
lines changed

deps/v8/BUILD.gn

+2
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

+2-2
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

+4-1
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

+4-1
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

+4-2
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

+4-1
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) {
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
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

-20
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

-2
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

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#undef MAP_TYPE
3232

3333
#include "src/base/macros.h"
34+
#include "src/base/platform/platform-posix-time.h"
3435
#include "src/base/platform/platform-posix.h"
3536
#include "src/base/platform/platform.h"
3637

@@ -84,7 +85,9 @@ bool OS::ArmUsingHardFloat() {
8485

8586
#endif // __arm__
8687

87-
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
88+
TimezoneCache* OS::CreateTimezoneCache() {
89+
return new PosixDefaultTimezoneCache();
90+
}
8891

8992
void* OS::Allocate(const size_t requested, size_t* allocated,
9093
OS::MemoryPermission access) {

deps/v8/src/v8.gyp

+14
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,8 @@
20632063
'base/platform/platform-linux.cc',
20642064
'base/platform/platform-posix.h',
20652065
'base/platform/platform-posix.cc',
2066+
'base/platform/platform-posix-time.h',
2067+
'base/platform/platform-posix-time.cc',
20662068
],
20672069
}
20682070
],
@@ -2071,6 +2073,8 @@
20712073
'base/debug/stack_trace_android.cc',
20722074
'base/platform/platform-posix.h',
20732075
'base/platform/platform-posix.cc',
2076+
'base/platform/platform-posix-time.h',
2077+
'base/platform/platform-posix-time.cc',
20742078
],
20752079
'link_settings': {
20762080
'target_conditions': [
@@ -2127,6 +2131,8 @@
21272131
'base/debug/stack_trace_posix.cc',
21282132
'base/platform/platform-posix.h',
21292133
'base/platform/platform-posix.cc',
2134+
'base/platform/platform-posix-time.h',
2135+
'base/platform/platform-posix-time.cc',
21302136
'base/qnx-math.h'
21312137
],
21322138
'target_conditions': [
@@ -2158,6 +2164,8 @@
21582164
'base/platform/platform-freebsd.cc',
21592165
'base/platform/platform-posix.h',
21602166
'base/platform/platform-posix.cc',
2167+
'base/platform/platform-posix-time.h',
2168+
'base/platform/platform-posix-time.cc',
21612169
],
21622170
}
21632171
],
@@ -2170,6 +2178,8 @@
21702178
'base/platform/platform-openbsd.cc',
21712179
'base/platform/platform-posix.h',
21722180
'base/platform/platform-posix.cc'
2181+
'base/platform/platform-posix-time.h',
2182+
'base/platform/platform-posix-time.cc',
21732183
],
21742184
}
21752185
],
@@ -2183,6 +2193,8 @@
21832193
'base/platform/platform-openbsd.cc',
21842194
'base/platform/platform-posix.h',
21852195
'base/platform/platform-posix.cc',
2196+
'base/platform/platform-posix-time.h',
2197+
'base/platform/platform-posix-time.cc',
21862198
],
21872199
}
21882200
],
@@ -2213,6 +2225,8 @@
22132225
'base/platform/platform-macos.cc',
22142226
'base/platform/platform-posix.h',
22152227
'base/platform/platform-posix.cc',
2228+
'base/platform/platform-posix-time.h',
2229+
'base/platform/platform-posix-time.cc',
22162230
]},
22172231
],
22182232
['OS=="win"', {

0 commit comments

Comments
 (0)