From a19221e60b9e6205e8363302c53e778a624b86bf Mon Sep 17 00:00:00 2001 From: Jaideep Bajwa Date: Thu, 3 Aug 2017 10:54:59 -0400 Subject: [PATCH] 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. R=littledan@chromium.org, ulan@chromium.org BUG=v8:6578 LOG=N Change-Id: I58342893aeefe79ac50e1df041d614fc473f15bf Reviewed-on: https://chromium-review.googlesource.com/568686 Reviewed-by: Daniel Ehrenberg Commit-Queue: Jaideep Bajwa Cr-Commit-Position: refs/heads/master@{#46604} PR-URL: https://github.com/nodejs/node/pull/14608 Reviewed-By: Ben Noordhuis Reviewed-By: Gireesh Punathil Reviewed-By: James M Snell --- deps/v8/BUILD.gn | 2 ++ deps/v8/include/v8-version.h | 4 +-- deps/v8/src/base/platform/platform-freebsd.cc | 5 ++- deps/v8/src/base/platform/platform-linux.cc | 5 ++- deps/v8/src/base/platform/platform-macos.cc | 6 ++-- deps/v8/src/base/platform/platform-openbsd.cc | 5 ++- .../src/base/platform/platform-posix-time.cc | 31 +++++++++++++++++++ .../src/base/platform/platform-posix-time.h | 19 ++++++++++++ deps/v8/src/base/platform/platform-posix.cc | 20 ------------ deps/v8/src/base/platform/platform-posix.h | 2 -- deps/v8/src/base/platform/platform-qnx.cc | 5 ++- deps/v8/src/v8.gyp | 14 +++++++++ 12 files changed, 88 insertions(+), 30 deletions(-) create mode 100644 deps/v8/src/base/platform/platform-posix-time.cc create mode 100644 deps/v8/src/base/platform/platform-posix-time.h diff --git a/deps/v8/BUILD.gn b/deps/v8/BUILD.gn index 2060cb19817059..b60425df45b469 100644 --- a/deps/v8/BUILD.gn +++ b/deps/v8/BUILD.gn @@ -2507,6 +2507,8 @@ v8_component("v8_libbase") { if (is_posix) { sources += [ + "src/base/platform/platform-posix-time.cc", + "src/base/platform/platform-posix-time.h", "src/base/platform/platform-posix.cc", "src/base/platform/platform-posix.h", ] diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index 0889459ca778da..db9369f649a9e5 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -10,8 +10,8 @@ // system so their names cannot be changed without changing the scripts. #define V8_MAJOR_VERSION 6 #define V8_MINOR_VERSION 0 -#define V8_BUILD_NUMBER 286 -#define V8_PATCH_LEVEL 52 +#define V8_BUILD_NUMBER 287 +#define V8_PATCH_LEVEL 53 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/src/base/platform/platform-freebsd.cc b/deps/v8/src/base/platform/platform-freebsd.cc index 5c5b8a0d3b04bb..9ab1601e7a81d9 100644 --- a/deps/v8/src/base/platform/platform-freebsd.cc +++ b/deps/v8/src/base/platform/platform-freebsd.cc @@ -29,13 +29,16 @@ #undef MAP_TYPE #include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" #include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" namespace v8 { namespace base { -TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); } +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} void* OS::Allocate(const size_t requested, size_t* allocated, OS::MemoryPermission access) { diff --git a/deps/v8/src/base/platform/platform-linux.cc b/deps/v8/src/base/platform/platform-linux.cc index 483cdd49ca91d5..ba161b26c73b0c 100644 --- a/deps/v8/src/base/platform/platform-linux.cc +++ b/deps/v8/src/base/platform/platform-linux.cc @@ -44,6 +44,7 @@ #undef MAP_TYPE #include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" #include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" @@ -92,7 +93,9 @@ bool OS::ArmUsingHardFloat() { #endif // def __arm__ -TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); } +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} void* OS::Allocate(const size_t requested, size_t* allocated, OS::MemoryPermission access) { diff --git a/deps/v8/src/base/platform/platform-macos.cc b/deps/v8/src/base/platform/platform-macos.cc index 7d1a6d24719902..50ac55d880e89e 100644 --- a/deps/v8/src/base/platform/platform-macos.cc +++ b/deps/v8/src/base/platform/platform-macos.cc @@ -36,10 +36,10 @@ #undef MAP_TYPE #include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" #include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" - namespace v8 { namespace base { @@ -97,7 +97,9 @@ std::vector OS::GetSharedLibraryAddresses() { void OS::SignalCodeMovingGC() { } -TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); } +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } diff --git a/deps/v8/src/base/platform/platform-openbsd.cc b/deps/v8/src/base/platform/platform-openbsd.cc index 06040e2f404d8f..0056ad56d49765 100644 --- a/deps/v8/src/base/platform/platform-openbsd.cc +++ b/deps/v8/src/base/platform/platform-openbsd.cc @@ -27,13 +27,16 @@ #undef MAP_TYPE #include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" #include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" namespace v8 { namespace base { -TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); } +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} void* OS::Allocate(const size_t requested, size_t* allocated, OS::MemoryPermission access) { diff --git a/deps/v8/src/base/platform/platform-posix-time.cc b/deps/v8/src/base/platform/platform-posix-time.cc new file mode 100644 index 00000000000000..a960f7237eaa20 --- /dev/null +++ b/deps/v8/src/base/platform/platform-posix-time.cc @@ -0,0 +1,31 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "src/base/platform/platform-posix-time.h" + +namespace v8 { +namespace base { + +const char* PosixDefaultTimezoneCache::LocalTimezone(double time) { + if (std::isnan(time)) return ""; + time_t tv = static_cast(std::floor(time / msPerSecond)); + struct tm tm; + struct tm* t = localtime_r(&tv, &tm); + if (!t || !t->tm_zone) return ""; + return t->tm_zone; +} + +double PosixDefaultTimezoneCache::LocalTimeOffset() { + time_t tv = time(NULL); + struct tm tm; + struct tm* t = localtime_r(&tv, &tm); + // tm_gmtoff includes any daylight savings offset, so subtract it. + return static_cast(t->tm_gmtoff * msPerSecond - + (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); +} + +} // namespace base +} // namespace v8 diff --git a/deps/v8/src/base/platform/platform-posix-time.h b/deps/v8/src/base/platform/platform-posix-time.h new file mode 100644 index 00000000000000..945ea3b2e9eee3 --- /dev/null +++ b/deps/v8/src/base/platform/platform-posix-time.h @@ -0,0 +1,19 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/base/platform/platform-posix.h" + +namespace v8 { +namespace base { + +class PosixDefaultTimezoneCache : public PosixTimezoneCache { + public: + const char* LocalTimezone(double time_ms) override; + double LocalTimeOffset() override; + + ~PosixDefaultTimezoneCache() override {} +}; + +} // namespace base +} // namespace v8 diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc index 25c270ad28605b..621abbe6f17fa1 100644 --- a/deps/v8/src/base/platform/platform-posix.cc +++ b/deps/v8/src/base/platform/platform-posix.cc @@ -388,26 +388,6 @@ double OS::TimeCurrentMillis() { return Time::Now().ToJsTime(); } -#if !V8_OS_AIX && !V8_OS_SOLARIS && !V8_OS_CYGWIN -const char* PosixTimezoneCache::LocalTimezone(double time) { - if (std::isnan(time)) return ""; - time_t tv = static_cast(std::floor(time / msPerSecond)); - struct tm tm; - struct tm* t = localtime_r(&tv, &tm); - if (!t || !t->tm_zone) return ""; - return t->tm_zone; -} - -double PosixTimezoneCache::LocalTimeOffset() { - time_t tv = time(NULL); - struct tm tm; - struct tm* t = localtime_r(&tv, &tm); - // tm_gmtoff includes any daylight savings offset, so subtract it. - return static_cast(t->tm_gmtoff * msPerSecond - - (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); -} -#endif - double PosixTimezoneCache::DaylightSavingsOffset(double time) { if (std::isnan(time)) return std::numeric_limits::quiet_NaN(); time_t tv = static_cast(std::floor(time/msPerSecond)); diff --git a/deps/v8/src/base/platform/platform-posix.h b/deps/v8/src/base/platform/platform-posix.h index 9818f642476c29..b092bb526dfd86 100644 --- a/deps/v8/src/base/platform/platform-posix.h +++ b/deps/v8/src/base/platform/platform-posix.h @@ -13,9 +13,7 @@ namespace base { class PosixTimezoneCache : public TimezoneCache { public: - const char* LocalTimezone(double time_ms) override; double DaylightSavingsOffset(double time_ms) override; - double LocalTimeOffset() override; void Clear() override {} ~PosixTimezoneCache() override {} diff --git a/deps/v8/src/base/platform/platform-qnx.cc b/deps/v8/src/base/platform/platform-qnx.cc index 7ce3de119d69b8..f151bba8bb7474 100644 --- a/deps/v8/src/base/platform/platform-qnx.cc +++ b/deps/v8/src/base/platform/platform-qnx.cc @@ -31,6 +31,7 @@ #undef MAP_TYPE #include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" #include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" @@ -84,7 +85,9 @@ bool OS::ArmUsingHardFloat() { #endif // __arm__ -TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); } +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} void* OS::Allocate(const size_t requested, size_t* allocated, OS::MemoryPermission access) { diff --git a/deps/v8/src/v8.gyp b/deps/v8/src/v8.gyp index 8015a6bda634cf..c269f245aaa65b 100644 --- a/deps/v8/src/v8.gyp +++ b/deps/v8/src/v8.gyp @@ -2063,6 +2063,8 @@ 'base/platform/platform-linux.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ], } ], @@ -2071,6 +2073,8 @@ 'base/debug/stack_trace_android.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ], 'link_settings': { 'target_conditions': [ @@ -2127,6 +2131,8 @@ 'base/debug/stack_trace_posix.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', 'base/qnx-math.h' ], 'target_conditions': [ @@ -2158,6 +2164,8 @@ 'base/platform/platform-freebsd.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ], } ], @@ -2170,6 +2178,8 @@ 'base/platform/platform-openbsd.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc' + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ], } ], @@ -2183,6 +2193,8 @@ 'base/platform/platform-openbsd.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ], } ], @@ -2213,6 +2225,8 @@ 'base/platform/platform-macos.cc', 'base/platform/platform-posix.h', 'base/platform/platform-posix.cc', + 'base/platform/platform-posix-time.h', + 'base/platform/platform-posix-time.cc', ]}, ], ['OS=="win"', {