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

Side by Side Diff: src/objects.cc

Issue 328007: Stop throwing exceptions for out-of-range accesses to CanvasArrays.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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 | « src/messages.js ('k') | 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 6032 matching lines...) Expand 10 before | Expand all | Expand 10 after
6043 return Smi::FromInt(value); 6043 return Smi::FromInt(value);
6044 } 6044 }
6045 break; 6045 break;
6046 } 6046 }
6047 case EXTERNAL_BYTE_ELEMENTS: { 6047 case EXTERNAL_BYTE_ELEMENTS: {
6048 ExternalByteArray* array = ExternalByteArray::cast(elements()); 6048 ExternalByteArray* array = ExternalByteArray::cast(elements());
6049 if (index < static_cast<uint32_t>(array->length())) { 6049 if (index < static_cast<uint32_t>(array->length())) {
6050 int8_t value = array->get(index); 6050 int8_t value = array->get(index);
6051 return Smi::FromInt(value); 6051 return Smi::FromInt(value);
6052 } 6052 }
6053 return Top::Throw(*Factory::NewIndexError(index)); 6053 break;
6054 } 6054 }
6055 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { 6055 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
6056 ExternalUnsignedByteArray* array = 6056 ExternalUnsignedByteArray* array =
6057 ExternalUnsignedByteArray::cast(elements()); 6057 ExternalUnsignedByteArray::cast(elements());
6058 if (index < static_cast<uint32_t>(array->length())) { 6058 if (index < static_cast<uint32_t>(array->length())) {
6059 uint8_t value = array->get(index); 6059 uint8_t value = array->get(index);
6060 return Smi::FromInt(value); 6060 return Smi::FromInt(value);
6061 } 6061 }
6062 return Top::Throw(*Factory::NewIndexError(index)); 6062 break;
6063 } 6063 }
6064 case EXTERNAL_SHORT_ELEMENTS: { 6064 case EXTERNAL_SHORT_ELEMENTS: {
6065 ExternalShortArray* array = ExternalShortArray::cast(elements()); 6065 ExternalShortArray* array = ExternalShortArray::cast(elements());
6066 if (index < static_cast<uint32_t>(array->length())) { 6066 if (index < static_cast<uint32_t>(array->length())) {
6067 int16_t value = array->get(index); 6067 int16_t value = array->get(index);
6068 return Smi::FromInt(value); 6068 return Smi::FromInt(value);
6069 } 6069 }
6070 return Top::Throw(*Factory::NewIndexError(index)); 6070 break;
6071 } 6071 }
6072 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { 6072 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
6073 ExternalUnsignedShortArray* array = 6073 ExternalUnsignedShortArray* array =
6074 ExternalUnsignedShortArray::cast(elements()); 6074 ExternalUnsignedShortArray::cast(elements());
6075 if (index < static_cast<uint32_t>(array->length())) { 6075 if (index < static_cast<uint32_t>(array->length())) {
6076 uint16_t value = array->get(index); 6076 uint16_t value = array->get(index);
6077 return Smi::FromInt(value); 6077 return Smi::FromInt(value);
6078 } 6078 }
6079 return Top::Throw(*Factory::NewIndexError(index)); 6079 break;
6080 } 6080 }
6081 case EXTERNAL_INT_ELEMENTS: { 6081 case EXTERNAL_INT_ELEMENTS: {
6082 ExternalIntArray* array = ExternalIntArray::cast(elements()); 6082 ExternalIntArray* array = ExternalIntArray::cast(elements());
6083 if (index < static_cast<uint32_t>(array->length())) { 6083 if (index < static_cast<uint32_t>(array->length())) {
6084 int32_t value = array->get(index); 6084 int32_t value = array->get(index);
6085 return Heap::NumberFromInt32(value); 6085 return Heap::NumberFromInt32(value);
6086 } 6086 }
6087 return Top::Throw(*Factory::NewIndexError(index)); 6087 break;
6088 } 6088 }
6089 case EXTERNAL_UNSIGNED_INT_ELEMENTS: { 6089 case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
6090 ExternalUnsignedIntArray* array = 6090 ExternalUnsignedIntArray* array =
6091 ExternalUnsignedIntArray::cast(elements()); 6091 ExternalUnsignedIntArray::cast(elements());
6092 if (index < static_cast<uint32_t>(array->length())) { 6092 if (index < static_cast<uint32_t>(array->length())) {
6093 uint32_t value = array->get(index); 6093 uint32_t value = array->get(index);
6094 return Heap::NumberFromUint32(value); 6094 return Heap::NumberFromUint32(value);
6095 } 6095 }
6096 return Top::Throw(*Factory::NewIndexError(index)); 6096 break;
6097 } 6097 }
6098 case EXTERNAL_FLOAT_ELEMENTS: { 6098 case EXTERNAL_FLOAT_ELEMENTS: {
6099 ExternalFloatArray* array = ExternalFloatArray::cast(elements()); 6099 ExternalFloatArray* array = ExternalFloatArray::cast(elements());
6100 if (index < static_cast<uint32_t>(array->length())) { 6100 if (index < static_cast<uint32_t>(array->length())) {
6101 float value = array->get(index); 6101 float value = array->get(index);
6102 return Heap::AllocateHeapNumber(value); 6102 return Heap::AllocateHeapNumber(value);
6103 } 6103 }
6104 return Top::Throw(*Factory::NewIndexError(index)); 6104 break;
6105 } 6105 }
6106 case DICTIONARY_ELEMENTS: { 6106 case DICTIONARY_ELEMENTS: {
6107 NumberDictionary* dictionary = element_dictionary(); 6107 NumberDictionary* dictionary = element_dictionary();
6108 int entry = dictionary->FindEntry(index); 6108 int entry = dictionary->FindEntry(index);
6109 if (entry != NumberDictionary::kNotFound) { 6109 if (entry != NumberDictionary::kNotFound) {
6110 Object* element = dictionary->ValueAt(entry); 6110 Object* element = dictionary->ValueAt(entry);
6111 PropertyDetails details = dictionary->DetailsAt(entry); 6111 PropertyDetails details = dictionary->DetailsAt(entry);
6112 if (details.type() == CALLBACKS) { 6112 if (details.type() == CALLBACKS) {
6113 // Only accessors allowed as elements. 6113 // Only accessors allowed as elements.
6114 FixedArray* structure = FixedArray::cast(element); 6114 FixedArray* structure = FixedArray::cast(element);
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
7313 cast_value = static_cast<ValueType>(int_value); 7313 cast_value = static_cast<ValueType>(int_value);
7314 } else if (value->IsHeapNumber()) { 7314 } else if (value->IsHeapNumber()) {
7315 double double_value = HeapNumber::cast(value)->value(); 7315 double double_value = HeapNumber::cast(value)->value();
7316 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); 7316 cast_value = static_cast<ValueType>(DoubleToInt32(double_value));
7317 } else { 7317 } else {
7318 // Clamp undefined to zero (default). All other types have been 7318 // Clamp undefined to zero (default). All other types have been
7319 // converted to a number type further up in the call chain. 7319 // converted to a number type further up in the call chain.
7320 ASSERT(value->IsUndefined()); 7320 ASSERT(value->IsUndefined());
7321 } 7321 }
7322 receiver->set(index, cast_value); 7322 receiver->set(index, cast_value);
7323 } else {
7324 return Top::Throw(*Factory::NewIndexError(index));
7325 } 7323 }
7326 return Heap::NumberFromInt32(cast_value); 7324 return Heap::NumberFromInt32(cast_value);
7327 } 7325 }
7328 7326
7329 7327
7330 Object* ExternalByteArray::SetValue(uint32_t index, Object* value) { 7328 Object* ExternalByteArray::SetValue(uint32_t index, Object* value) {
7331 return ExternalArrayIntSetter<ExternalByteArray, int8_t> 7329 return ExternalArrayIntSetter<ExternalByteArray, int8_t>
7332 (this, index, value); 7330 (this, index, value);
7333 } 7331 }
7334 7332
(...skipping 30 matching lines...) Expand all
7365 cast_value = static_cast<uint32_t>(int_value); 7363 cast_value = static_cast<uint32_t>(int_value);
7366 } else if (value->IsHeapNumber()) { 7364 } else if (value->IsHeapNumber()) {
7367 double double_value = HeapNumber::cast(value)->value(); 7365 double double_value = HeapNumber::cast(value)->value();
7368 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); 7366 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value));
7369 } else { 7367 } else {
7370 // Clamp undefined to zero (default). All other types have been 7368 // Clamp undefined to zero (default). All other types have been
7371 // converted to a number type further up in the call chain. 7369 // converted to a number type further up in the call chain.
7372 ASSERT(value->IsUndefined()); 7370 ASSERT(value->IsUndefined());
7373 } 7371 }
7374 set(index, cast_value); 7372 set(index, cast_value);
7375 } else {
7376 return Top::Throw(*Factory::NewIndexError(index));
7377 } 7373 }
7378 return Heap::NumberFromUint32(cast_value); 7374 return Heap::NumberFromUint32(cast_value);
7379 } 7375 }
7380 7376
7381 7377
7382 Object* ExternalFloatArray::SetValue(uint32_t index, Object* value) { 7378 Object* ExternalFloatArray::SetValue(uint32_t index, Object* value) {
7383 float cast_value = 0; 7379 float cast_value = 0;
7384 if (index < static_cast<uint32_t>(length())) { 7380 if (index < static_cast<uint32_t>(length())) {
7385 if (value->IsSmi()) { 7381 if (value->IsSmi()) {
7386 int int_value = Smi::cast(value)->value(); 7382 int int_value = Smi::cast(value)->value();
7387 cast_value = static_cast<float>(int_value); 7383 cast_value = static_cast<float>(int_value);
7388 } else if (value->IsHeapNumber()) { 7384 } else if (value->IsHeapNumber()) {
7389 double double_value = HeapNumber::cast(value)->value(); 7385 double double_value = HeapNumber::cast(value)->value();
7390 cast_value = static_cast<float>(double_value); 7386 cast_value = static_cast<float>(double_value);
7391 } else { 7387 } else {
7392 // Clamp undefined to zero (default). All other types have been 7388 // Clamp undefined to zero (default). All other types have been
7393 // converted to a number type further up in the call chain. 7389 // converted to a number type further up in the call chain.
7394 ASSERT(value->IsUndefined()); 7390 ASSERT(value->IsUndefined());
7395 } 7391 }
7396 set(index, cast_value); 7392 set(index, cast_value);
7397 } else {
7398 return Top::Throw(*Factory::NewIndexError(index));
7399 } 7393 }
7400 return Heap::AllocateHeapNumber(cast_value); 7394 return Heap::AllocateHeapNumber(cast_value);
7401 } 7395 }
7402 7396
7403 7397
7404 Object* GlobalObject::GetPropertyCell(LookupResult* result) { 7398 Object* GlobalObject::GetPropertyCell(LookupResult* result) {
7405 ASSERT(!HasFastProperties()); 7399 ASSERT(!HasFastProperties());
7406 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry()); 7400 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry());
7407 ASSERT(value->IsJSGlobalPropertyCell()); 7401 ASSERT(value->IsJSGlobalPropertyCell());
7408 return value; 7402 return value;
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
8312 if (break_point_objects()->IsUndefined()) return 0; 8306 if (break_point_objects()->IsUndefined()) return 0;
8313 // Single beak point. 8307 // Single beak point.
8314 if (!break_point_objects()->IsFixedArray()) return 1; 8308 if (!break_point_objects()->IsFixedArray()) return 1;
8315 // Multiple break points. 8309 // Multiple break points.
8316 return FixedArray::cast(break_point_objects())->length(); 8310 return FixedArray::cast(break_point_objects())->length();
8317 } 8311 }
8318 #endif 8312 #endif
8319 8313
8320 8314
8321 } } // namespace v8::internal 8315 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/messages.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698