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

Unified Diff: src/runtime.cc

Issue 9040: * Added check for HeapNumber in the fast-cast Smi switch. (Closed)
Patch Set: Fix ofr Issue 137. Addressed reviewer comments Created 12 years, 1 month 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/runtime.h ('k') | test/mjsunit/regress/regress-137.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 197aae6079682e54e10b7b1eb4fdfc18d7162126..c76d9b47866401e5e31fe140a551d0e867419147 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2554,6 +2554,26 @@ static Object* Runtime_NumberToJSInt32(Arguments args) {
}
+// Converts a Number to a Smi, if possible. Returns NaN if the number is not
+// a small integer.
+static Object* Runtime_NumberToSmi(Arguments args) {
+ NoHandleAllocation ha;
+ ASSERT(args.length() == 1);
+
+ Object* obj = args[0];
+ if (obj->IsSmi()) {
+ return obj;
+ }
+ if (obj->IsHeapNumber()) {
+ double value = HeapNumber::cast(obj)->value();
+ int int_value = FastD2I(value);
+ if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
+ return Smi::FromInt(int_value);
+ }
+ }
+ return Heap::nan_value();
+}
+
static Object* Runtime_NumberAdd(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 2);
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/regress/regress-137.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698