OLD | NEW |
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 Loading... |
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::Factory::NewExternalPixelArray(kElementCount, pixel_data); |
10554 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 10554 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
10555 for (int i = 0; i < kElementCount; i++) { | 10555 for (int i = 0; i < kElementCount; i++) { |
10556 pixels->set(i, i % 256); | 10556 pixels->set(i, i % 256); |
10557 } | 10557 } |
10558 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 10558 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
10559 for (int i = 0; i < kElementCount; i++) { | 10559 for (int i = 0; i < kElementCount; i++) { |
10560 CHECK_EQ(i % 256, pixels->get(i)); | 10560 CHECK_EQ(i % 256, pixels->get(i)); |
10561 CHECK_EQ(i % 256, pixel_data[i]); | 10561 CHECK_EQ(i % 256, pixel_data[i]); |
10562 } | 10562 } |
10563 | 10563 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10883 | 10883 |
10884 // Make sure that pixel array loads are optimized by crankshaft. | 10884 // Make sure that pixel array loads are optimized by crankshaft. |
10885 result = CompileRun("function pa_load(p) {" | 10885 result = CompileRun("function pa_load(p) {" |
10886 " var sum = 0;" | 10886 " var sum = 0;" |
10887 " for (var i=0; i<256; ++i) {" | 10887 " for (var i=0; i<256; ++i) {" |
10888 " sum += p[i];" | 10888 " sum += p[i];" |
10889 " }" | 10889 " }" |
10890 " return sum; " | 10890 " return sum; " |
10891 "}" | 10891 "}" |
10892 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | 10892 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
10893 "for (var i = 0; i < 10000; ++i) {" | 10893 "for (var i = 0; i < 5000; ++i) {" |
10894 " result = pa_load(pixels);" | 10894 " result = pa_load(pixels);" |
10895 "}" | 10895 "}" |
10896 "result"); | 10896 "result"); |
10897 CHECK_EQ(32640, result->Int32Value()); | 10897 CHECK_EQ(32640, result->Int32Value()); |
10898 | 10898 |
10899 // Make sure that pixel array stores are optimized by crankshaft. | 10899 // Make sure that pixel array stores are optimized by crankshaft. |
10900 result = CompileRun("function pa_init(p) {" | 10900 result = CompileRun("function pa_init(p) {" |
10901 "for (var i = 0; i < 256; ++i) { p[i] = i; }" | 10901 "for (var i = 0; i < 256; ++i) { p[i] = i; }" |
10902 "}" | 10902 "}" |
10903 "function pa_load(p) {" | 10903 "function pa_load(p) {" |
10904 " var sum = 0;" | 10904 " var sum = 0;" |
10905 " for (var i=0; i<256; ++i) {" | 10905 " for (var i=0; i<256; ++i) {" |
10906 " sum += p[i];" | 10906 " sum += p[i];" |
10907 " }" | 10907 " }" |
10908 " return sum; " | 10908 " return sum; " |
10909 "}" | 10909 "}" |
10910 "for (var i = 0; i < 100000; ++i) {" | 10910 "for (var i = 0; i < 5000; ++i) {" |
10911 " pa_init(pixels);" | 10911 " pa_init(pixels);" |
10912 "}" | 10912 "}" |
10913 "result = pa_load(pixels);" | 10913 "result = pa_load(pixels);" |
10914 "result"); | 10914 "result"); |
10915 CHECK_EQ(32640, result->Int32Value()); | 10915 CHECK_EQ(32640, result->Int32Value()); |
10916 | 10916 |
10917 free(pixel_data); | 10917 free(pixel_data); |
10918 } | 10918 } |
10919 | 10919 |
10920 | 10920 |
(...skipping 27 matching lines...) Expand all Loading... |
10948 ApiTestFuzzer::Fuzz(); | 10948 ApiTestFuzzer::Fuzz(); |
10949 return v8::Handle<Value>(); | 10949 return v8::Handle<Value>(); |
10950 } | 10950 } |
10951 | 10951 |
10952 | 10952 |
10953 THREADED_TEST(PixelArrayWithInterceptor) { | 10953 THREADED_TEST(PixelArrayWithInterceptor) { |
10954 v8::HandleScope scope; | 10954 v8::HandleScope scope; |
10955 LocalContext context; | 10955 LocalContext context; |
10956 const int kElementCount = 260; | 10956 const int kElementCount = 260; |
10957 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 10957 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
10958 i::Handle<i::PixelArray> pixels = | 10958 i::Handle<i::ExternalPixelArray> pixels = |
10959 i::Factory::NewPixelArray(kElementCount, pixel_data); | 10959 i::Factory::NewExternalPixelArray(kElementCount, pixel_data); |
10960 for (int i = 0; i < kElementCount; i++) { | 10960 for (int i = 0; i < kElementCount; i++) { |
10961 pixels->set(i, i % 256); | 10961 pixels->set(i, i % 256); |
10962 } | 10962 } |
10963 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 10963 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
10964 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, | 10964 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, |
10965 NotHandledIndexedPropertySetter); | 10965 NotHandledIndexedPropertySetter); |
10966 v8::Handle<v8::Object> obj = templ->NewInstance(); | 10966 v8::Handle<v8::Object> obj = templ->NewInstance(); |
10967 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 10967 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
10968 context->Global()->Set(v8_str("pixels"), obj); | 10968 context->Global()->Set(v8_str("pixels"), obj); |
10969 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); | 10969 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); |
10970 CHECK_EQ(1, result->Int32Value()); | 10970 CHECK_EQ(1, result->Int32Value()); |
10971 result = CompileRun("var sum = 0;" | 10971 result = CompileRun("var sum = 0;" |
10972 "for (var i = 0; i < 8; i++) {" | 10972 "for (var i = 0; i < 8; i++) {" |
10973 " sum += pixels[i] = pixels[i] = -i;" | 10973 " sum += pixels[i] = pixels[i] = -i;" |
10974 "}" | 10974 "}" |
10975 "sum;"); | 10975 "sum;"); |
10976 CHECK_EQ(-28, result->Int32Value()); | 10976 CHECK_EQ(-28, result->Int32Value()); |
10977 result = CompileRun("pixels.hasOwnProperty('1')"); | 10977 result = CompileRun("pixels.hasOwnProperty('1')"); |
10978 CHECK(result->BooleanValue()); | 10978 CHECK(result->BooleanValue()); |
10979 free(pixel_data); | 10979 free(pixel_data); |
10980 } | 10980 } |
10981 | 10981 |
10982 | 10982 |
10983 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { | 10983 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { |
10984 switch (array_type) { | 10984 switch (array_type) { |
10985 case v8::kExternalByteArray: | 10985 case v8::kExternalByteArray: |
10986 case v8::kExternalUnsignedByteArray: | 10986 case v8::kExternalUnsignedByteArray: |
| 10987 case v8::kExternalPixelArray: |
10987 return 1; | 10988 return 1; |
10988 break; | 10989 break; |
10989 case v8::kExternalShortArray: | 10990 case v8::kExternalShortArray: |
10990 case v8::kExternalUnsignedShortArray: | 10991 case v8::kExternalUnsignedShortArray: |
10991 return 2; | 10992 return 2; |
10992 break; | 10993 break; |
10993 case v8::kExternalIntArray: | 10994 case v8::kExternalIntArray: |
10994 case v8::kExternalUnsignedIntArray: | 10995 case v8::kExternalUnsignedIntArray: |
10995 case v8::kExternalFloatArray: | 10996 case v8::kExternalFloatArray: |
10996 return 4; | 10997 return 4; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11367 | 11368 |
11368 | 11369 |
11369 THREADED_TEST(ExternalUnsignedByteArray) { | 11370 THREADED_TEST(ExternalUnsignedByteArray) { |
11370 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>( | 11371 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>( |
11371 v8::kExternalUnsignedByteArray, | 11372 v8::kExternalUnsignedByteArray, |
11372 0, | 11373 0, |
11373 255); | 11374 255); |
11374 } | 11375 } |
11375 | 11376 |
11376 | 11377 |
| 11378 THREADED_TEST(ExternalPixelArray) { |
| 11379 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>( |
| 11380 v8::kExternalPixelArray, |
| 11381 0, |
| 11382 255); |
| 11383 } |
| 11384 |
| 11385 |
11377 THREADED_TEST(ExternalShortArray) { | 11386 THREADED_TEST(ExternalShortArray) { |
11378 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>( | 11387 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>( |
11379 v8::kExternalShortArray, | 11388 v8::kExternalShortArray, |
11380 -32768, | 11389 -32768, |
11381 32767); | 11390 32767); |
11382 } | 11391 } |
11383 | 11392 |
11384 | 11393 |
11385 THREADED_TEST(ExternalUnsignedShortArray) { | 11394 THREADED_TEST(ExternalUnsignedShortArray) { |
11386 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>( | 11395 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11444 | 11453 |
11445 | 11454 |
11446 THREADED_TEST(ExternalArrayInfo) { | 11455 THREADED_TEST(ExternalArrayInfo) { |
11447 ExternalArrayInfoTestHelper(v8::kExternalByteArray); | 11456 ExternalArrayInfoTestHelper(v8::kExternalByteArray); |
11448 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); | 11457 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); |
11449 ExternalArrayInfoTestHelper(v8::kExternalShortArray); | 11458 ExternalArrayInfoTestHelper(v8::kExternalShortArray); |
11450 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); | 11459 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); |
11451 ExternalArrayInfoTestHelper(v8::kExternalIntArray); | 11460 ExternalArrayInfoTestHelper(v8::kExternalIntArray); |
11452 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); | 11461 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); |
11453 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); | 11462 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); |
| 11463 ExternalArrayInfoTestHelper(v8::kExternalPixelArray); |
11454 } | 11464 } |
11455 | 11465 |
11456 | 11466 |
11457 THREADED_TEST(ScriptContextDependence) { | 11467 THREADED_TEST(ScriptContextDependence) { |
11458 v8::HandleScope scope; | 11468 v8::HandleScope scope; |
11459 LocalContext c1; | 11469 LocalContext c1; |
11460 const char *source = "foo"; | 11470 const char *source = "foo"; |
11461 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); | 11471 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)); | 11472 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); |
11463 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); | 11473 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12884 v8::Handle<v8::Function> define_property = | 12894 v8::Handle<v8::Function> define_property = |
12885 CompileRun("(function() {" | 12895 CompileRun("(function() {" |
12886 " Object.defineProperty(" | 12896 " Object.defineProperty(" |
12887 " this," | 12897 " this," |
12888 " 1," | 12898 " 1," |
12889 " { configurable: true, enumerable: true, value: 3 });" | 12899 " { configurable: true, enumerable: true, value: 3 });" |
12890 "})").As<Function>(); | 12900 "})").As<Function>(); |
12891 context->DetachGlobal(); | 12901 context->DetachGlobal(); |
12892 define_property->Call(proxy, 0, NULL); | 12902 define_property->Call(proxy, 0, NULL); |
12893 } | 12903 } |
OLD | NEW |