| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 for (Object* o = array_buffer->weak_first_array(); | 78 for (Object* o = array_buffer->weak_first_array(); |
| 79 !o->IsUndefined(); | 79 !o->IsUndefined(); |
| 80 o = JSTypedArray::cast(o)->weak_next()) { | 80 o = JSTypedArray::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 i::FLAG_stress_compaction = false; | |
| 89 v8::V8::Initialize(); | 88 v8::V8::Initialize(); |
| 90 LocalContext context; | 89 LocalContext context; |
| 91 Isolate* isolate = GetIsolateFrom(&context); | 90 Isolate* isolate = GetIsolateFrom(&context); |
| 92 | 91 |
| 93 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); | 92 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 94 { | 93 { |
| 95 v8::HandleScope s1(context->GetIsolate()); | 94 v8::HandleScope s1(context->GetIsolate()); |
| 96 v8::Handle<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(256); | 95 v8::Handle<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(256); |
| 97 { | 96 { |
| 98 v8::HandleScope s2(context->GetIsolate()); | 97 v8::HandleScope s2(context->GetIsolate()); |
| 99 v8::Handle<v8::ArrayBuffer> ab2 = v8::ArrayBuffer::New(128); | 98 v8::Handle<v8::ArrayBuffer> ab2 = v8::ArrayBuffer::New(128); |
| 100 | 99 |
| 101 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); | 100 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); |
| 102 Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2); | 101 Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2); |
| 103 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); | 102 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); |
| 104 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); | 103 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); |
| 105 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2)); | 104 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2)); |
| 106 } | 105 } |
| 107 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 106 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 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::kAbortIncrementalMarkingMask); |
| 118 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); | 117 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 119 } | 118 } |
| 120 | 119 |
| 121 | 120 |
| 122 TEST(WeakArrayBuffersFromScript) { | 121 TEST(WeakArrayBuffersFromScript) { |
| 123 v8::V8::Initialize(); | 122 v8::V8::Initialize(); |
| 124 LocalContext context; | 123 LocalContext context; |
| 125 Isolate* isolate = GetIsolateFrom(&context); | 124 Isolate* isolate = GetIsolateFrom(&context); |
| 126 | 125 |
| 127 for (int i = 1; i <= 3; i++) { | 126 for (int i = 1; i <= 3; i++) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 148 *v8::Utils::OpenHandle(*ab1))); | 147 *v8::Utils::OpenHandle(*ab1))); |
| 149 CHECK(HasArrayBufferInWeakList(isolate->heap(), | 148 CHECK(HasArrayBufferInWeakList(isolate->heap(), |
| 150 *v8::Utils::OpenHandle(*ab2))); | 149 *v8::Utils::OpenHandle(*ab2))); |
| 151 CHECK(HasArrayBufferInWeakList(isolate->heap(), | 150 CHECK(HasArrayBufferInWeakList(isolate->heap(), |
| 152 *v8::Utils::OpenHandle(*ab3))); | 151 *v8::Utils::OpenHandle(*ab3))); |
| 153 } | 152 } |
| 154 | 153 |
| 155 i::ScopedVector<char> source(1024); | 154 i::ScopedVector<char> source(1024); |
| 156 i::OS::SNPrintF(source, "ab%d = null;", i); | 155 i::OS::SNPrintF(source, "ab%d = null;", i); |
| 157 CompileRun(source.start()); | 156 CompileRun(source.start()); |
| 158 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 157 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 159 | 158 |
| 160 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); | 159 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap())); |
| 161 | 160 |
| 162 { | 161 { |
| 163 v8::HandleScope s2(context->GetIsolate()); | 162 v8::HandleScope s2(context->GetIsolate()); |
| 164 for (int j = 1; j <= 3; j++) { | 163 for (int j = 1; j <= 3; j++) { |
| 165 if (j == i) continue; | 164 if (j == i) continue; |
| 166 i::OS::SNPrintF(source, "ab%d", j); | 165 i::OS::SNPrintF(source, "ab%d", j); |
| 167 v8::Handle<v8::ArrayBuffer> ab = | 166 v8::Handle<v8::ArrayBuffer> ab = |
| 168 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun(source.start())); | 167 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun(source.start())); |
| 169 CHECK(HasArrayBufferInWeakList(isolate->heap(), | 168 CHECK(HasArrayBufferInWeakList(isolate->heap(), |
| 170 *v8::Utils::OpenHandle(*ab))); | 169 *v8::Utils::OpenHandle(*ab))); |
| 171 } | 170 } |
| 172 } | 171 } |
| 173 | 172 |
| 174 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); | 173 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); |
| 175 } | 174 } |
| 176 | 175 |
| 177 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 176 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 178 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); | 177 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 template <typename TypedArray> | 181 template <typename TypedArray> |
| 183 void TestTypedArrayFromApi() { | 182 void TestTypedArrayFromApi() { |
| 184 v8::V8::Initialize(); | 183 v8::V8::Initialize(); |
| 185 LocalContext context; | 184 LocalContext context; |
| 186 Isolate* isolate = GetIsolateFrom(&context); | 185 Isolate* isolate = GetIsolateFrom(&context); |
| 187 | 186 |
| 188 v8::HandleScope s1(context->GetIsolate()); | 187 v8::HandleScope s1(context->GetIsolate()); |
| 189 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048); | 188 v8::Handle<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(2048); |
| 190 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 189 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 191 { | 190 { |
| 192 v8::HandleScope s2(context->GetIsolate()); | 191 v8::HandleScope s2(context->GetIsolate()); |
| 193 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256); | 192 v8::Handle<TypedArray> ta1 = TypedArray::New(ab, 0, 256); |
| 194 { | 193 { |
| 195 v8::HandleScope s3(context->GetIsolate()); | 194 v8::HandleScope s3(context->GetIsolate()); |
| 196 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128); | 195 v8::Handle<TypedArray> ta2 = TypedArray::New(ab, 0, 128); |
| 197 | 196 |
| 198 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); | 197 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); |
| 199 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2); | 198 Handle<JSTypedArray> ita2 = v8::Utils::OpenHandle(*ta2); |
| 200 CHECK_EQ(2, CountTypedArrays(*iab)); | 199 CHECK_EQ(2, CountTypedArrays(*iab)); |
| 201 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); | 200 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); |
| 202 CHECK(HasTypedArrayInWeakList(*iab, *ita2)); | 201 CHECK(HasTypedArrayInWeakList(*iab, *ita2)); |
| 203 } | 202 } |
| 204 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 203 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 205 CHECK_EQ(1, CountTypedArrays(*iab)); | 204 CHECK_EQ(1, CountTypedArrays(*iab)); |
| 206 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); | 205 Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1); |
| 207 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); | 206 CHECK(HasTypedArrayInWeakList(*iab, *ita1)); |
| 208 } | 207 } |
| 209 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 208 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 210 | 209 |
| 211 CHECK_EQ(0, CountTypedArrays(*iab)); | 210 CHECK_EQ(0, CountTypedArrays(*iab)); |
| 212 } | 211 } |
| 213 | 212 |
| 214 | 213 |
| 215 TEST(Uint8ArrayFromApi) { | 214 TEST(Uint8ArrayFromApi) { |
| 216 TestTypedArrayFromApi<v8::Uint8Array>(); | 215 TestTypedArrayFromApi<v8::Uint8Array>(); |
| 217 } | 216 } |
| 218 | 217 |
| 219 | 218 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); | 290 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 292 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 291 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 293 CHECK_EQ(3, CountTypedArrays(*iab)); | 292 CHECK_EQ(3, CountTypedArrays(*iab)); |
| 294 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); | 293 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); |
| 295 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); | 294 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); |
| 296 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); | 295 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); |
| 297 } | 296 } |
| 298 | 297 |
| 299 i::OS::SNPrintF(source, "ta%d = null;", i); | 298 i::OS::SNPrintF(source, "ta%d = null;", i); |
| 300 CompileRun(source.start()); | 299 CompileRun(source.start()); |
| 301 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 300 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 302 | 301 |
| 303 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); | 302 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 304 | 303 |
| 305 { | 304 { |
| 306 v8::HandleScope s2(context->GetIsolate()); | 305 v8::HandleScope s2(context->GetIsolate()); |
| 307 v8::Handle<v8::ArrayBuffer> ab = | 306 v8::Handle<v8::ArrayBuffer> ab = |
| 308 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 307 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 309 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 308 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 310 CHECK_EQ(2, CountTypedArrays(*iab)); | 309 CHECK_EQ(2, CountTypedArrays(*iab)); |
| 311 for (int j = 1; j <= 3; j++) { | 310 for (int j = 1; j <= 3; j++) { |
| 312 if (j == i) continue; | 311 if (j == i) continue; |
| 313 i::OS::SNPrintF(source, "ta%d", j); | 312 i::OS::SNPrintF(source, "ta%d", j); |
| 314 v8::Handle<TypedArray> ta = | 313 v8::Handle<TypedArray> ta = |
| 315 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); | 314 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); |
| 316 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); | 315 CHECK(HasTypedArrayInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); |
| 317 } | 316 } |
| 318 } | 317 } |
| 319 | 318 |
| 320 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); | 319 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); |
| 321 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 320 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 322 | 321 |
| 323 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); | 322 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 324 | 323 |
| 325 { | 324 { |
| 326 v8::HandleScope s3(context->GetIsolate()); | 325 v8::HandleScope s3(context->GetIsolate()); |
| 327 v8::Handle<v8::ArrayBuffer> ab = | 326 v8::Handle<v8::ArrayBuffer> ab = |
| 328 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 327 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 329 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 328 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 330 CHECK_EQ(0, CountTypedArrays(*iab)); | 329 CHECK_EQ(0, CountTypedArrays(*iab)); |
| 331 } | 330 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 369 |
| 371 TEST(Float64ArrayFromScript) { | 370 TEST(Float64ArrayFromScript) { |
| 372 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); | 371 TestTypedArrayFromScript<v8::Float64Array>("Float64Array"); |
| 373 } | 372 } |
| 374 | 373 |
| 375 | 374 |
| 376 TEST(Uint8ClampedArrayFromScript) { | 375 TEST(Uint8ClampedArrayFromScript) { |
| 377 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); | 376 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); |
| 378 } | 377 } |
| 379 | 378 |
| OLD | NEW |