| OLD | NEW |
| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // We want to test our deprecated API entries, too. |
| 29 #define V8_DISABLE_DEPRECATIONS 1 |
| 30 |
| 28 #include <limits.h> | 31 #include <limits.h> |
| 29 | 32 |
| 30 #ifndef WIN32 | 33 #ifndef WIN32 |
| 31 #include <signal.h> // kill | 34 #include <signal.h> // kill |
| 32 #include <unistd.h> // getpid | 35 #include <unistd.h> // getpid |
| 33 #endif // WIN32 | 36 #endif // WIN32 |
| 34 | 37 |
| 35 #include "v8.h" | 38 #include "v8.h" |
| 36 | 39 |
| 37 #include "api.h" | 40 #include "api.h" |
| (...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2051 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2049 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); | 2052 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0)); |
| 2050 | 2053 |
| 2051 obj->SetInternalField(0, v8::External::Wrap(unaligned)); | 2054 obj->SetInternalField(0, v8::External::Wrap(unaligned)); |
| 2052 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2055 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2053 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); | 2056 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0)); |
| 2054 | 2057 |
| 2055 delete[] data; | 2058 delete[] data; |
| 2056 } | 2059 } |
| 2057 | 2060 |
| 2061 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, |
| 2062 void* value) { |
| 2063 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
| 2064 obj->SetPointerInInternalField(0, value); |
| 2065 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2066 CHECK_EQ(value, obj->GetPointerFromInternalField(0)); |
| 2067 } |
| 2068 |
| 2069 |
| 2070 THREADED_TEST(InternalFieldsAlignedPointers) { |
| 2071 v8::HandleScope scope; |
| 2072 LocalContext env; |
| 2073 |
| 2074 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
| 2075 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 2076 instance_templ->SetInternalFieldCount(1); |
| 2077 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 2078 CHECK_EQ(1, obj->InternalFieldCount()); |
| 2079 |
| 2080 CheckAlignedPointerInInternalField(obj, NULL); |
| 2081 |
| 2082 int* heap_allocated = new int[100]; |
| 2083 CheckAlignedPointerInInternalField(obj, heap_allocated); |
| 2084 delete[] heap_allocated; |
| 2085 |
| 2086 int stack_allocated[100]; |
| 2087 CheckAlignedPointerInInternalField(obj, stack_allocated); |
| 2088 |
| 2089 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); |
| 2090 CheckAlignedPointerInInternalField(obj, huge); |
| 2091 } |
| 2092 |
| 2058 | 2093 |
| 2059 THREADED_TEST(IdentityHash) { | 2094 THREADED_TEST(IdentityHash) { |
| 2060 v8::HandleScope scope; | 2095 v8::HandleScope scope; |
| 2061 LocalContext env; | 2096 LocalContext env; |
| 2062 | 2097 |
| 2063 // Ensure that the test starts with an fresh heap to test whether the hash | 2098 // Ensure that the test starts with an fresh heap to test whether the hash |
| 2064 // code is based on the address. | 2099 // code is based on the address. |
| 2065 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 2100 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2066 Local<v8::Object> obj = v8::Object::New(); | 2101 Local<v8::Object> obj = v8::Object::New(); |
| 2067 int hash = obj->GetIdentityHash(); | 2102 int hash = obj->GetIdentityHash(); |
| (...skipping 15694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17762 | 17797 |
| 17763 i::Semaphore* sem_; | 17798 i::Semaphore* sem_; |
| 17764 volatile int sem_value_; | 17799 volatile int sem_value_; |
| 17765 }; | 17800 }; |
| 17766 | 17801 |
| 17767 | 17802 |
| 17768 THREADED_TEST(SemaphoreInterruption) { | 17803 THREADED_TEST(SemaphoreInterruption) { |
| 17769 ThreadInterruptTest().RunTest(); | 17804 ThreadInterruptTest().RunTest(); |
| 17770 } | 17805 } |
| 17771 #endif // WIN32 | 17806 #endif // WIN32 |
| OLD | NEW |