OLD | NEW |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 for (Object* o = array_buffer->weak_first_view(); | 67 for (Object* o = array_buffer->weak_first_view(); |
68 !o->IsUndefined(); | 68 !o->IsUndefined(); |
69 o = JSArrayBufferView::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 HasViewInWeakList(JSArrayBuffer* array_buffer, | 76 static bool HasViewInWeakList(JSArrayBuffer* array_buffer, |
77 JSObject* ta) { | 77 JSArrayBufferView* ta) { |
78 for (Object* o = array_buffer->weak_first_view(); | 78 for (Object* o = array_buffer->weak_first_view(); |
79 !o->IsUndefined(); | 79 !o->IsUndefined(); |
80 o = JSArrayBufferView::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) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); | 173 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); |
174 } | 174 } |
175 | 175 |
176 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 176 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
177 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); | 177 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 template <typename TypedArray> | 181 template <typename View> |
182 void TestTypedArrayFromApi() { | 182 void TestViewFromApi() { |
183 v8::V8::Initialize(); | 183 v8::V8::Initialize(); |
184 LocalContext context; | 184 LocalContext context; |
185 Isolate* isolate = GetIsolateFrom(&context); | 185 Isolate* isolate = GetIsolateFrom(&context); |
186 | 186 |
187 v8::HandleScope s1(context->GetIsolate()); | 187 v8::HandleScope s1(context->GetIsolate()); |
188 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048); | 188 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048); |
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<View> ta1 = View::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<View> ta2 = View::New(ab, 0, 128); |
196 | 196 |
197 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); | 197 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
198 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2); | 198 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); |
199 CHECK_EQ(2, CountViews(*iab)); | 199 CHECK_EQ(2, CountViews(*iab)); |
200 CHECK(HasViewInWeakList(*iab, *ita1)); | 200 CHECK(HasViewInWeakList(*iab, *ita1)); |
201 CHECK(HasViewInWeakList(*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, CountViews(*iab)); | 204 CHECK_EQ(1, CountViews(*iab)); |
205 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); | 205 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
206 CHECK(HasViewInWeakList(*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, CountViews(*iab)); | 210 CHECK_EQ(0, CountViews(*iab)); |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 TEST(Uint8ArrayFromApi) { | 214 TEST(Uint8ArrayFromApi) { |
215 TestTypedArrayFromApi<v8::Uint8Array>(); | 215 TestViewFromApi<v8::Uint8Array>(); |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 TEST(Int8ArrayFromApi) { | 219 TEST(Int8ArrayFromApi) { |
220 TestTypedArrayFromApi<v8::Int8Array>(); | 220 TestViewFromApi<v8::Int8Array>(); |
221 } | 221 } |
222 | 222 |
223 | 223 |
224 TEST(Uint16ArrayFromApi) { | 224 TEST(Uint16ArrayFromApi) { |
225 TestTypedArrayFromApi<v8::Uint16Array>(); | 225 TestViewFromApi<v8::Uint16Array>(); |
226 } | 226 } |
227 | 227 |
228 | 228 |
229 TEST(Int16ArrayFromApi) { | 229 TEST(Int16ArrayFromApi) { |
230 TestTypedArrayFromApi<v8::Int16Array>(); | 230 TestViewFromApi<v8::Int16Array>(); |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 TEST(Uint32ArrayFromApi) { | 234 TEST(Uint32ArrayFromApi) { |
235 TestTypedArrayFromApi<v8::Uint32Array>(); | 235 TestViewFromApi<v8::Uint32Array>(); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 TEST(Int32ArrayFromApi) { | 239 TEST(Int32ArrayFromApi) { |
240 TestTypedArrayFromApi<v8::Int32Array>(); | 240 TestViewFromApi<v8::Int32Array>(); |
241 } | 241 } |
242 | 242 |
243 | 243 |
244 TEST(Float32ArrayFromApi) { | 244 TEST(Float32ArrayFromApi) { |
245 TestTypedArrayFromApi<v8::Float32Array>(); | 245 TestViewFromApi<v8::Float32Array>(); |
246 } | 246 } |
247 | 247 |
248 | 248 |
249 TEST(Float64ArrayFromApi) { | 249 TEST(Float64ArrayFromApi) { |
250 TestTypedArrayFromApi<v8::Float64Array>(); | 250 TestViewFromApi<v8::Float64Array>(); |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 TEST(Uint8ClampedArrayFromApi) { | 254 TEST(Uint8ClampedArrayFromApi) { |
255 TestTypedArrayFromApi<v8::Uint8ClampedArray>(); | 255 TestViewFromApi<v8::Uint8ClampedArray>(); |
| 256 } |
| 257 |
| 258 |
| 259 TEST(DataViewFromApi) { |
| 260 TestViewFromApi<v8::DataView>(); |
256 } | 261 } |
257 | 262 |
258 template <typename TypedArray> | 263 template <typename TypedArray> |
259 static void TestTypedArrayFromScript(const char* constructor) { | 264 static void TestTypedArrayFromScript(const char* constructor) { |
260 v8::V8::Initialize(); | 265 v8::V8::Initialize(); |
261 LocalContext context; | 266 LocalContext context; |
262 Isolate* isolate = GetIsolateFrom(&context); | 267 Isolate* isolate = GetIsolateFrom(&context); |
263 v8::HandleScope scope(context->GetIsolate()); | 268 v8::HandleScope scope(context->GetIsolate()); |
264 CompileRun("var ab = new ArrayBuffer(2048);"); | 269 CompileRun("var ab = new ArrayBuffer(2048);"); |
265 for (int i = 1; i <= 3; i++) { | 270 for (int i = 1; i <= 3; i++) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); | 376 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); |
372 } | 377 } |
373 | 378 |
374 | 379 |
375 TEST(Uint8ClampedArrayFromScript) { | 380 TEST(Uint8ClampedArrayFromScript) { |
376 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); | 381 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); |
377 } | 382 } |
378 | 383 |
379 | 384 |
380 TEST(DataViewFromScript) { | 385 TEST(DataViewFromScript) { |
381 TestTypedArrayFromScript<v8::Object>("DataView"); | 386 TestTypedArrayFromScript<v8::DataView>("DataView"); |
382 } | 387 } |
OLD | NEW |