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

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

Issue 933533003: Version 4.2.70.1 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.2.70
Patch Set: Created 5 years, 10 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
« no previous file with comments | « src/version.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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) { 55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) {
56 for (Object* o = heap->array_buffers_list(); 56 for (Object* o = heap->array_buffers_list();
57 !o->IsUndefined(); 57 !o->IsUndefined();
58 o = JSArrayBuffer::cast(o)->weak_next()) { 58 o = JSArrayBuffer::cast(o)->weak_next()) {
59 if (ab == o) return true; 59 if (ab == o) return true;
60 } 60 }
61 return false; 61 return false;
62 } 62 }
63 63
64 64
65 static int CountViewsInNewSpaceList(Heap* heap, JSArrayBuffer* array_buffer) { 65 static int CountViews(JSArrayBuffer* array_buffer) {
66 int count = 0;
67 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();) {
68 JSArrayBufferView* view = JSArrayBufferView::cast(o);
69 if (array_buffer == view->buffer()) {
70 count++;
71 }
72 o = view->weak_next();
73 }
74 return count;
75 }
76
77
78 static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) {
79 int count = 0; 66 int count = 0;
80 for (Object* o = array_buffer->weak_first_view(); 67 for (Object* o = array_buffer->weak_first_view();
81 !o->IsUndefined(); 68 !o->IsUndefined();
82 o = JSArrayBufferView::cast(o)->weak_next()) { 69 o = JSArrayBufferView::cast(o)->weak_next()) {
83 count++; 70 count++;
84 } 71 }
85 72
86 return count + CountViewsInNewSpaceList(heap, array_buffer); 73 return count;
87 } 74 }
88 75
89 76 static bool HasViewInWeakList(JSArrayBuffer* array_buffer,
90 static bool HasViewInNewSpaceList(Heap* heap, JSArrayBufferView* ta) { 77 JSArrayBufferView* ta) {
91 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined(); 78 for (Object* o = array_buffer->weak_first_view();
79 !o->IsUndefined();
92 o = JSArrayBufferView::cast(o)->weak_next()) { 80 o = JSArrayBufferView::cast(o)->weak_next()) {
93 if (ta == o) return true; 81 if (ta == o) return true;
94 } 82 }
95 return false; 83 return false;
96 } 84 }
97 85
98 86
99 static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer,
100 JSArrayBufferView* ta) {
101 for (Object* o = array_buffer->weak_first_view();
102 !o->IsUndefined();
103 o = JSArrayBufferView::cast(o)->weak_next()) {
104 if (ta == o) return true;
105 }
106 return HasViewInNewSpaceList(heap, ta);
107 }
108
109
110 TEST(WeakArrayBuffersFromApi) { 87 TEST(WeakArrayBuffersFromApi) {
111 v8::V8::Initialize(); 88 v8::V8::Initialize();
112 LocalContext context; 89 LocalContext context;
113 Isolate* isolate = GetIsolateFrom(&context); 90 Isolate* isolate = GetIsolateFrom(&context);
114 91
115 int start = CountArrayBuffersInWeakList(isolate->heap()); 92 int start = CountArrayBuffersInWeakList(isolate->heap());
116 { 93 {
117 v8::HandleScope s1(context->GetIsolate()); 94 v8::HandleScope s1(context->GetIsolate());
118 v8::Handle<v8::ArrayBuffer> ab1 = 95 v8::Handle<v8::ArrayBuffer> ab1 =
119 v8::ArrayBuffer::New(context->GetIsolate(), 256); 96 v8::ArrayBuffer::New(context->GetIsolate(), 256);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 193 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
217 { 194 {
218 v8::HandleScope s2(context->GetIsolate()); 195 v8::HandleScope s2(context->GetIsolate());
219 v8::Handle<View> ta1 = View::New(ab, 0, 256); 196 v8::Handle<View> ta1 = View::New(ab, 0, 256);
220 { 197 {
221 v8::HandleScope s3(context->GetIsolate()); 198 v8::HandleScope s3(context->GetIsolate());
222 v8::Handle<View> ta2 = View::New(ab, 0, 128); 199 v8::Handle<View> ta2 = View::New(ab, 0, 128);
223 200
224 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); 201 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
225 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); 202 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2);
226 CHECK_EQ(2, CountViews(isolate->heap(), *iab)); 203 CHECK_EQ(2, CountViews(*iab));
227 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); 204 CHECK(HasViewInWeakList(*iab, *ita1));
228 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2)); 205 CHECK(HasViewInWeakList(*iab, *ita2));
229 } 206 }
230 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 207 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
231 CHECK_EQ(1, CountViews(isolate->heap(), *iab)); 208 CHECK_EQ(1, CountViews(*iab));
232 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); 209 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
233 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); 210 CHECK(HasViewInWeakList(*iab, *ita1));
234 } 211 }
235 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 212 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
236 213
237 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); 214 CHECK_EQ(0, CountViews(*iab));
238 } 215 }
239 216
240 217
241 TEST(Uint8ArrayFromApi) { 218 TEST(Uint8ArrayFromApi) {
242 TestViewFromApi<v8::Uint8Array>(); 219 TestViewFromApi<v8::Uint8Array>();
243 } 220 }
244 221
245 222
246 TEST(Int8ArrayFromApi) { 223 TEST(Int8ArrayFromApi) {
247 TestViewFromApi<v8::Int8Array>(); 224 TestViewFromApi<v8::Int8Array>();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 v8::Handle<v8::ArrayBuffer> ab = 292 v8::Handle<v8::ArrayBuffer> ab =
316 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 293 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
317 v8::Handle<TypedArray> ta1 = 294 v8::Handle<TypedArray> ta1 =
318 v8::Handle<TypedArray>::Cast(CompileRun("ta1")); 295 v8::Handle<TypedArray>::Cast(CompileRun("ta1"));
319 v8::Handle<TypedArray> ta2 = 296 v8::Handle<TypedArray> ta2 =
320 v8::Handle<TypedArray>::Cast(CompileRun("ta2")); 297 v8::Handle<TypedArray>::Cast(CompileRun("ta2"));
321 v8::Handle<TypedArray> ta3 = 298 v8::Handle<TypedArray> ta3 =
322 v8::Handle<TypedArray>::Cast(CompileRun("ta3")); 299 v8::Handle<TypedArray>::Cast(CompileRun("ta3"));
323 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 300 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
324 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 301 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
325 CHECK_EQ(3, CountViews(isolate->heap(), *iab)); 302 CHECK_EQ(3, CountViews(*iab));
326 CHECK(HasViewInWeakList(isolate->heap(), *iab, 303 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1)));
327 *v8::Utils::OpenHandle(*ta1))); 304 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2)));
328 CHECK(HasViewInWeakList(isolate->heap(), *iab, 305 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3)));
329 *v8::Utils::OpenHandle(*ta2)));
330 CHECK(HasViewInWeakList(isolate->heap(), *iab,
331 *v8::Utils::OpenHandle(*ta3)));
332 } 306 }
333 307
334 i::SNPrintF(source, "ta%d = null;", i); 308 i::SNPrintF(source, "ta%d = null;", i);
335 CompileRun(source.start()); 309 CompileRun(source.start());
336 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 310 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
337 311
338 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 312 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
339 313
340 { 314 {
341 v8::HandleScope s2(context->GetIsolate()); 315 v8::HandleScope s2(context->GetIsolate());
342 v8::Handle<v8::ArrayBuffer> ab = 316 v8::Handle<v8::ArrayBuffer> ab =
343 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 317 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
344 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 318 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
345 CHECK_EQ(2, CountViews(isolate->heap(), *iab)); 319 CHECK_EQ(2, CountViews(*iab));
346 for (int j = 1; j <= 3; j++) { 320 for (int j = 1; j <= 3; j++) {
347 if (j == i) continue; 321 if (j == i) continue;
348 i::SNPrintF(source, "ta%d", j); 322 i::SNPrintF(source, "ta%d", j);
349 v8::Handle<TypedArray> ta = 323 v8::Handle<TypedArray> ta =
350 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); 324 v8::Handle<TypedArray>::Cast(CompileRun(source.start()));
351 CHECK(HasViewInWeakList(isolate->heap(), *iab, 325 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta)));
352 *v8::Utils::OpenHandle(*ta)));
353 } 326 }
354 } 327 }
355 328
356 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); 329 CompileRun("ta1 = null; ta2 = null; ta3 = null;");
357 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 330 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
358 331
359 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); 332 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
360 333
361 { 334 {
362 v8::HandleScope s3(context->GetIsolate()); 335 v8::HandleScope s3(context->GetIsolate());
363 v8::Handle<v8::ArrayBuffer> ab = 336 v8::Handle<v8::ArrayBuffer> ab =
364 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 337 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
365 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 338 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
366 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); 339 CHECK_EQ(0, CountViews(*iab));
367 } 340 }
368 } 341 }
369 } 342 }
370 343
371 344
372 TEST(Uint8ArrayFromScript) { 345 TEST(Uint8ArrayFromScript) {
373 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); 346 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array");
374 } 347 }
375 348
376 349
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 383
411 384
412 TEST(Uint8ClampedArrayFromScript) { 385 TEST(Uint8ClampedArrayFromScript) {
413 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); 386 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray");
414 } 387 }
415 388
416 389
417 TEST(DataViewFromScript) { 390 TEST(DataViewFromScript) {
418 TestTypedArrayFromScript<v8::DataView>("DataView"); 391 TestTypedArrayFromScript<v8::DataView>("DataView");
419 } 392 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698