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

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

Issue 16950013: Do not use weak handles for ArrayBuffers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
« src/heap.cc ('K') | « src/runtime.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 v8::HandleScope s2(context->GetIsolate()); 97 v8::HandleScope s2(context->GetIsolate());
98 v8::Handle<v8::ArrayBuffer> ab2 = v8::ArrayBuffer::New(128); 98 v8::Handle<v8::ArrayBuffer> ab2 = v8::ArrayBuffer::New(128);
99 99
100 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); 100 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1);
101 Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2); 101 Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2);
102 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); 102 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()));
103 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); 103 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1));
104 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2)); 104 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2));
105 } 105 }
106 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 106 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
107 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
108 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 107 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
109 { 108 {
110 HandleScope scope2(isolate); 109 HandleScope scope2(isolate);
111 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); 110 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1);
112 111
113 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); 112 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1));
114 } 113 }
115 } 114 }
116 115
117 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 116 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
118 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
119 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); 117 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
120 } 118 }
121 119
122 120
123 TEST(WeakArrayBuffersFromScript) { 121 TEST(WeakArrayBuffersFromScript) {
124 v8::V8::Initialize(); 122 v8::V8::Initialize();
125 LocalContext context; 123 LocalContext context;
126 Isolate* isolate = GetIsolateFrom(&context); 124 Isolate* isolate = GetIsolateFrom(&context);
127 125
128 for (int i = 1; i <= 3; i++) { 126 for (int i = 1; i <= 3; i++) {
(...skipping 21 matching lines...) Expand all
150 CHECK(HasArrayBufferInWeakList(isolate->heap(), 148 CHECK(HasArrayBufferInWeakList(isolate->heap(),
151 *v8::Utils::OpenHandle(*ab2))); 149 *v8::Utils::OpenHandle(*ab2)));
152 CHECK(HasArrayBufferInWeakList(isolate->heap(), 150 CHECK(HasArrayBufferInWeakList(isolate->heap(),
153 *v8::Utils::OpenHandle(*ab3))); 151 *v8::Utils::OpenHandle(*ab3)));
154 } 152 }
155 153
156 i::ScopedVector<char> source(1024); 154 i::ScopedVector<char> source(1024);
157 i::OS::SNPrintF(source, "ab%d = null;", i); 155 i::OS::SNPrintF(source, "ab%d = null;", i);
158 CompileRun(source.start()); 156 CompileRun(source.start());
159 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 157 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
160 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
161 158
162 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); 159 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()));
163 160
164 { 161 {
165 v8::HandleScope s2(context->GetIsolate()); 162 v8::HandleScope s2(context->GetIsolate());
166 for (int j = 1; j <= 3; j++) { 163 for (int j = 1; j <= 3; j++) {
167 if (j == i) continue; 164 if (j == i) continue;
168 i::OS::SNPrintF(source, "ab%d", j); 165 i::OS::SNPrintF(source, "ab%d", j);
169 v8::Handle<v8::ArrayBuffer> ab = 166 v8::Handle<v8::ArrayBuffer> ab =
170 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun(source.start())); 167 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun(source.start()));
171 CHECK(HasArrayBufferInWeakList(isolate->heap(), 168 CHECK(HasArrayBufferInWeakList(isolate->heap(),
172 *v8::Utils::OpenHandle(*ab))); 169 *v8::Utils::OpenHandle(*ab)));
173 } 170 }
174 } 171 }
175 172
176 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); 173 CompileRun("ab1 = null; ab2 = null; ab3 = null;");
177 } 174 }
178 175
179 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 176 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
180 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
181 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); 177 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
182 } 178 }
183 } 179 }
184 180
185 template <typename TypedArray> 181 template <typename TypedArray>
186 void TestTypedArrayFromApi() { 182 void TestTypedArrayFromApi() {
187 v8::V8::Initialize(); 183 v8::V8::Initialize();
188 LocalContext context; 184 LocalContext context;
189 Isolate* isolate = GetIsolateFrom(&context); 185 Isolate* isolate = GetIsolateFrom(&context);
190 186
191 v8::HandleScope s1(context->GetIsolate()); 187 v8::HandleScope s1(context->GetIsolate());
192 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048); 188 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048);
193 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 189 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
194 { 190 {
195 v8::HandleScope s2(context->GetIsolate()); 191 v8::HandleScope s2(context->GetIsolate());
196 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256); 192 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256);
197 { 193 {
198 v8::HandleScope s3(context->GetIsolate()); 194 v8::HandleScope s3(context->GetIsolate());
199 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128); 195 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128);
200 196
201 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); 197 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1);
202 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2); 198 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2);
203 CHECK_EQ(2, CountTypedArrays(*iab)); 199 CHECK_EQ(2, CountTypedArrays(*iab));
204 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); 200 CHECK(HasTypedArrayInWeakList(*iab, *ita1));
205 CHECK(HasTypedArrayInWeakList(*iab, *ita2)); 201 CHECK(HasTypedArrayInWeakList(*iab, *ita2));
206 } 202 }
207 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 203 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
208 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
209 CHECK_EQ(1, CountTypedArrays(*iab)); 204 CHECK_EQ(1, CountTypedArrays(*iab));
210 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); 205 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1);
211 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); 206 CHECK(HasTypedArrayInWeakList(*iab, *ita1));
212 } 207 }
213 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 208 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
214 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
215 209
216 CHECK_EQ(0, CountTypedArrays(*iab)); 210 CHECK_EQ(0, CountTypedArrays(*iab));
217 } 211 }
218 212
219 213
220 TEST(Uint8ArrayFromApi) { 214 TEST(Uint8ArrayFromApi) {
221 TestTypedArrayFromApi<v8::Uint8Array>(); 215 TestTypedArrayFromApi<v8::Uint8Array>();
222 } 216 }
223 217
224 218
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 291 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
298 CHECK_EQ(3, CountTypedArrays(*iab)); 292 CHECK_EQ(3, CountTypedArrays(*iab));
299 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); 293 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta1)));
300 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); 294 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta2)));
301 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); 295 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta3)));
302 } 296 }
303 297
304 i::OS::SNPrintF(source, "ta%d = null;", i); 298 i::OS::SNPrintF(source, "ta%d = null;", i);
305 CompileRun(source.start()); 299 CompileRun(source.start());
306 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 300 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
307 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
308 301
309 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 302 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
310 303
311 { 304 {
312 v8::HandleScope s2(context->GetIsolate()); 305 v8::HandleScope s2(context->GetIsolate());
313 v8::Handle<v8::ArrayBuffer> ab = 306 v8::Handle<v8::ArrayBuffer> ab =
314 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 307 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
315 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 308 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
316 CHECK_EQ(2, CountTypedArrays(*iab)); 309 CHECK_EQ(2, CountTypedArrays(*iab));
317 for (int j = 1; j <= 3; j++) { 310 for (int j = 1; j <= 3; j++) {
318 if (j == i) continue; 311 if (j == i) continue;
319 i::OS::SNPrintF(source, "ta%d", j); 312 i::OS::SNPrintF(source, "ta%d", j);
320 v8::Handle<TypedArray> ta = 313 v8::Handle<TypedArray> ta =
321 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); 314 v8::Handle<TypedArray>::Cast(CompileRun(source.start()));
322 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); 315 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta)));
323 } 316 }
324 } 317 }
325 318
326 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); 319 CompileRun("ta1 = null; ta2 = null; ta3 = null;");
327 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 320 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
328 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
329 321
330 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 322 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
331 323
332 { 324 {
333 v8::HandleScope s3(context->GetIsolate()); 325 v8::HandleScope s3(context->GetIsolate());
334 v8::Handle<v8::ArrayBuffer> ab = 326 v8::Handle<v8::ArrayBuffer> ab =
335 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 327 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
336 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 328 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
337 CHECK_EQ(0, CountTypedArrays(*iab)); 329 CHECK_EQ(0, CountTypedArrays(*iab));
338 } 330 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 369
378 TEST(Float64ArrayFromScript) { 370 TEST(Float64ArrayFromScript) {
379 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); 371 TestTypedArrayFromScript<v8::Float64Array>("Float64Array");
380 } 372 }
381 373
382 374
383 TEST(Uint8ClampedArrayFromScript) { 375 TEST(Uint8ClampedArrayFromScript) {
384 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); 376 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray");
385 } 377 }
386 378
OLDNEW
« src/heap.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698