| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 9084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9095 } | 9095 } |
| 9096 ASSERT_NE(NULL, result_double); | 9096 ASSERT_NE(NULL, result_double); |
| 9097 result_double->set_value(static_cast<double>(result)); | 9097 result_double->set_value(static_cast<double>(result)); |
| 9098 return result_double; | 9098 return result_double; |
| 9099 } | 9099 } |
| 9100 | 9100 |
| 9101 | 9101 |
| 9102 Object* ExternalPixelArray::SetValue(uint32_t index, Object* value) { | 9102 Object* ExternalPixelArray::SetValue(uint32_t index, Object* value) { |
| 9103 uint8_t clamped_value = 0; | 9103 uint8_t clamped_value = 0; |
| 9104 if (index < static_cast<uint32_t>(length())) { | 9104 if (index < static_cast<uint32_t>(length())) { |
| 9105 if (value->IsSmi()) { | 9105 clamped_value = NumberToClampedUInt8(value); |
| 9106 int int_value = Smi::cast(value)->value(); | |
| 9107 if (int_value < 0) { | |
| 9108 clamped_value = 0; | |
| 9109 } else if (int_value > 255) { | |
| 9110 clamped_value = 255; | |
| 9111 } else { | |
| 9112 clamped_value = static_cast<uint8_t>(int_value); | |
| 9113 } | |
| 9114 } else if (value->IsHeapNumber()) { | |
| 9115 double double_value = HeapNumber::cast(value)->value(); | |
| 9116 if (!(double_value > 0)) { | |
| 9117 // NaN and less than zero clamp to zero. | |
| 9118 clamped_value = 0; | |
| 9119 } else if (double_value > 255) { | |
| 9120 // Greater than 255 clamp to 255. | |
| 9121 clamped_value = 255; | |
| 9122 } else { | |
| 9123 // Other doubles are rounded to the nearest integer. | |
| 9124 clamped_value = static_cast<uint8_t>(double_value + 0.5); | |
| 9125 } | |
| 9126 } else { | |
| 9127 // Clamp undefined to zero (default). All other types have been | |
| 9128 // converted to a number type further up in the call chain. | |
| 9129 ASSERT(value->IsUndefined()); | |
| 9130 } | |
| 9131 set(index, clamped_value); | 9106 set(index, clamped_value); |
| 9132 } | 9107 } |
| 9133 return Smi::FromInt(clamped_value); | 9108 return Smi::FromInt(clamped_value); |
| 9134 } | 9109 } |
| 9135 | 9110 |
| 9136 | 9111 |
| 9137 template<typename ExternalArrayClass, typename ValueType> | 9112 template<typename ExternalArrayClass, typename ValueType> |
| 9138 static MaybeObject* ExternalArrayIntSetter(Heap* heap, | 9113 static MaybeObject* ExternalArrayIntSetter(Heap* heap, |
| 9139 ExternalArrayClass* receiver, | 9114 ExternalArrayClass* receiver, |
| 9140 uint32_t index, | 9115 uint32_t index, |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10317 if (break_point_objects()->IsUndefined()) return 0; | 10292 if (break_point_objects()->IsUndefined()) return 0; |
| 10318 // Single beak point. | 10293 // Single beak point. |
| 10319 if (!break_point_objects()->IsFixedArray()) return 1; | 10294 if (!break_point_objects()->IsFixedArray()) return 1; |
| 10320 // Multiple break points. | 10295 // Multiple break points. |
| 10321 return FixedArray::cast(break_point_objects())->length(); | 10296 return FixedArray::cast(break_point_objects())->length(); |
| 10322 } | 10297 } |
| 10323 #endif | 10298 #endif |
| 10324 | 10299 |
| 10325 | 10300 |
| 10326 } } // namespace v8::internal | 10301 } } // namespace v8::internal |
| OLD | NEW |