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

Side by Side Diff: src/objects.cc

Issue 159518: - Clamp double values as doubles to get a free NaN check and... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 6967 matching lines...) Expand 10 before | Expand all | Expand 10 after
6978 } 6978 }
6979 ASSERT_NE(NULL, result_double); 6979 ASSERT_NE(NULL, result_double);
6980 result_double->set_value(static_cast<double>(result)); 6980 result_double->set_value(static_cast<double>(result));
6981 return result_double; 6981 return result_double;
6982 } 6982 }
6983 6983
6984 6984
6985 Object* PixelArray::SetValue(uint32_t index, Object* value) { 6985 Object* PixelArray::SetValue(uint32_t index, Object* value) {
6986 uint8_t clamped_value = 0; 6986 uint8_t clamped_value = 0;
6987 if (index < static_cast<uint32_t>(length())) { 6987 if (index < static_cast<uint32_t>(length())) {
6988 int int_value = 0;
6989 if (value->IsSmi()) { 6988 if (value->IsSmi()) {
6990 int_value = Smi::cast(value)->value(); 6989 int int_value = Smi::cast(value)->value();
6990 if (int_value < 0) {
6991 clamped_value = 0;
6992 } else if (int_value > 255) {
6993 clamped_value = 255;
6994 } else {
6995 clamped_value = static_cast<uint8_t>(int_value);
6996 }
6991 } else if (value->IsHeapNumber()) { 6997 } else if (value->IsHeapNumber()) {
6992 double double_value = HeapNumber::cast(value)->value(); 6998 double double_value = HeapNumber::cast(value)->value();
6993 if (!isnan(double_value)) { 6999 if (!(double_value > 0)) {
6994 // NaN clamps to zero (default). Other doubles are rounded to 7000 // NaN and less than zero clamp to zero.
6995 // the nearest integer. 7001 clamped_value = 0;
6996 int_value = static_cast<int>(double_value + 0.5); 7002 } else if (double_value > 255) {
7003 // Greater than 255 clamp to 255.
7004 clamped_value = 255;
7005 } else {
7006 // Other doubles are rounded to the nearest integer.
7007 clamped_value = static_cast<uint8_t>(double_value + 0.5);
6997 } 7008 }
6998 } else { 7009 } else {
6999 // Clamp undefined to zero (default). All other types have been 7010 // Clamp undefined to zero (default). All other types have been
7000 // converted to a number type further up in the call chain. 7011 // converted to a number type further up in the call chain.
7001 ASSERT(value->IsUndefined()); 7012 ASSERT(value->IsUndefined());
7002 } 7013 }
7003 if (int_value < 0) {
7004 clamped_value = 0;
7005 } else if (int_value > 255) {
7006 clamped_value = 255;
7007 } else {
7008 clamped_value = static_cast<uint8_t>(int_value);
7009 }
7010 set(index, clamped_value); 7014 set(index, clamped_value);
7011 } 7015 }
7012 return Smi::FromInt(clamped_value); 7016 return Smi::FromInt(clamped_value);
7013 } 7017 }
7014 7018
7015 7019
7016 Object* GlobalObject::GetPropertyCell(LookupResult* result) { 7020 Object* GlobalObject::GetPropertyCell(LookupResult* result) {
7017 ASSERT(!HasFastProperties()); 7021 ASSERT(!HasFastProperties());
7018 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry()); 7022 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry());
7019 ASSERT(value->IsJSGlobalPropertyCell()); 7023 ASSERT(value->IsJSGlobalPropertyCell());
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
7922 if (break_point_objects()->IsUndefined()) return 0; 7926 if (break_point_objects()->IsUndefined()) return 0;
7923 // Single beak point. 7927 // Single beak point.
7924 if (!break_point_objects()->IsFixedArray()) return 1; 7928 if (!break_point_objects()->IsFixedArray()) return 1;
7925 // Multiple break points. 7929 // Multiple break points.
7926 return FixedArray::cast(break_point_objects())->length(); 7930 return FixedArray::cast(break_point_objects())->length();
7927 } 7931 }
7928 #endif 7932 #endif
7929 7933
7930 7934
7931 } } // namespace v8::internal 7935 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698