Index: src/base/bits.cc |
diff --git a/src/base/bits.cc b/src/base/bits.cc |
index 74d747fc9059f135cc2986b9b73f6ce473391534..1666229d5ccec1121ad56a3783d3d8022810591e 100644 |
--- a/src/base/bits.cc |
+++ b/src/base/bits.cc |
@@ -48,6 +48,21 @@ int32_t SignedMod32(int32_t lhs, int32_t rhs) { |
return lhs % rhs; |
} |
+ |
+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 bits |
} // namespace base |
} // namespace v8 |