Index: src/platform/time.cc |
diff --git a/src/platform/time.cc b/src/platform/time.cc |
index 756be9375a82f9feb1e6aa785f909fdba88886ff..ea6dd2c0bae6cfea3fc947b4c6f841c91a58b875 100644 |
--- a/src/platform/time.cc |
+++ b/src/platform/time.cc |
@@ -126,7 +126,9 @@ int64_t TimeDelta::InNanoseconds() const { |
#if V8_OS_MACOSX |
TimeDelta TimeDelta::FromMachTimespec(struct mach_timespec ts) { |
- ASSERT(ts.tv_nsec >= 0); |
+ ASSERT_GE(ts.tv_nsec, 0); |
+ ASSERT_LT(ts.tv_nsec, |
+ static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT |
return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond + |
ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
} |
@@ -144,6 +146,28 @@ struct mach_timespec TimeDelta::ToMachTimespec() const { |
#endif // V8_OS_MACOSX |
+#if V8_OS_POSIX |
+ |
+TimeDelta TimeDelta::FromTimespec(struct timespec ts) { |
+ ASSERT_GE(ts.tv_nsec, 0); |
+ ASSERT_LT(ts.tv_nsec, |
+ static_cast<long>(Time::kNanosecondsPerSecond)); // NOLINT |
+ return TimeDelta(ts.tv_sec * Time::kMicrosecondsPerSecond + |
+ ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
+} |
+ |
+ |
+struct timespec TimeDelta::ToTimespec() const { |
+ struct timespec ts; |
+ ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond; |
+ ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) * |
+ Time::kNanosecondsPerMicrosecond; |
+ return ts; |
+} |
+ |
+#endif // V8_OS_POSIX |
+ |
+ |
#if V8_OS_WIN |
// We implement time using the high-resolution timers so that we can get |