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

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

Issue 17153011: DataView implementation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/fuzz-natives-part1.js » ('j') | 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 CountTypedArrays(JSArrayBuffer* array_buffer) { 65 static int CountViews(JSArrayBuffer* array_buffer) {
66 int count = 0; 66 int count = 0;
67 for (Object* o = array_buffer->weak_first_array(); 67 for (Object* o = array_buffer->weak_first_view();
68 !o->IsUndefined(); 68 !o->IsUndefined();
69 o = JSTypedArray::cast(o)->weak_next()) { 69 o = JSArrayBufferView::cast(o)->weak_next()) {
70 count++; 70 count++;
71 } 71 }
72 72
73 return count; 73 return count;
74 } 74 }
75 75
76 static bool HasTypedArrayInWeakList(JSArrayBuffer* array_buffer, 76 static bool HasViewInWeakList(JSArrayBuffer* array_buffer,
77 JSTypedArray* ta) { 77 JSObject* ta) {
78 for (Object* o = array_buffer->weak_first_array(); 78 for (Object* o = array_buffer->weak_first_view();
79 !o->IsUndefined(); 79 !o->IsUndefined();
80 o = JSTypedArray::cast(o)->weak_next()) { 80 o = JSArrayBufferView::cast(o)->weak_next()) {
81 if (ta == o) return true; 81 if (ta == o) return true;
82 } 82 }
83 return false; 83 return false;
84 } 84 }
85 85
86 86
87 TEST(WeakArrayBuffersFromApi) { 87 TEST(WeakArrayBuffersFromApi) {
88 v8::V8::Initialize(); 88 v8::V8::Initialize();
89 LocalContext context; 89 LocalContext context;
90 Isolate* isolate = GetIsolateFrom(&context); 90 Isolate* isolate = GetIsolateFrom(&context);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 189 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
190 { 190 {
191 v8::HandleScope s2(context->GetIsolate()); 191 v8::HandleScope s2(context->GetIsolate());
192 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256); 192 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256);
193 { 193 {
194 v8::HandleScope s3(context->GetIsolate()); 194 v8::HandleScope s3(context->GetIsolate());
195 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128); 195 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128);
196 196
197 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); 197 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1);
198 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2); 198 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2);
199 CHECK_EQ(2, CountTypedArrays(*iab)); 199 CHECK_EQ(2, CountViews(*iab));
200 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); 200 CHECK(HasViewInWeakList(*iab, *ita1));
201 CHECK(HasTypedArrayInWeakList(*iab, *ita2)); 201 CHECK(HasViewInWeakList(*iab, *ita2));
202 } 202 }
203 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 203 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
204 CHECK_EQ(1, CountTypedArrays(*iab)); 204 CHECK_EQ(1, CountViews(*iab));
205 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); 205 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1);
206 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); 206 CHECK(HasViewInWeakList(*iab, *ita1));
207 } 207 }
208 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 208 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
209 209
210 CHECK_EQ(0, CountTypedArrays(*iab)); 210 CHECK_EQ(0, CountViews(*iab));
211 } 211 }
212 212
213 213
214 TEST(Uint8ArrayFromApi) { 214 TEST(Uint8ArrayFromApi) {
215 TestTypedArrayFromApi<v8::Uint8Array>(); 215 TestTypedArrayFromApi<v8::Uint8Array>();
216 } 216 }
217 217
218 218
219 TEST(Int8ArrayFromApi) { 219 TEST(Int8ArrayFromApi) {
220 TestTypedArrayFromApi<v8::Int8Array>(); 220 TestTypedArrayFromApi<v8::Int8Array>();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 v8::Handle<v8::ArrayBuffer> ab = 282 v8::Handle<v8::ArrayBuffer> ab =
283 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 283 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
284 v8::Handle<TypedArray> ta1 = 284 v8::Handle<TypedArray> ta1 =
285 v8::Handle<TypedArray>::Cast(CompileRun("ta1")); 285 v8::Handle<TypedArray>::Cast(CompileRun("ta1"));
286 v8::Handle<TypedArray> ta2 = 286 v8::Handle<TypedArray> ta2 =
287 v8::Handle<TypedArray>::Cast(CompileRun("ta2")); 287 v8::Handle<TypedArray>::Cast(CompileRun("ta2"));
288 v8::Handle<TypedArray> ta3 = 288 v8::Handle<TypedArray> ta3 =
289 v8::Handle<TypedArray>::Cast(CompileRun("ta3")); 289 v8::Handle<TypedArray>::Cast(CompileRun("ta3"));
290 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 290 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
291 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 291 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
292 CHECK_EQ(3, CountTypedArrays(*iab)); 292 CHECK_EQ(3, CountViews(*iab));
293 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); 293 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1)));
294 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); 294 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2)));
295 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); 295 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3)));
296 } 296 }
297 297
298 i::OS::SNPrintF(source, "ta%d = null;", i); 298 i::OS::SNPrintF(source, "ta%d = null;", i);
299 CompileRun(source.start()); 299 CompileRun(source.start());
300 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 300 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
301 301
302 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 302 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
303 303
304 { 304 {
305 v8::HandleScope s2(context->GetIsolate()); 305 v8::HandleScope s2(context->GetIsolate());
306 v8::Handle<v8::ArrayBuffer> ab = 306 v8::Handle<v8::ArrayBuffer> ab =
307 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 307 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
308 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 308 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
309 CHECK_EQ(2, CountTypedArrays(*iab)); 309 CHECK_EQ(2, CountViews(*iab));
310 for (int j = 1; j <= 3; j++) { 310 for (int j = 1; j <= 3; j++) {
311 if (j == i) continue; 311 if (j == i) continue;
312 i::OS::SNPrintF(source, "ta%d", j); 312 i::OS::SNPrintF(source, "ta%d", j);
313 v8::Handle<TypedArray> ta = 313 v8::Handle<TypedArray> ta =
314 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); 314 v8::Handle<TypedArray>::Cast(CompileRun(source.start()));
315 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); 315 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta)));
316 } 316 }
317 } 317 }
318 318
319 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); 319 CompileRun("ta1 = null; ta2 = null; ta3 = null;");
320 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 320 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
321 321
322 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); 322 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
323 323
324 { 324 {
325 v8::HandleScope s3(context->GetIsolate()); 325 v8::HandleScope s3(context->GetIsolate());
326 v8::Handle<v8::ArrayBuffer> ab = 326 v8::Handle<v8::ArrayBuffer> ab =
327 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); 327 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
328 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); 328 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
329 CHECK_EQ(0, CountTypedArrays(*iab)); 329 CHECK_EQ(0, CountViews(*iab));
330 } 330 }
331 } 331 }
332 } 332 }
333 333
334 334
335 TEST(Uint8ArrayFromScript) { 335 TEST(Uint8ArrayFromScript) {
336 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); 336 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array");
337 } 337 }
338 338
339 339
(...skipping 29 matching lines...) Expand all
369 369
370 TEST(Float64ArrayFromScript) { 370 TEST(Float64ArrayFromScript) {
371 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); 371 TestTypedArrayFromScript<v8::Float64Array>("Float64Array");
372 } 372 }
373 373
374 374
375 TEST(Uint8ClampedArrayFromScript) { 375 TEST(Uint8ClampedArrayFromScript) {
376 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); 376 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray");
377 } 377 }
378 378
379
380 TEST(DataViewFromScript) {
381 TestTypedArrayFromScript<v8::Object>("DataView");
382 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/fuzz-natives-part1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698