| Index: src/base/platform/time.cc
|
| diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc
|
| index 6d5e538970cfd8e8b3608c196b79c361a44c4107..fed39fc9f74649d09ec8e667bec84387a4237bfe 100644
|
| --- a/src/base/platform/time.cc
|
| +++ b/src/base/platform/time.cc
|
| @@ -28,6 +28,37 @@
|
| namespace v8 {
|
| namespace base {
|
|
|
| +namespace time_internal {
|
| +
|
| +int64_t SaturatedAdd(TimeDelta delta, int64_t value) {
|
| + CheckedNumeric<int64_t> rv(delta.delta_);
|
| + rv += value;
|
| + return FromCheckedNumeric(rv);
|
| +}
|
| +
|
| +int64_t SaturatedSub(TimeDelta delta, int64_t value) {
|
| + CheckedNumeric<int64_t> rv(delta.delta_);
|
| + rv -= value;
|
| + return FromCheckedNumeric(rv);
|
| +}
|
| +
|
| +int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value) {
|
| + if (value.IsValid())
|
| + return value.ValueUnsafe();
|
| +
|
| + // We could return max/min but we don't really expose what the maximum delta
|
| + // is. Instead, return max/(-max), which is something that clients can reason
|
| + // about.
|
| + // TODO(rvargas) crbug.com/332611: don't use internal values.
|
| + int64_t limit = std::numeric_limits<int64_t>::max();
|
| + if (value.validity() == internal::RANGE_UNDERFLOW)
|
| + limit = -limit;
|
| + return value.ValueOrDefault(limit);
|
| +}
|
| +
|
| +} // namespace time_internal
|
| +
|
| +
|
| TimeDelta TimeDelta::FromDays(int days) {
|
| return TimeDelta(days * Time::kMicrosecondsPerDay);
|
| }
|
|
|