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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/regress/regress-137.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 NoHandleAllocation ha; 2547 NoHandleAllocation ha;
2548 ASSERT(args.length() == 1); 2548 ASSERT(args.length() == 1);
2549 2549
2550 Object* obj = args[0]; 2550 Object* obj = args[0];
2551 if (obj->IsSmi()) return obj; 2551 if (obj->IsSmi()) return obj;
2552 CONVERT_DOUBLE_CHECKED(number, obj); 2552 CONVERT_DOUBLE_CHECKED(number, obj);
2553 return Heap::NumberFromInt32(DoubleToInt32(number)); 2553 return Heap::NumberFromInt32(DoubleToInt32(number));
2554 } 2554 }
2555 2555
2556 2556
2557 // Converts a Number to a Smi, if possible. Returns NaN if the number is not
2558 // a small integer.
2559 static Object* Runtime_NumberToSmi(Arguments args) {
2560 NoHandleAllocation ha;
2561 ASSERT(args.length() == 1);
2562
2563 Object* obj = args[0];
2564 if (obj->IsSmi()) {
2565 return obj;
2566 }
2567 if (obj->IsHeapNumber()) {
2568 double value = HeapNumber::cast(obj)->value();
2569 int int_value = FastD2I(value);
2570 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
2571 return Smi::FromInt(int_value);
2572 }
2573 }
2574 return Heap::nan_value();
2575 }
2576
2557 static Object* Runtime_NumberAdd(Arguments args) { 2577 static Object* Runtime_NumberAdd(Arguments args) {
2558 NoHandleAllocation ha; 2578 NoHandleAllocation ha;
2559 ASSERT(args.length() == 2); 2579 ASSERT(args.length() == 2);
2560 2580
2561 CONVERT_DOUBLE_CHECKED(x, args[0]); 2581 CONVERT_DOUBLE_CHECKED(x, args[0]);
2562 CONVERT_DOUBLE_CHECKED(y, args[1]); 2582 CONVERT_DOUBLE_CHECKED(y, args[1]);
2563 return Heap::AllocateHeapNumber(x + y); 2583 return Heap::AllocateHeapNumber(x + y);
2564 } 2584 }
2565 2585
2566 2586
(...skipping 3236 matching lines...) Expand 10 before | Expand all | Expand 10 after
5803 } else { 5823 } else {
5804 // Handle last resort GC and make sure to allow future allocations 5824 // Handle last resort GC and make sure to allow future allocations
5805 // to grow the heap without causing GCs (if possible). 5825 // to grow the heap without causing GCs (if possible).
5806 Counters::gc_last_resort_from_js.Increment(); 5826 Counters::gc_last_resort_from_js.Increment();
5807 Heap::CollectAllGarbage(); 5827 Heap::CollectAllGarbage();
5808 } 5828 }
5809 } 5829 }
5810 5830
5811 5831
5812 } } // namespace v8::internal 5832 } } // namespace v8::internal
OLDNEW
« 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