Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: src/conversions-inl.h

Issue 1290743005: Make some foo.h headers usable without foo-inl.h header. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: As per offline comment. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/conversions.h ('k') | src/layout-descriptor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions-inl.h
diff --git a/src/conversions-inl.h b/src/conversions-inl.h
index ae87dc4d31b01763eef756a1058a05ca0dc1561e..d9f16ade2eda6b69e2d2c2e3892acc0bd5ffea63 100644
--- a/src/conversions-inl.h
+++ b/src/conversions-inl.h
@@ -18,6 +18,7 @@
#include "src/base/platform/platform.h"
#include "src/conversions.h"
#include "src/double.h"
+#include "src/objects-inl.h"
#include "src/scanner.h"
#include "src/strtod.h"
@@ -97,6 +98,68 @@ int32_t DoubleToInt32(double x) {
}
+bool IsSmiDouble(double value) {
+ return !IsMinusZero(value) && value >= Smi::kMinValue &&
+ value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
+}
+
+
+bool IsInt32Double(double value) {
+ return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt &&
+ value == FastI2D(FastD2I(value));
+}
+
+
+bool IsUint32Double(double value) {
+ return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 &&
+ value == FastUI2D(FastD2UI(value));
+}
+
+
+int32_t NumberToInt32(Object* number) {
+ if (number->IsSmi()) return Smi::cast(number)->value();
+ return DoubleToInt32(number->Number());
+}
+
+
+uint32_t NumberToUint32(Object* number) {
+ if (number->IsSmi()) return Smi::cast(number)->value();
+ return DoubleToUint32(number->Number());
+}
+
+
+bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) {
+ SealHandleScope shs(isolate);
+ if (number->IsSmi()) {
+ int value = Smi::cast(number)->value();
+ DCHECK(static_cast<unsigned>(Smi::kMaxValue) <=
+ std::numeric_limits<size_t>::max());
+ if (value >= 0) {
+ *result = static_cast<size_t>(value);
+ return true;
+ }
+ return false;
+ } else {
+ DCHECK(number->IsHeapNumber());
+ double value = HeapNumber::cast(number)->value();
+ if (value >= 0 && value <= std::numeric_limits<size_t>::max()) {
+ *result = static_cast<size_t>(value);
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
+
+size_t NumberToSize(Isolate* isolate, Object* number) {
+ size_t result = 0;
+ bool is_valid = TryNumberToSize(isolate, number, &result);
+ CHECK(is_valid);
+ return result;
+}
+
+
template <class Iterator, class EndMark>
bool SubStringEquals(Iterator* current,
EndMark end,
« no previous file with comments | « src/conversions.h ('k') | src/layout-descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698