| 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 9619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9630 CHECK_EQ(255, result->Int32Value()); | 9630 CHECK_EQ(255, result->Int32Value()); |
| 9631 result = CompileRun("var i = 0;" | 9631 result = CompileRun("var i = 0;" |
| 9632 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" | 9632 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" |
| 9633 "i"); | 9633 "i"); |
| 9634 CHECK_EQ(255, result->Int32Value()); | 9634 CHECK_EQ(255, result->Int32Value()); |
| 9635 | 9635 |
| 9636 free(pixel_data); | 9636 free(pixel_data); |
| 9637 } | 9637 } |
| 9638 | 9638 |
| 9639 | 9639 |
| 9640 THREADED_TEST(PixelArrayInfo) { |
| 9641 v8::HandleScope scope; |
| 9642 LocalContext context; |
| 9643 for (int size = 0; size < 100; size += 10) { |
| 9644 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); |
| 9645 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 9646 obj->SetIndexedPropertiesToPixelData(pixel_data, size); |
| 9647 CHECK(obj->HasIndexedPropertiesInPixelData()); |
| 9648 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); |
| 9649 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); |
| 9650 free(pixel_data); |
| 9651 } |
| 9652 } |
| 9653 |
| 9654 |
| 9655 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { |
| 9656 switch (array_type) { |
| 9657 case v8::kExternalByteArray: |
| 9658 case v8::kExternalUnsignedByteArray: |
| 9659 return 1; |
| 9660 break; |
| 9661 case v8::kExternalShortArray: |
| 9662 case v8::kExternalUnsignedShortArray: |
| 9663 return 2; |
| 9664 break; |
| 9665 case v8::kExternalIntArray: |
| 9666 case v8::kExternalUnsignedIntArray: |
| 9667 case v8::kExternalFloatArray: |
| 9668 return 4; |
| 9669 break; |
| 9670 default: |
| 9671 UNREACHABLE(); |
| 9672 return -1; |
| 9673 } |
| 9674 } |
| 9675 |
| 9676 |
| 9640 template <class ExternalArrayClass, class ElementType> | 9677 template <class ExternalArrayClass, class ElementType> |
| 9641 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, | 9678 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, |
| 9642 int64_t low, | 9679 int64_t low, |
| 9643 int64_t high) { | 9680 int64_t high) { |
| 9644 v8::HandleScope scope; | 9681 v8::HandleScope scope; |
| 9645 LocalContext context; | 9682 LocalContext context; |
| 9646 const int kElementCount = 40; | 9683 const int kElementCount = 40; |
| 9647 int element_size = 0; | 9684 int element_size = ExternalArrayElementSize(array_type); |
| 9648 switch (array_type) { | |
| 9649 case v8::kExternalByteArray: | |
| 9650 case v8::kExternalUnsignedByteArray: | |
| 9651 element_size = 1; | |
| 9652 break; | |
| 9653 case v8::kExternalShortArray: | |
| 9654 case v8::kExternalUnsignedShortArray: | |
| 9655 element_size = 2; | |
| 9656 break; | |
| 9657 case v8::kExternalIntArray: | |
| 9658 case v8::kExternalUnsignedIntArray: | |
| 9659 case v8::kExternalFloatArray: | |
| 9660 element_size = 4; | |
| 9661 break; | |
| 9662 default: | |
| 9663 UNREACHABLE(); | |
| 9664 break; | |
| 9665 } | |
| 9666 ElementType* array_data = | 9685 ElementType* array_data = |
| 9667 static_cast<ElementType*>(malloc(kElementCount * element_size)); | 9686 static_cast<ElementType*>(malloc(kElementCount * element_size)); |
| 9668 i::Handle<ExternalArrayClass> array = | 9687 i::Handle<ExternalArrayClass> array = |
| 9669 i::Handle<ExternalArrayClass>::cast( | 9688 i::Handle<ExternalArrayClass>::cast( |
| 9670 i::Factory::NewExternalArray(kElementCount, array_type, array_data)); | 9689 i::Factory::NewExternalArray(kElementCount, array_type, array_data)); |
| 9671 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 9690 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
| 9672 for (int i = 0; i < kElementCount; i++) { | 9691 for (int i = 0; i < kElementCount; i++) { |
| 9673 array->set(i, static_cast<ElementType>(i)); | 9692 array->set(i, static_cast<ElementType>(i)); |
| 9674 } | 9693 } |
| 9675 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 9694 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10036 TestExternalByteArray(); | 10055 TestExternalByteArray(); |
| 10037 TestExternalUnsignedByteArray(); | 10056 TestExternalUnsignedByteArray(); |
| 10038 TestExternalShortArray(); | 10057 TestExternalShortArray(); |
| 10039 TestExternalUnsignedShortArray(); | 10058 TestExternalUnsignedShortArray(); |
| 10040 TestExternalIntArray(); | 10059 TestExternalIntArray(); |
| 10041 TestExternalUnsignedIntArray(); | 10060 TestExternalUnsignedIntArray(); |
| 10042 TestExternalFloatArray(); | 10061 TestExternalFloatArray(); |
| 10043 } | 10062 } |
| 10044 | 10063 |
| 10045 | 10064 |
| 10065 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { |
| 10066 v8::HandleScope scope; |
| 10067 LocalContext context; |
| 10068 for (int size = 0; size < 100; size += 10) { |
| 10069 int element_size = ExternalArrayElementSize(array_type); |
| 10070 void* external_data = malloc(size * element_size); |
| 10071 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 10072 obj->SetIndexedPropertiesToExternalArrayData( |
| 10073 external_data, array_type, size); |
| 10074 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); |
| 10075 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); |
| 10076 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); |
| 10077 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); |
| 10078 free(external_data); |
| 10079 } |
| 10080 } |
| 10081 |
| 10082 |
| 10083 THREADED_TEST(ExternalArrayInfo) { |
| 10084 ExternalArrayInfoTestHelper(v8::kExternalByteArray); |
| 10085 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); |
| 10086 ExternalArrayInfoTestHelper(v8::kExternalShortArray); |
| 10087 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); |
| 10088 ExternalArrayInfoTestHelper(v8::kExternalIntArray); |
| 10089 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); |
| 10090 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); |
| 10091 } |
| 10092 |
| 10093 |
| 10046 THREADED_TEST(ScriptContextDependence) { | 10094 THREADED_TEST(ScriptContextDependence) { |
| 10047 v8::HandleScope scope; | 10095 v8::HandleScope scope; |
| 10048 LocalContext c1; | 10096 LocalContext c1; |
| 10049 const char *source = "foo"; | 10097 const char *source = "foo"; |
| 10050 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); | 10098 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); |
| 10051 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); | 10099 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); |
| 10052 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); | 10100 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); |
| 10053 CHECK_EQ(dep->Run()->Int32Value(), 100); | 10101 CHECK_EQ(dep->Run()->Int32Value(), 100); |
| 10054 CHECK_EQ(indep->Run()->Int32Value(), 100); | 10102 CHECK_EQ(indep->Run()->Int32Value(), 100); |
| 10055 LocalContext c2; | 10103 LocalContext c2; |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10868 const char* code = | 10916 const char* code = |
| 10869 "(function() {" | 10917 "(function() {" |
| 10870 " for (var i = 0; i < 2*16; i++) {" | 10918 " for (var i = 0; i < 2*16; i++) {" |
| 10871 " %_GetFromCache(0, 'a' + i);" | 10919 " %_GetFromCache(0, 'a' + i);" |
| 10872 " };" | 10920 " };" |
| 10873 " return 'PASSED';" | 10921 " return 'PASSED';" |
| 10874 "})()"; | 10922 "})()"; |
| 10875 v8::internal::Heap::ClearJSFunctionResultCaches(); | 10923 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10876 ExpectString(code, "PASSED"); | 10924 ExpectString(code, "PASSED"); |
| 10877 } | 10925 } |
| OLD | NEW |