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

Side by Side Diff: src/objects.cc

Issue 6551001: Implement pixel array elements access in the presence of an (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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/objects.h ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 6648 matching lines...) Expand 10 before | Expand all | Expand 10 after
6659 static_cast<uint32_t> 6659 static_cast<uint32_t>
6660 (Smi::cast(JSArray::cast(this)->length())->value()) : 6660 (Smi::cast(JSArray::cast(this)->length())->value()) :
6661 static_cast<uint32_t>(FixedArray::cast(elements())->length()); 6661 static_cast<uint32_t>(FixedArray::cast(elements())->length());
6662 if ((index < length) && 6662 if ((index < length) &&
6663 !FixedArray::cast(elements())->get(index)->IsTheHole()) { 6663 !FixedArray::cast(elements())->get(index)->IsTheHole()) {
6664 return true; 6664 return true;
6665 } 6665 }
6666 break; 6666 break;
6667 } 6667 }
6668 case PIXEL_ELEMENTS: { 6668 case PIXEL_ELEMENTS: {
6669 // TODO(iposva): Add testcase.
6670 PixelArray* pixels = PixelArray::cast(elements()); 6669 PixelArray* pixels = PixelArray::cast(elements());
6671 if (index < static_cast<uint32_t>(pixels->length())) { 6670 if (index < static_cast<uint32_t>(pixels->length())) {
6672 return true; 6671 return true;
6673 } 6672 }
6674 break; 6673 break;
6675 } 6674 }
6676 case EXTERNAL_BYTE_ELEMENTS: 6675 case EXTERNAL_BYTE_ELEMENTS:
6677 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: 6676 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
6678 case EXTERNAL_SHORT_ELEMENTS: 6677 case EXTERNAL_SHORT_ELEMENTS:
6679 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: 6678 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
6680 case EXTERNAL_INT_ELEMENTS: 6679 case EXTERNAL_INT_ELEMENTS:
6681 case EXTERNAL_UNSIGNED_INT_ELEMENTS: 6680 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
6682 case EXTERNAL_FLOAT_ELEMENTS: { 6681 case EXTERNAL_FLOAT_ELEMENTS: {
6683 // TODO(kbr): Add testcase.
6684 ExternalArray* array = ExternalArray::cast(elements()); 6682 ExternalArray* array = ExternalArray::cast(elements());
6685 if (index < static_cast<uint32_t>(array->length())) { 6683 if (index < static_cast<uint32_t>(array->length())) {
6686 return true; 6684 return true;
6687 } 6685 }
6688 break; 6686 break;
6689 } 6687 }
6690 case DICTIONARY_ELEMENTS: { 6688 case DICTIONARY_ELEMENTS: {
6691 if (element_dictionary()->FindEntry(index) 6689 if (element_dictionary()->FindEntry(index)
6692 != NumberDictionary::kNotFound) { 6690 != NumberDictionary::kNotFound) {
6693 return true; 6691 return true;
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
7264 // JSArray::length cannot change. 7262 // JSArray::length cannot change.
7265 switch (GetElementsKind()) { 7263 switch (GetElementsKind()) {
7266 case FAST_ELEMENTS: { 7264 case FAST_ELEMENTS: {
7267 FixedArray* elms = FixedArray::cast(elements()); 7265 FixedArray* elms = FixedArray::cast(elements());
7268 if (index < static_cast<uint32_t>(elms->length())) { 7266 if (index < static_cast<uint32_t>(elms->length())) {
7269 Object* value = elms->get(index); 7267 Object* value = elms->get(index);
7270 if (!value->IsTheHole()) return value; 7268 if (!value->IsTheHole()) return value;
7271 } 7269 }
7272 break; 7270 break;
7273 } 7271 }
7274 case PIXEL_ELEMENTS: { 7272 case PIXEL_ELEMENTS:
7275 // TODO(iposva): Add testcase and implement.
7276 UNIMPLEMENTED();
7277 break;
7278 }
7279 case EXTERNAL_BYTE_ELEMENTS: 7273 case EXTERNAL_BYTE_ELEMENTS:
7280 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: 7274 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
7281 case EXTERNAL_SHORT_ELEMENTS: 7275 case EXTERNAL_SHORT_ELEMENTS:
7282 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: 7276 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
7283 case EXTERNAL_INT_ELEMENTS: 7277 case EXTERNAL_INT_ELEMENTS:
7284 case EXTERNAL_UNSIGNED_INT_ELEMENTS: 7278 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
7285 case EXTERNAL_FLOAT_ELEMENTS: { 7279 case EXTERNAL_FLOAT_ELEMENTS: {
7286 // TODO(kbr): Add testcase and implement. 7280 MaybeObject* value = GetExternalElement(index);
7287 UNIMPLEMENTED(); 7281 if (!value->ToObjectUnchecked()->IsUndefined()) return value;
7288 break; 7282 break;
7289 } 7283 }
7290 case DICTIONARY_ELEMENTS: { 7284 case DICTIONARY_ELEMENTS: {
7291 NumberDictionary* dictionary = element_dictionary(); 7285 NumberDictionary* dictionary = element_dictionary();
7292 int entry = dictionary->FindEntry(index); 7286 int entry = dictionary->FindEntry(index);
7293 if (entry != NumberDictionary::kNotFound) { 7287 if (entry != NumberDictionary::kNotFound) {
7294 Object* element = dictionary->ValueAt(entry); 7288 Object* element = dictionary->ValueAt(entry);
7295 PropertyDetails details = dictionary->DetailsAt(entry); 7289 PropertyDetails details = dictionary->DetailsAt(entry);
7296 if (details.type() == CALLBACKS) { 7290 if (details.type() == CALLBACKS) {
7297 return GetElementWithCallback(receiver, 7291 return GetElementWithCallback(receiver,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
7365 // JSArray::length cannot change. 7359 // JSArray::length cannot change.
7366 switch (GetElementsKind()) { 7360 switch (GetElementsKind()) {
7367 case FAST_ELEMENTS: { 7361 case FAST_ELEMENTS: {
7368 FixedArray* elms = FixedArray::cast(elements()); 7362 FixedArray* elms = FixedArray::cast(elements());
7369 if (index < static_cast<uint32_t>(elms->length())) { 7363 if (index < static_cast<uint32_t>(elms->length())) {
7370 Object* value = elms->get(index); 7364 Object* value = elms->get(index);
7371 if (!value->IsTheHole()) return value; 7365 if (!value->IsTheHole()) return value;
7372 } 7366 }
7373 break; 7367 break;
7374 } 7368 }
7369 case PIXEL_ELEMENTS:
7370 case EXTERNAL_BYTE_ELEMENTS:
7371 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
7372 case EXTERNAL_SHORT_ELEMENTS:
7373 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
7374 case EXTERNAL_INT_ELEMENTS:
7375 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
7376 case EXTERNAL_FLOAT_ELEMENTS: {
7377 MaybeObject* value = GetExternalElement(index);
7378 if (!value->ToObjectUnchecked()->IsUndefined()) return value;
7379 break;
7380 }
7381 case DICTIONARY_ELEMENTS: {
7382 NumberDictionary* dictionary = element_dictionary();
7383 int entry = dictionary->FindEntry(index);
7384 if (entry != NumberDictionary::kNotFound) {
7385 Object* element = dictionary->ValueAt(entry);
7386 PropertyDetails details = dictionary->DetailsAt(entry);
7387 if (details.type() == CALLBACKS) {
7388 return GetElementWithCallback(receiver,
7389 element,
7390 index,
7391 this);
7392 }
7393 return element;
7394 }
7395 break;
7396 }
7397 }
7398
7399 Object* pt = GetPrototype();
7400 if (pt == Heap::null_value()) return Heap::undefined_value();
7401 return pt->GetElementWithReceiver(receiver, index);
7402 }
7403
7404
7405 MaybeObject* JSObject::GetExternalElement(uint32_t index) {
7406 // Get element works for both JSObject and JSArray since
7407 // JSArray::length cannot change.
7408 switch (GetElementsKind()) {
7375 case PIXEL_ELEMENTS: { 7409 case PIXEL_ELEMENTS: {
7376 PixelArray* pixels = PixelArray::cast(elements()); 7410 PixelArray* pixels = PixelArray::cast(elements());
7377 if (index < static_cast<uint32_t>(pixels->length())) { 7411 if (index < static_cast<uint32_t>(pixels->length())) {
7378 uint8_t value = pixels->get(index); 7412 uint8_t value = pixels->get(index);
7379 return Smi::FromInt(value); 7413 return Smi::FromInt(value);
7380 } 7414 }
7381 break; 7415 break;
7382 } 7416 }
7383 case EXTERNAL_BYTE_ELEMENTS: { 7417 case EXTERNAL_BYTE_ELEMENTS: {
7384 ExternalByteArray* array = ExternalByteArray::cast(elements()); 7418 ExternalByteArray* array = ExternalByteArray::cast(elements());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7432 break; 7466 break;
7433 } 7467 }
7434 case EXTERNAL_FLOAT_ELEMENTS: { 7468 case EXTERNAL_FLOAT_ELEMENTS: {
7435 ExternalFloatArray* array = ExternalFloatArray::cast(elements()); 7469 ExternalFloatArray* array = ExternalFloatArray::cast(elements());
7436 if (index < static_cast<uint32_t>(array->length())) { 7470 if (index < static_cast<uint32_t>(array->length())) {
7437 float value = array->get(index); 7471 float value = array->get(index);
7438 return Heap::AllocateHeapNumber(value); 7472 return Heap::AllocateHeapNumber(value);
7439 } 7473 }
7440 break; 7474 break;
7441 } 7475 }
7442 case DICTIONARY_ELEMENTS: { 7476 case FAST_ELEMENTS:
7443 NumberDictionary* dictionary = element_dictionary(); 7477 case DICTIONARY_ELEMENTS:
7444 int entry = dictionary->FindEntry(index); 7478 UNREACHABLE();
7445 if (entry != NumberDictionary::kNotFound) {
7446 Object* element = dictionary->ValueAt(entry);
7447 PropertyDetails details = dictionary->DetailsAt(entry);
7448 if (details.type() == CALLBACKS) {
7449 return GetElementWithCallback(receiver,
7450 element,
7451 index,
7452 this);
7453 }
7454 return element;
7455 }
7456 break; 7479 break;
7457 }
7458 } 7480 }
7459 7481 return Heap::undefined_value();
7460 Object* pt = GetPrototype();
7461 if (pt == Heap::null_value()) return Heap::undefined_value();
7462 return pt->GetElementWithReceiver(receiver, index);
7463 } 7482 }
7464 7483
7465 7484
7466 bool JSObject::HasDenseElements() { 7485 bool JSObject::HasDenseElements() {
7467 int capacity = 0; 7486 int capacity = 0;
7468 int number_of_elements = 0; 7487 int number_of_elements = 0;
7469 7488
7470 switch (GetElementsKind()) { 7489 switch (GetElementsKind()) {
7471 case FAST_ELEMENTS: { 7490 case FAST_ELEMENTS: {
7472 FixedArray* elms = FixedArray::cast(elements()); 7491 FixedArray* elms = FixedArray::cast(elements());
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after
9991 if (break_point_objects()->IsUndefined()) return 0; 10010 if (break_point_objects()->IsUndefined()) return 0;
9992 // Single beak point. 10011 // Single beak point.
9993 if (!break_point_objects()->IsFixedArray()) return 1; 10012 if (!break_point_objects()->IsFixedArray()) return 1;
9994 // Multiple break points. 10013 // Multiple break points.
9995 return FixedArray::cast(break_point_objects())->length(); 10014 return FixedArray::cast(break_point_objects())->length();
9996 } 10015 }
9997 #endif 10016 #endif
9998 10017
9999 10018
10000 } } // namespace v8::internal 10019 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698