| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 14470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14481 default: | 14481 default: |
| 14482 UNREACHABLE(); | 14482 UNREACHABLE(); |
| 14483 return 0; | 14483 return 0; |
| 14484 } | 14484 } |
| 14485 } | 14485 } |
| 14486 | 14486 |
| 14487 | 14487 |
| 14488 Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { | 14488 Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { |
| 14489 uint8_t clamped_value = 0; | 14489 uint8_t clamped_value = 0; |
| 14490 if (index < static_cast<uint32_t>(length())) { | 14490 if (index < static_cast<uint32_t>(length())) { |
| 14491 if (value->IsSmi()) { | 14491 clamped_value = clampObjectToUint8(value); |
| 14492 int int_value = Smi::cast(value)->value(); | |
| 14493 if (int_value < 0) { | |
| 14494 clamped_value = 0; | |
| 14495 } else if (int_value > 255) { | |
| 14496 clamped_value = 255; | |
| 14497 } else { | |
| 14498 clamped_value = static_cast<uint8_t>(int_value); | |
| 14499 } | |
| 14500 } else if (value->IsHeapNumber()) { | |
| 14501 double double_value = HeapNumber::cast(value)->value(); | |
| 14502 if (!(double_value > 0)) { | |
| 14503 // NaN and less than zero clamp to zero. | |
| 14504 clamped_value = 0; | |
| 14505 } else if (double_value > 255) { | |
| 14506 // Greater than 255 clamp to 255. | |
| 14507 clamped_value = 255; | |
| 14508 } else { | |
| 14509 // Other doubles are rounded to the nearest integer. | |
| 14510 clamped_value = static_cast<uint8_t>(lrint(double_value)); | |
| 14511 } | |
| 14512 } else { | |
| 14513 // Clamp undefined to zero (default). All other types have been | |
| 14514 // converted to a number type further up in the call chain. | |
| 14515 ASSERT(value->IsUndefined()); | |
| 14516 } | |
| 14517 set(index, clamped_value); | 14492 set(index, clamped_value); |
| 14518 } | 14493 } |
| 14519 return Smi::FromInt(clamped_value); | 14494 return Smi::FromInt(clamped_value); |
| 14520 } | 14495 } |
| 14521 | 14496 |
| 14522 | 14497 |
| 14523 Handle<Object> ExternalUint8ClampedArray::SetValue( | 14498 Handle<Object> ExternalUint8ClampedArray::SetValue( |
| 14524 Handle<ExternalUint8ClampedArray> array, | 14499 Handle<ExternalUint8ClampedArray> array, |
| 14525 uint32_t index, | 14500 uint32_t index, |
| 14526 Handle<Object> value) { | 14501 Handle<Object> value) { |
| (...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16363 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16338 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16364 static const char* error_messages_[] = { | 16339 static const char* error_messages_[] = { |
| 16365 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16340 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16366 }; | 16341 }; |
| 16367 #undef ERROR_MESSAGES_TEXTS | 16342 #undef ERROR_MESSAGES_TEXTS |
| 16368 return error_messages_[reason]; | 16343 return error_messages_[reason]; |
| 16369 } | 16344 } |
| 16370 | 16345 |
| 16371 | 16346 |
| 16372 } } // namespace v8::internal | 16347 } } // namespace v8::internal |
| OLD | NEW |