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

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

Issue 6546036: Combine typed and pixel arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: final version Created 9 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/x64/stub-cache-x64.cc ('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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-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 10531 matching lines...) Expand 10 before | Expand all | Expand 10 after
10542 context->DetachGlobal(); 10542 context->DetachGlobal();
10543 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 10543 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
10544 } 10544 }
10545 10545
10546 10546
10547 THREADED_TEST(PixelArray) { 10547 THREADED_TEST(PixelArray) {
10548 v8::HandleScope scope; 10548 v8::HandleScope scope;
10549 LocalContext context; 10549 LocalContext context;
10550 const int kElementCount = 260; 10550 const int kElementCount = 260;
10551 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 10551 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10552 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, 10552 i::Handle<i::ExternalPixelArray> pixels =
10553 pixel_data); 10553 i::Handle<i::ExternalPixelArray>::cast(
10554 i::Factory::NewExternalArray(kElementCount,
10555 v8::kExternalPixelArray,
10556 pixel_data));
10554 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. 10557 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification.
10555 for (int i = 0; i < kElementCount; i++) { 10558 for (int i = 0; i < kElementCount; i++) {
10556 pixels->set(i, i % 256); 10559 pixels->set(i, i % 256);
10557 } 10560 }
10558 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. 10561 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification.
10559 for (int i = 0; i < kElementCount; i++) { 10562 for (int i = 0; i < kElementCount; i++) {
10560 CHECK_EQ(i % 256, pixels->get(i)); 10563 CHECK_EQ(i % 256, pixels->get(i));
10561 CHECK_EQ(i % 256, pixel_data[i]); 10564 CHECK_EQ(i % 256, pixel_data[i]);
10562 } 10565 }
10563 10566
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
10883 10886
10884 // Make sure that pixel array loads are optimized by crankshaft. 10887 // Make sure that pixel array loads are optimized by crankshaft.
10885 result = CompileRun("function pa_load(p) {" 10888 result = CompileRun("function pa_load(p) {"
10886 " var sum = 0;" 10889 " var sum = 0;"
10887 " for (var i=0; i<256; ++i) {" 10890 " for (var i=0; i<256; ++i) {"
10888 " sum += p[i];" 10891 " sum += p[i];"
10889 " }" 10892 " }"
10890 " return sum; " 10893 " return sum; "
10891 "}" 10894 "}"
10892 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" 10895 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10893 "for (var i = 0; i < 10000; ++i) {" 10896 "for (var i = 0; i < 5000; ++i) {"
10894 " result = pa_load(pixels);" 10897 " result = pa_load(pixels);"
10895 "}" 10898 "}"
10896 "result"); 10899 "result");
10897 CHECK_EQ(32640, result->Int32Value()); 10900 CHECK_EQ(32640, result->Int32Value());
10898 10901
10899 // Make sure that pixel array stores are optimized by crankshaft. 10902 // Make sure that pixel array stores are optimized by crankshaft.
10900 result = CompileRun("function pa_init(p) {" 10903 result = CompileRun("function pa_init(p) {"
10901 "for (var i = 0; i < 256; ++i) { p[i] = i; }" 10904 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
10902 "}" 10905 "}"
10903 "function pa_load(p) {" 10906 "function pa_load(p) {"
10904 " var sum = 0;" 10907 " var sum = 0;"
10905 " for (var i=0; i<256; ++i) {" 10908 " for (var i=0; i<256; ++i) {"
10906 " sum += p[i];" 10909 " sum += p[i];"
10907 " }" 10910 " }"
10908 " return sum; " 10911 " return sum; "
10909 "}" 10912 "}"
10910 "for (var i = 0; i < 100000; ++i) {" 10913 "for (var i = 0; i < 5000; ++i) {"
10911 " pa_init(pixels);" 10914 " pa_init(pixels);"
10912 "}" 10915 "}"
10913 "result = pa_load(pixels);" 10916 "result = pa_load(pixels);"
10914 "result"); 10917 "result");
10915 CHECK_EQ(32640, result->Int32Value()); 10918 CHECK_EQ(32640, result->Int32Value());
10916 10919
10917 free(pixel_data); 10920 free(pixel_data);
10918 } 10921 }
10919 10922
10920 10923
(...skipping 27 matching lines...) Expand all
10948 ApiTestFuzzer::Fuzz(); 10951 ApiTestFuzzer::Fuzz();
10949 return v8::Handle<Value>(); 10952 return v8::Handle<Value>();
10950 } 10953 }
10951 10954
10952 10955
10953 THREADED_TEST(PixelArrayWithInterceptor) { 10956 THREADED_TEST(PixelArrayWithInterceptor) {
10954 v8::HandleScope scope; 10957 v8::HandleScope scope;
10955 LocalContext context; 10958 LocalContext context;
10956 const int kElementCount = 260; 10959 const int kElementCount = 260;
10957 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 10960 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10958 i::Handle<i::PixelArray> pixels = 10961 i::Handle<i::ExternalPixelArray> pixels =
10959 i::Factory::NewPixelArray(kElementCount, pixel_data); 10962 i::Handle<i::ExternalPixelArray>::cast(
10963 i::Factory::NewExternalArray(kElementCount,
10964 v8::kExternalPixelArray,
10965 pixel_data));
10960 for (int i = 0; i < kElementCount; i++) { 10966 for (int i = 0; i < kElementCount; i++) {
10961 pixels->set(i, i % 256); 10967 pixels->set(i, i % 256);
10962 } 10968 }
10963 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 10969 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
10964 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, 10970 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter,
10965 NotHandledIndexedPropertySetter); 10971 NotHandledIndexedPropertySetter);
10966 v8::Handle<v8::Object> obj = templ->NewInstance(); 10972 v8::Handle<v8::Object> obj = templ->NewInstance();
10967 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); 10973 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
10968 context->Global()->Set(v8_str("pixels"), obj); 10974 context->Global()->Set(v8_str("pixels"), obj);
10969 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); 10975 v8::Handle<v8::Value> result = CompileRun("pixels[1]");
10970 CHECK_EQ(1, result->Int32Value()); 10976 CHECK_EQ(1, result->Int32Value());
10971 result = CompileRun("var sum = 0;" 10977 result = CompileRun("var sum = 0;"
10972 "for (var i = 0; i < 8; i++) {" 10978 "for (var i = 0; i < 8; i++) {"
10973 " sum += pixels[i] = pixels[i] = -i;" 10979 " sum += pixels[i] = pixels[i] = -i;"
10974 "}" 10980 "}"
10975 "sum;"); 10981 "sum;");
10976 CHECK_EQ(-28, result->Int32Value()); 10982 CHECK_EQ(-28, result->Int32Value());
10977 result = CompileRun("pixels.hasOwnProperty('1')"); 10983 result = CompileRun("pixels.hasOwnProperty('1')");
10978 CHECK(result->BooleanValue()); 10984 CHECK(result->BooleanValue());
10979 free(pixel_data); 10985 free(pixel_data);
10980 } 10986 }
10981 10987
10982 10988
10983 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { 10989 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
10984 switch (array_type) { 10990 switch (array_type) {
10985 case v8::kExternalByteArray: 10991 case v8::kExternalByteArray:
10986 case v8::kExternalUnsignedByteArray: 10992 case v8::kExternalUnsignedByteArray:
10993 case v8::kExternalPixelArray:
10987 return 1; 10994 return 1;
10988 break; 10995 break;
10989 case v8::kExternalShortArray: 10996 case v8::kExternalShortArray:
10990 case v8::kExternalUnsignedShortArray: 10997 case v8::kExternalUnsignedShortArray:
10991 return 2; 10998 return 2;
10992 break; 10999 break;
10993 case v8::kExternalIntArray: 11000 case v8::kExternalIntArray:
10994 case v8::kExternalUnsignedIntArray: 11001 case v8::kExternalUnsignedIntArray:
10995 case v8::kExternalFloatArray: 11002 case v8::kExternalFloatArray:
10996 return 4; 11003 return 4;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
11198 CHECK_EQ(0, 11205 CHECK_EQ(0,
11199 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11206 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11200 11207
11201 result = CompileRun("for (var i = 0; i < 8; i++) {" 11208 result = CompileRun("for (var i = 0; i < 8; i++) {"
11202 " ext_array[i] = 5;" 11209 " ext_array[i] = 5;"
11203 "}" 11210 "}"
11204 "for (var i = 0; i < 8; i++) {" 11211 "for (var i = 0; i < 8; i++) {"
11205 " ext_array[i] = Infinity;" 11212 " ext_array[i] = Infinity;"
11206 "}" 11213 "}"
11207 "ext_array[5];"); 11214 "ext_array[5];");
11208 CHECK_EQ(0, result->Int32Value()); 11215 int expected_value =
11209 CHECK_EQ(0, 11216 (array_type == v8::kExternalPixelArray) ? 255 : 0;
11217 CHECK_EQ(expected_value, result->Int32Value());
11218 CHECK_EQ(expected_value,
11210 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11219 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11211 11220
11212 result = CompileRun("for (var i = 0; i < 8; i++) {" 11221 result = CompileRun("for (var i = 0; i < 8; i++) {"
11213 " ext_array[i] = 5;" 11222 " ext_array[i] = 5;"
11214 "}" 11223 "}"
11215 "for (var i = 0; i < 8; i++) {" 11224 "for (var i = 0; i < 8; i++) {"
11216 " ext_array[i] = -Infinity;" 11225 " ext_array[i] = -Infinity;"
11217 "}" 11226 "}"
11218 "ext_array[5];"); 11227 "ext_array[5];");
11219 CHECK_EQ(0, result->Int32Value()); 11228 CHECK_EQ(0, result->Int32Value());
11220 CHECK_EQ(0, 11229 CHECK_EQ(0,
11221 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11230 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11222 11231
11223 // Check truncation behavior of integral arrays. 11232 // Check truncation behavior of integral arrays.
11224 const char* unsigned_data = 11233 const char* unsigned_data =
11225 "var source_data = [0.6, 10.6];" 11234 "var source_data = [0.6, 10.6];"
11226 "var expected_results = [0, 10];"; 11235 "var expected_results = [0, 10];";
11227 const char* signed_data = 11236 const char* signed_data =
11228 "var source_data = [0.6, 10.6, -0.6, -10.6];" 11237 "var source_data = [0.6, 10.6, -0.6, -10.6];"
11229 "var expected_results = [0, 10, 0, -10];"; 11238 "var expected_results = [0, 10, 0, -10];";
11239 const char* pixel_data =
11240 "var source_data = [0.6, 10.6];"
11241 "var expected_results = [1, 11];";
11230 bool is_unsigned = 11242 bool is_unsigned =
11231 (array_type == v8::kExternalUnsignedByteArray || 11243 (array_type == v8::kExternalUnsignedByteArray ||
11232 array_type == v8::kExternalUnsignedShortArray || 11244 array_type == v8::kExternalUnsignedShortArray ||
11233 array_type == v8::kExternalUnsignedIntArray); 11245 array_type == v8::kExternalUnsignedIntArray);
11246 bool is_pixel_data = array_type == v8::kExternalPixelArray;
11234 11247
11235 i::OS::SNPrintF(test_buf, 11248 i::OS::SNPrintF(test_buf,
11236 "%s" 11249 "%s"
11237 "var all_passed = true;" 11250 "var all_passed = true;"
11238 "for (var i = 0; i < source_data.length; i++) {" 11251 "for (var i = 0; i < source_data.length; i++) {"
11239 " for (var j = 0; j < 8; j++) {" 11252 " for (var j = 0; j < 8; j++) {"
11240 " ext_array[j] = source_data[i];" 11253 " ext_array[j] = source_data[i];"
11241 " }" 11254 " }"
11242 " all_passed = all_passed &&" 11255 " all_passed = all_passed &&"
11243 " (ext_array[5] == expected_results[i]);" 11256 " (ext_array[5] == expected_results[i]);"
11244 "}" 11257 "}"
11245 "all_passed;", 11258 "all_passed;",
11246 (is_unsigned ? unsigned_data : signed_data)); 11259 (is_unsigned ?
11260 unsigned_data :
11261 (is_pixel_data ? pixel_data : signed_data)));
11247 result = CompileRun(test_buf.start()); 11262 result = CompileRun(test_buf.start());
11248 CHECK_EQ(true, result->BooleanValue()); 11263 CHECK_EQ(true, result->BooleanValue());
11249 } 11264 }
11250 11265
11251 result = CompileRun("ext_array[3] = 33;" 11266 result = CompileRun("ext_array[3] = 33;"
11252 "delete ext_array[3];" 11267 "delete ext_array[3];"
11253 "ext_array[3];"); 11268 "ext_array[3];");
11254 CHECK_EQ(33, result->Int32Value()); 11269 CHECK_EQ(33, result->Int32Value());
11255 11270
11256 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" 11271 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
11367 11382
11368 11383
11369 THREADED_TEST(ExternalUnsignedByteArray) { 11384 THREADED_TEST(ExternalUnsignedByteArray) {
11370 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>( 11385 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>(
11371 v8::kExternalUnsignedByteArray, 11386 v8::kExternalUnsignedByteArray,
11372 0, 11387 0,
11373 255); 11388 255);
11374 } 11389 }
11375 11390
11376 11391
11392 THREADED_TEST(ExternalPixelArray) {
11393 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
11394 v8::kExternalPixelArray,
11395 0,
11396 255);
11397 }
11398
11399
11377 THREADED_TEST(ExternalShortArray) { 11400 THREADED_TEST(ExternalShortArray) {
11378 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>( 11401 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
11379 v8::kExternalShortArray, 11402 v8::kExternalShortArray,
11380 -32768, 11403 -32768,
11381 32767); 11404 32767);
11382 } 11405 }
11383 11406
11384 11407
11385 THREADED_TEST(ExternalUnsignedShortArray) { 11408 THREADED_TEST(ExternalUnsignedShortArray) {
11386 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>( 11409 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
11444 11467
11445 11468
11446 THREADED_TEST(ExternalArrayInfo) { 11469 THREADED_TEST(ExternalArrayInfo) {
11447 ExternalArrayInfoTestHelper(v8::kExternalByteArray); 11470 ExternalArrayInfoTestHelper(v8::kExternalByteArray);
11448 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); 11471 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
11449 ExternalArrayInfoTestHelper(v8::kExternalShortArray); 11472 ExternalArrayInfoTestHelper(v8::kExternalShortArray);
11450 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); 11473 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
11451 ExternalArrayInfoTestHelper(v8::kExternalIntArray); 11474 ExternalArrayInfoTestHelper(v8::kExternalIntArray);
11452 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); 11475 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
11453 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); 11476 ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
11477 ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
11454 } 11478 }
11455 11479
11456 11480
11457 THREADED_TEST(ScriptContextDependence) { 11481 THREADED_TEST(ScriptContextDependence) {
11458 v8::HandleScope scope; 11482 v8::HandleScope scope;
11459 LocalContext c1; 11483 LocalContext c1;
11460 const char *source = "foo"; 11484 const char *source = "foo";
11461 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 11485 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
11462 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 11486 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
11463 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 11487 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
12884 v8::Handle<v8::Function> define_property = 12908 v8::Handle<v8::Function> define_property =
12885 CompileRun("(function() {" 12909 CompileRun("(function() {"
12886 " Object.defineProperty(" 12910 " Object.defineProperty("
12887 " this," 12911 " this,"
12888 " 1," 12912 " 1,"
12889 " { configurable: true, enumerable: true, value: 3 });" 12913 " { configurable: true, enumerable: true, value: 3 });"
12890 "})").As<Function>(); 12914 "})").As<Function>();
12891 context->DetachGlobal(); 12915 context->DetachGlobal();
12892 define_property->Call(proxy, 0, NULL); 12916 define_property->Call(proxy, 0, NULL);
12893 } 12917 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698