| Index: test/cctest/test-api.cc
|
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
| index f1cda629356adf9e8836e7ef3450068b1f84e151..2f901e92c91ae77a61d03718ac58833968005754 100644
|
| --- a/test/cctest/test-api.cc
|
| +++ b/test/cctest/test-api.cc
|
| @@ -15614,20 +15614,13 @@ static void CheckElementValue(i::Isolate* isolate,
|
| }
|
|
|
|
|
| -THREADED_TEST(PixelArray) {
|
| +template <class ArrayType, int kElementCount>
|
| +void DoTestUint8ClampedArray(
|
| + i::Handle<ArrayType> pixels, v8::Handle<v8::Object> obj,
|
| + uint8_t* pixel_data) {
|
| LocalContext context;
|
| i::Isolate* isolate = CcTest::i_isolate();
|
| - i::Factory* factory = isolate->factory();
|
| v8::HandleScope scope(context->GetIsolate());
|
| - const int kElementCount = 260;
|
| - uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
|
| - i::Handle<i::ExternalUint8ClampedArray> pixels =
|
| - i::Handle<i::ExternalUint8ClampedArray>::cast(
|
| - factory->NewExternalArray(kElementCount,
|
| - v8::kExternalUint8ClampedArray,
|
| - pixel_data));
|
| - // Force GC to trigger verification.
|
| - CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
| for (int i = 0; i < kElementCount; i++) {
|
| pixels->set(i, i % 256);
|
| }
|
| @@ -15635,14 +15628,12 @@ THREADED_TEST(PixelArray) {
|
| CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
| for (int i = 0; i < kElementCount; i++) {
|
| CHECK_EQ(i % 256, pixels->get_scalar(i));
|
| - CHECK_EQ(i % 256, pixel_data[i]);
|
| + if (pixel_data != NULL) {
|
| + CHECK_EQ(i % 256, pixel_data[i]);
|
| + }
|
| }
|
|
|
| - v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
|
| i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
|
| - // Set the elements to be the pixels.
|
| - // jsobj->set_elements(*pixels);
|
| - obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
|
| CheckElementValue(isolate, 1, jsobj, 1);
|
| obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503));
|
| context->Global()->Set(v8_str("pixels"), obj);
|
| @@ -15651,6 +15642,17 @@ THREADED_TEST(PixelArray) {
|
| result = CompileRun("pixels[1]");
|
| CHECK_EQ(1, result->Int32Value());
|
|
|
| + ArrayType::SetValue(pixels, 0, i::handle(i::Smi::FromInt(256), isolate));
|
| + CHECK_EQ(255, pixels->get_scalar(0));
|
| + ArrayType::SetValue(pixels, 0, i::handle(i::Smi::FromInt(-1), isolate));
|
| + CHECK_EQ(0, pixels->get_scalar(0));
|
| + ArrayType::SetValue(pixels, 0, isolate->factory()->NewNumber(1025.73));
|
| + CHECK_EQ(255, pixels->get_scalar(0));
|
| + ArrayType::SetValue(pixels, 0, isolate->factory()->NewNumber(-1025.73));
|
| + CHECK_EQ(0, pixels->get_scalar(0));
|
| +
|
| + pixels->set(0, 0);
|
| +
|
| result = CompileRun("var sum = 0;"
|
| "for (var i = 0; i < 8; i++) {"
|
| " sum += pixels[i] = pixels[i] = -i;"
|
| @@ -15810,11 +15812,17 @@ THREADED_TEST(PixelArray) {
|
| // Test for index greater than 255. Regression test for:
|
| // http://code.google.com/p/chromium/issues/detail?id=26337.
|
| result = CompileRun("pixels[256] = 255;");
|
| - CHECK_EQ(255, result->Int32Value());
|
| - result = CompileRun("var i = 0;"
|
| - "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
|
| - "i");
|
| - CHECK_EQ(255, result->Int32Value());
|
| + if (pixel_data != NULL) {
|
| + v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
|
| + // Set the elements to be the pixels.
|
| + // jsobj->set_elements(*pixels);
|
| + obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
|
| + CHECK_EQ(255, result->Int32Value());
|
| + result = CompileRun("var i = 0;"
|
| + "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
|
| + "i");
|
| + CHECK_EQ(255, result->Int32Value());
|
| + }
|
|
|
| // Make sure that pixel array ICs recognize when a non-pixel array
|
| // is passed to it.
|
| @@ -15990,11 +15998,55 @@ THREADED_TEST(PixelArray) {
|
| "result = pa_load(pixels);"
|
| "result");
|
| CHECK_EQ(32640, result->Int32Value());
|
| +}
|
| +
|
|
|
| +THREADED_TEST(PixelArray) {
|
| + LocalContext context;
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| + v8::HandleScope scope(context->GetIsolate());
|
| + const int kElementCount = 260;
|
| + uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
|
| + i::Handle<i::ExternalUint8ClampedArray> pixels =
|
| + i::Handle<i::ExternalUint8ClampedArray>::cast(
|
| + factory->NewExternalArray(kElementCount,
|
| + v8::kExternalUint8ClampedArray,
|
| + pixel_data));
|
| + // Force GC to trigger verification.
|
| + CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
| + v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
|
| + obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
|
| + DoTestUint8ClampedArray<i::ExternalUint8ClampedArray, kElementCount>(
|
| + pixels, obj, pixel_data);
|
| free(pixel_data);
|
| }
|
|
|
|
|
| +THREADED_TEST(FixedPixelArray) {
|
| + LocalContext context;
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| + v8::HandleScope scope(context->GetIsolate());
|
| + const int kElementCount = 260;
|
| + i::Handle<i::FixedUint8ClampedArray> pixels =
|
| + i::Handle<i::FixedUint8ClampedArray>::cast(
|
| + factory->NewFixedTypedArray(kElementCount,
|
| + v8::kExternalUint8ClampedArray));
|
| + // Force GC to trigger verification.
|
| + CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
| + v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
|
| + i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
|
| + // Set the elements to be the pixels.
|
| + i::Handle<i::Map> fixed_array_map =
|
| + i::JSObject::GetElementsTransitionMap(jsobj, i::UINT8_CLAMPED_ELEMENTS);
|
| + jsobj->set_map(*fixed_array_map);
|
| + jsobj->set_elements(*pixels);
|
| + DoTestUint8ClampedArray<i::FixedUint8ClampedArray, kElementCount>(
|
| + pixels, obj, NULL);
|
| +}
|
| +
|
| +
|
| THREADED_TEST(PixelArrayInfo) {
|
| LocalContext context;
|
| v8::HandleScope scope(context->GetIsolate());
|
| @@ -16412,6 +16464,7 @@ static void FixedTypedArrayTestHelper(
|
| fixed_array->map()->instance_type());
|
| CHECK_EQ(kElementCount, fixed_array->length());
|
| CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
|
| +
|
| for (int i = 0; i < kElementCount; i++) {
|
| fixed_array->set(i, static_cast<ElementType>(i));
|
| }
|
|
|