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

Side by Side Diff: test/cctest/test-api.cc

Issue 212663005: Fix FixedUint8ClampedArray::SetValue. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 15596 matching lines...) Expand 10 before | Expand all | Expand 10 after
15607 15607
15608 static void CheckElementValue(i::Isolate* isolate, 15608 static void CheckElementValue(i::Isolate* isolate,
15609 int expected, 15609 int expected,
15610 i::Handle<i::Object> obj, 15610 i::Handle<i::Object> obj,
15611 int offset) { 15611 int offset) {
15612 i::Object* element = *i::Object::GetElement(isolate, obj, offset); 15612 i::Object* element = *i::Object::GetElement(isolate, obj, offset);
15613 CHECK_EQ(expected, i::Smi::cast(element)->value()); 15613 CHECK_EQ(expected, i::Smi::cast(element)->value());
15614 } 15614 }
15615 15615
15616 15616
15617 THREADED_TEST(PixelArray) { 15617 template <class ArrayType, int kElementCount>
15618 void DoTestUint8ClampedArray(
15619 i::Handle<ArrayType> pixels, v8::Handle<v8::Object> obj,
15620 uint8_t* pixel_data) {
15618 LocalContext context; 15621 LocalContext context;
15619 i::Isolate* isolate = CcTest::i_isolate(); 15622 i::Isolate* isolate = CcTest::i_isolate();
15620 i::Factory* factory = isolate->factory();
15621 v8::HandleScope scope(context->GetIsolate()); 15623 v8::HandleScope scope(context->GetIsolate());
15622 const int kElementCount = 260;
15623 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
15624 i::Handle<i::ExternalUint8ClampedArray> pixels =
15625 i::Handle<i::ExternalUint8ClampedArray>::cast(
15626 factory->NewExternalArray(kElementCount,
15627 v8::kExternalUint8ClampedArray,
15628 pixel_data));
15629 // Force GC to trigger verification.
15630 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15631 for (int i = 0; i < kElementCount; i++) { 15624 for (int i = 0; i < kElementCount; i++) {
15632 pixels->set(i, i % 256); 15625 pixels->set(i, i % 256);
15633 } 15626 }
15634 // Force GC to trigger verification. 15627 // Force GC to trigger verification.
15635 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 15628 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
15636 for (int i = 0; i < kElementCount; i++) { 15629 for (int i = 0; i < kElementCount; i++) {
15637 CHECK_EQ(i % 256, pixels->get_scalar(i)); 15630 CHECK_EQ(i % 256, pixels->get_scalar(i));
15638 CHECK_EQ(i % 256, pixel_data[i]); 15631 if (pixel_data != NULL) {
15632 CHECK_EQ(i % 256, pixel_data[i]);
15633 }
15639 } 15634 }
15640 15635
15641 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
15642 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 15636 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
15643 // Set the elements to be the pixels.
15644 // jsobj->set_elements(*pixels);
15645 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
15646 CheckElementValue(isolate, 1, jsobj, 1); 15637 CheckElementValue(isolate, 1, jsobj, 1);
15647 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503)); 15638 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503));
15648 context->Global()->Set(v8_str("pixels"), obj); 15639 context->Global()->Set(v8_str("pixels"), obj);
15649 v8::Handle<v8::Value> result = CompileRun("pixels.field"); 15640 v8::Handle<v8::Value> result = CompileRun("pixels.field");
15650 CHECK_EQ(1503, result->Int32Value()); 15641 CHECK_EQ(1503, result->Int32Value());
15651 result = CompileRun("pixels[1]"); 15642 result = CompileRun("pixels[1]");
15652 CHECK_EQ(1, result->Int32Value()); 15643 CHECK_EQ(1, result->Int32Value());
15653 15644
15645 ArrayType::SetValue(pixels, 0, i::handle(i::Smi::FromInt(256), isolate));
15646 CHECK_EQ(255, pixels->get_scalar(0));
15647 ArrayType::SetValue(pixels, 0, i::handle(i::Smi::FromInt(-1), isolate));
15648 CHECK_EQ(0, pixels->get_scalar(0));
15649 ArrayType::SetValue(pixels, 0, isolate->factory()->NewNumber(1025.73));
15650 CHECK_EQ(255, pixels->get_scalar(0));
15651 ArrayType::SetValue(pixels, 0, isolate->factory()->NewNumber(-1025.73));
15652 CHECK_EQ(0, pixels->get_scalar(0));
15653
15654 pixels->set(0, 0);
15655
15654 result = CompileRun("var sum = 0;" 15656 result = CompileRun("var sum = 0;"
15655 "for (var i = 0; i < 8; i++) {" 15657 "for (var i = 0; i < 8; i++) {"
15656 " sum += pixels[i] = pixels[i] = -i;" 15658 " sum += pixels[i] = pixels[i] = -i;"
15657 "}" 15659 "}"
15658 "sum;"); 15660 "sum;");
15659 CHECK_EQ(-28, result->Int32Value()); 15661 CHECK_EQ(-28, result->Int32Value());
15660 15662
15661 result = CompileRun("var sum = 0;" 15663 result = CompileRun("var sum = 0;"
15662 "for (var i = 0; i < 8; i++) {" 15664 "for (var i = 0; i < 8; i++) {"
15663 " sum += pixels[i] = pixels[i] = 0;" 15665 " sum += pixels[i] = pixels[i] = 0;"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
15803 "js_array.concat(pixels);"); 15805 "js_array.concat(pixels);");
15804 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); 15806 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
15805 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); 15807 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value());
15806 15808
15807 result = CompileRun("pixels[1] = 23;"); 15809 result = CompileRun("pixels[1] = 23;");
15808 CHECK_EQ(23, result->Int32Value()); 15810 CHECK_EQ(23, result->Int32Value());
15809 15811
15810 // Test for index greater than 255. Regression test for: 15812 // Test for index greater than 255. Regression test for:
15811 // http://code.google.com/p/chromium/issues/detail?id=26337. 15813 // http://code.google.com/p/chromium/issues/detail?id=26337.
15812 result = CompileRun("pixels[256] = 255;"); 15814 result = CompileRun("pixels[256] = 255;");
15813 CHECK_EQ(255, result->Int32Value()); 15815 if (pixel_data != NULL) {
15814 result = CompileRun("var i = 0;" 15816 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
15815 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" 15817 // Set the elements to be the pixels.
15816 "i"); 15818 // jsobj->set_elements(*pixels);
15817 CHECK_EQ(255, result->Int32Value()); 15819 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
15820 CHECK_EQ(255, result->Int32Value());
15821 result = CompileRun("var i = 0;"
15822 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
15823 "i");
15824 CHECK_EQ(255, result->Int32Value());
15825 }
15818 15826
15819 // Make sure that pixel array ICs recognize when a non-pixel array 15827 // Make sure that pixel array ICs recognize when a non-pixel array
15820 // is passed to it. 15828 // is passed to it.
15821 result = CompileRun("function pa_load(p) {" 15829 result = CompileRun("function pa_load(p) {"
15822 " var sum = 0;" 15830 " var sum = 0;"
15823 " for (var j = 0; j < 256; j++) { sum += p[j]; }" 15831 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
15824 " return sum;" 15832 " return sum;"
15825 "}" 15833 "}"
15826 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" 15834 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15827 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" 15835 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
15983 " sum += p[i];" 15991 " sum += p[i];"
15984 " }" 15992 " }"
15985 " return sum; " 15993 " return sum; "
15986 "}" 15994 "}"
15987 "for (var i = 0; i < 5000; ++i) {" 15995 "for (var i = 0; i < 5000; ++i) {"
15988 " pa_init(pixels);" 15996 " pa_init(pixels);"
15989 "}" 15997 "}"
15990 "result = pa_load(pixels);" 15998 "result = pa_load(pixels);"
15991 "result"); 15999 "result");
15992 CHECK_EQ(32640, result->Int32Value()); 16000 CHECK_EQ(32640, result->Int32Value());
16001 }
15993 16002
16003
16004 THREADED_TEST(PixelArray) {
16005 LocalContext context;
16006 i::Isolate* isolate = CcTest::i_isolate();
16007 i::Factory* factory = isolate->factory();
16008 v8::HandleScope scope(context->GetIsolate());
16009 const int kElementCount = 260;
16010 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
16011 i::Handle<i::ExternalUint8ClampedArray> pixels =
16012 i::Handle<i::ExternalUint8ClampedArray>::cast(
16013 factory->NewExternalArray(kElementCount,
16014 v8::kExternalUint8ClampedArray,
16015 pixel_data));
16016 // Force GC to trigger verification.
16017 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16018 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
16019 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
16020 DoTestUint8ClampedArray<i::ExternalUint8ClampedArray, kElementCount>(
16021 pixels, obj, pixel_data);
15994 free(pixel_data); 16022 free(pixel_data);
15995 } 16023 }
15996 16024
15997 16025
16026 THREADED_TEST(FixedPixelArray) {
16027 LocalContext context;
16028 i::Isolate* isolate = CcTest::i_isolate();
16029 i::Factory* factory = isolate->factory();
16030 v8::HandleScope scope(context->GetIsolate());
16031 const int kElementCount = 260;
16032 i::Handle<i::FixedUint8ClampedArray> pixels =
16033 i::Handle<i::FixedUint8ClampedArray>::cast(
16034 factory->NewFixedTypedArray(kElementCount,
16035 v8::kExternalUint8ClampedArray));
16036 // Force GC to trigger verification.
16037 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16038 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
16039 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
16040 // Set the elements to be the pixels.
16041 i::Handle<i::Map> fixed_array_map =
16042 i::JSObject::GetElementsTransitionMap(jsobj, i::UINT8_CLAMPED_ELEMENTS);
16043 jsobj->set_map(*fixed_array_map);
16044 jsobj->set_elements(*pixels);
16045 DoTestUint8ClampedArray<i::FixedUint8ClampedArray, kElementCount>(
16046 pixels, obj, NULL);
16047 }
16048
16049
15998 THREADED_TEST(PixelArrayInfo) { 16050 THREADED_TEST(PixelArrayInfo) {
15999 LocalContext context; 16051 LocalContext context;
16000 v8::HandleScope scope(context->GetIsolate()); 16052 v8::HandleScope scope(context->GetIsolate());
16001 for (int size = 0; size < 100; size += 10) { 16053 for (int size = 0; size < 100; size += 10) {
16002 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 16054 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
16003 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate()); 16055 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
16004 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 16056 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
16005 CHECK(obj->HasIndexedPropertiesInPixelData()); 16057 CHECK(obj->HasIndexedPropertiesInPixelData());
16006 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 16058 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
16007 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 16059 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
16405 i::Factory* factory = isolate->factory(); 16457 i::Factory* factory = isolate->factory();
16406 v8::HandleScope scope(context->GetIsolate()); 16458 v8::HandleScope scope(context->GetIsolate());
16407 const int kElementCount = 260; 16459 const int kElementCount = 260;
16408 i::Handle<FixedTypedArrayClass> fixed_array = 16460 i::Handle<FixedTypedArrayClass> fixed_array =
16409 i::Handle<FixedTypedArrayClass>::cast( 16461 i::Handle<FixedTypedArrayClass>::cast(
16410 factory->NewFixedTypedArray(kElementCount, array_type)); 16462 factory->NewFixedTypedArray(kElementCount, array_type));
16411 CHECK_EQ(FixedTypedArrayClass::kInstanceType, 16463 CHECK_EQ(FixedTypedArrayClass::kInstanceType,
16412 fixed_array->map()->instance_type()); 16464 fixed_array->map()->instance_type());
16413 CHECK_EQ(kElementCount, fixed_array->length()); 16465 CHECK_EQ(kElementCount, fixed_array->length());
16414 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 16466 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16467
16415 for (int i = 0; i < kElementCount; i++) { 16468 for (int i = 0; i < kElementCount; i++) {
16416 fixed_array->set(i, static_cast<ElementType>(i)); 16469 fixed_array->set(i, static_cast<ElementType>(i));
16417 } 16470 }
16418 // Force GC to trigger verification. 16471 // Force GC to trigger verification.
16419 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 16472 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
16420 for (int i = 0; i < kElementCount; i++) { 16473 for (int i = 0; i < kElementCount; i++) {
16421 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), 16474 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)),
16422 static_cast<int64_t>(fixed_array->get_scalar(i))); 16475 static_cast<int64_t>(fixed_array->get_scalar(i)));
16423 } 16476 }
16424 v8::Handle<v8::Object> obj = v8::Object::New(CcTest::isolate()); 16477 v8::Handle<v8::Object> obj = v8::Object::New(CcTest::isolate());
(...skipping 5933 matching lines...) Expand 10 before | Expand all | Expand 10 after
22358 "f.call(friend);"); 22411 "f.call(friend);");
22359 CHECK_EQ(2, named_access_count); 22412 CHECK_EQ(2, named_access_count);
22360 22413
22361 // Test access using Object.setPrototypeOf reflective method. 22414 // Test access using Object.setPrototypeOf reflective method.
22362 named_access_count = 0; 22415 named_access_count = 0;
22363 CompileRun("Object.setPrototypeOf(friend, {});"); 22416 CompileRun("Object.setPrototypeOf(friend, {});");
22364 CHECK_EQ(1, named_access_count); 22417 CHECK_EQ(1, named_access_count);
22365 CompileRun("Object.getPrototypeOf(friend);"); 22418 CompileRun("Object.getPrototypeOf(friend);");
22366 CHECK_EQ(2, named_access_count); 22419 CHECK_EQ(2, named_access_count);
22367 } 22420 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698