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

Unified Diff: src/objects-inl.h

Issue 1003663002: Add Cast() for Int32 and Uint32 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« src/api.cc ('K') | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 779fd39ef96f9c9b78456d0c22a1cb87efc05a15..2781ccff2e0530643a5d87a1473afefd22bec920 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -635,6 +635,26 @@ bool Object::IsNumber() const {
}
+bool Object::IsInt32() const {
+ if (IsSmi()) return true;
+ if (IsNumber()) {
+ return IsInt32Double(Number());
+ }
+ return false;
+}
+
+
+bool Object::IsUint32() const {
+ if (IsSmi()) return Smi::cast(this)->value() >= 0;
+ if (IsNumber()) {
+ double value = Number();
+ return !i::IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 &&
+ value == FastUI2D(i::FastD2UI(value));
+ }
+ return false;
+}
+
+
TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE)
TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE)
@@ -1091,11 +1111,11 @@ bool Object::IsArgumentsMarker() const {
}
-double Object::Number() {
+double Object::Number() const {
DCHECK(IsNumber());
return IsSmi()
- ? static_cast<double>(reinterpret_cast<Smi*>(this)->value())
- : reinterpret_cast<HeapNumber*>(this)->value();
+ ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value())
+ : reinterpret_cast<const HeapNumber*>(this)->value();
}
« src/api.cc ('K') | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698