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

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

Issue 11190050: Heavy cleanup of the external pointer API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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
OLDNEW
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 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 obj->SetInternalField(0, v8::External::Wrap(aligned)); 2050 obj->SetInternalField(0, v8::External::Wrap(aligned));
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
Michael Starzinger 2012/10/25 09:41:53 Add second empty newline for readability.
Sven Panne 2012/10/25 14:23:08 Done.
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
2093
2094 static void CheckAlignedPointerInEmbedderData(LocalContext* env,
2095 int index,
2096 void* value) {
2097 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2098 (*env)->SetAlignedPointerInEmbedderData(index, value);
2099 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2100 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index));
2101 }
2102
2103
2104 static void* AlignedTestPointer(int i) {
2105 return reinterpret_cast<void*>(i * 1234);
2106 }
2107
2108
2109 THREADED_TEST(EmbedderDataAlignedPointers) {
2110 v8::HandleScope scope;
2111 LocalContext env;
2112
2113 CheckAlignedPointerInEmbedderData(&env, 0, NULL);
2114
2115 int* heap_allocated = new int[100];
2116 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated);
2117 delete[] heap_allocated;
2118
2119 int stack_allocated[100];
2120 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated);
2121
2122 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1));
2123 CheckAlignedPointerInEmbedderData(&env, 3, huge);
2124
2125 // Test growing of the embedder data's backing store.
2126 for (int i = 0; i < 100; i++) {
2127 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i));
2128 }
2129 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2130 for (int i = 0; i < 100; i++) {
2131 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
2132 }
2133 }
2134
2135
2136 static void CheckEmbedderData(LocalContext* env,
2137 int index,
2138 v8::Handle<Value> data) {
2139 (*env)->SetEmbedderData(index, data);
2140 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2141 }
2142
2143 THREADED_TEST(EmbedderData) {
2144 v8::HandleScope scope;
2145 LocalContext env;
2146
2147 CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps"));
2148 CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog."));
2149 CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
2150 CheckEmbedderData(&env, 0, v8::Boolean::New(true));
2151 }
2152
2058 2153
2059 THREADED_TEST(IdentityHash) { 2154 THREADED_TEST(IdentityHash) {
2060 v8::HandleScope scope; 2155 v8::HandleScope scope;
2061 LocalContext env; 2156 LocalContext env;
2062 2157
2063 // Ensure that the test starts with an fresh heap to test whether the hash 2158 // Ensure that the test starts with an fresh heap to test whether the hash
2064 // code is based on the address. 2159 // code is based on the address.
2065 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2160 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2066 Local<v8::Object> obj = v8::Object::New(); 2161 Local<v8::Object> obj = v8::Object::New();
2067 int hash = obj->GetIdentityHash(); 2162 int hash = obj->GetIdentityHash();
(...skipping 15694 matching lines...) Expand 10 before | Expand all | Expand 10 after
17762 17857
17763 i::Semaphore* sem_; 17858 i::Semaphore* sem_;
17764 volatile int sem_value_; 17859 volatile int sem_value_;
17765 }; 17860 };
17766 17861
17767 17862
17768 THREADED_TEST(SemaphoreInterruption) { 17863 THREADED_TEST(SemaphoreInterruption) {
17769 ThreadInterruptTest().RunTest(); 17864 ThreadInterruptTest().RunTest();
17770 } 17865 }
17771 #endif // WIN32 17866 #endif // WIN32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698