Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <littledan@chromium.org>
    Commit-Queue: Jaideep Bajwa <bjaideep@ca.ibm.com>
    Cr-Commit-Position: refs/heads/master@{#46604}
  • Loading branch information
Jaideep Bajwa committed Aug 14, 2017
commit d3dd7064b0491f9601e8da5ac4b850d868c99fe7
2 changes: 2 additions & 0 deletions deps/v8/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
5 changes: 4 additions & 1 deletion deps/v8/src/base/platform/platform-freebsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion deps/v8/src/base/platform/platform-linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions deps/v8/src/base/platform/platform-macos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -97,7 +97,9 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
void OS::SignalCodeMovingGC() {
}

TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}

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

Expand Down
5 changes: 4 additions & 1 deletion deps/v8/src/base/platform/platform-openbsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions deps/v8/src/base/platform/platform-posix-time.cc
Original file line number Diff line number Diff line change
@@ -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 <cmath>

#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<time_t>(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<double>(t->tm_gmtoff * msPerSecond -
(t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
}

} // namespace base
} // namespace v8
19 changes: 19 additions & 0 deletions deps/v8/src/base/platform/platform-posix-time.h
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions deps/v8/src/base/platform/platform-posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<time_t>(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<double>(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<double>::quiet_NaN();
time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
Expand Down
2 changes: 0 additions & 2 deletions deps/v8/src/base/platform/platform-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
5 changes: 4 additions & 1 deletion deps/v8/src/base/platform/platform-qnx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions deps/v8/src/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
}
],
Expand All @@ -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': [
Expand Down Expand Up @@ -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': [
Expand Down Expand Up @@ -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',
],
}
],
Expand All @@ -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',
],
}
],
Expand All @@ -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',
],
}
],
Expand Down Expand Up @@ -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"', {
Expand Down