| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 91 | 91 |
| 92 int start = CountArrayBuffersInWeakList(isolate->heap()); | 92 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 93 { | 93 { |
| 94 v8::HandleScope s1(context->GetIsolate()); | 94 v8::HandleScope s1(context->GetIsolate()); |
| 95 v8::Handle<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(256); | 95 v8::Handle<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(256); |
| 96 { | 96 { |
| 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()) - start); | 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::kAbortIncrementalMarkingMask); | 106 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 107 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 107 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 108 { | 108 { |
| 109 HandleScope scope2(isolate); | 109 HandleScope scope2(isolate); |
| 110 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); | 110 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); |
| 111 | 111 |
| 112 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); | 112 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 116 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 117 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start); | 117 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 TEST(WeakArrayBuffersFromScript) { | 121 TEST(WeakArrayBuffersFromScript) { |
| 122 v8::V8::Initialize(); | 122 v8::V8::Initialize(); |
| 123 LocalContext context; | 123 LocalContext context; |
| 124 Isolate* isolate = GetIsolateFrom(&context); | 124 Isolate* isolate = GetIsolateFrom(&context); |
| 125 int start = CountArrayBuffersInWeakList(isolate->heap()); | |
| 126 | 125 |
| 127 for (int i = 1; i <= 3; i++) { | 126 for (int i = 1; i <= 3; i++) { |
| 128 // Create 3 array buffers, make i-th of them garbage, | 127 // Create 3 array buffers, make i-th of them garbage, |
| 129 // validate correct state of array buffer weak list. | 128 // validate correct state of array buffer weak list. |
| 130 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start); | 129 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 131 { | 130 { |
| 132 v8::HandleScope scope(context->GetIsolate()); | 131 v8::HandleScope scope(context->GetIsolate()); |
| 133 | 132 |
| 134 { | 133 { |
| 135 v8::HandleScope s1(context->GetIsolate()); | 134 v8::HandleScope s1(context->GetIsolate()); |
| 136 CompileRun("var ab1 = new ArrayBuffer(256);" | 135 CompileRun("var ab1 = new ArrayBuffer(256);" |
| 137 "var ab2 = new ArrayBuffer(256);" | 136 "var ab2 = new ArrayBuffer(256);" |
| 138 "var ab3 = new ArrayBuffer(256);"); | 137 "var ab3 = new ArrayBuffer(256);"); |
| 139 v8::Handle<v8::ArrayBuffer> ab1 = | 138 v8::Handle<v8::ArrayBuffer> ab1 = |
| 140 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab1")); | 139 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab1")); |
| 141 v8::Handle<v8::ArrayBuffer> ab2 = | 140 v8::Handle<v8::ArrayBuffer> ab2 = |
| 142 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab2")); | 141 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab2")); |
| 143 v8::Handle<v8::ArrayBuffer> ab3 = | 142 v8::Handle<v8::ArrayBuffer> ab3 = |
| 144 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab3")); | 143 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab3")); |
| 145 | 144 |
| 146 CHECK_EQ(3, CountArrayBuffersInWeakList(isolate->heap()) - start); | 145 CHECK_EQ(3, CountArrayBuffersInWeakList(isolate->heap())); |
| 147 CHECK(HasArrayBufferInWeakList(isolate->heap(), | 146 CHECK(HasArrayBufferInWeakList(isolate->heap(), |
| 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::kAbortIncrementalMarkingMask); | 157 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 159 | 158 |
| 160 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()) - start); | 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::kAbortIncrementalMarkingMask); | 176 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 178 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start); | 177 CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap())); |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 template <typename View> | 181 template <typename View> |
| 183 void TestViewFromApi() { | 182 void TestViewFromApi() { |
| 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()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 TEST(DataViewFromApi) { | 259 TEST(DataViewFromApi) { |
| 261 TestViewFromApi<v8::DataView>(); | 260 TestViewFromApi<v8::DataView>(); |
| 262 } | 261 } |
| 263 | 262 |
| 264 template <typename TypedArray> | 263 template <typename TypedArray> |
| 265 static void TestTypedArrayFromScript(const char* constructor) { | 264 static void TestTypedArrayFromScript(const char* constructor) { |
| 266 v8::V8::Initialize(); | 265 v8::V8::Initialize(); |
| 267 LocalContext context; | 266 LocalContext context; |
| 268 Isolate* isolate = GetIsolateFrom(&context); | 267 Isolate* isolate = GetIsolateFrom(&context); |
| 269 v8::HandleScope scope(context->GetIsolate()); | 268 v8::HandleScope scope(context->GetIsolate()); |
| 270 int start = CountArrayBuffersInWeakList(isolate->heap()); | |
| 271 CompileRun("var ab = new ArrayBuffer(2048);"); | 269 CompileRun("var ab = new ArrayBuffer(2048);"); |
| 272 for (int i = 1; i <= 3; i++) { | 270 for (int i = 1; i <= 3; i++) { |
| 273 // Create 3 typed arrays, make i-th of them garbage, | 271 // Create 3 typed arrays, make i-th of them garbage, |
| 274 // validate correct state of typed array weak list. | 272 // validate correct state of typed array weak list. |
| 275 v8::HandleScope s0(context->GetIsolate()); | 273 v8::HandleScope s0(context->GetIsolate()); |
| 276 i::ScopedVector<char> source(2048); | 274 i::ScopedVector<char> source(2048); |
| 277 | 275 |
| 278 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 276 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 279 | 277 |
| 280 { | 278 { |
| 281 v8::HandleScope s1(context->GetIsolate()); | 279 v8::HandleScope s1(context->GetIsolate()); |
| 282 i::OS::SNPrintF(source, | 280 i::OS::SNPrintF(source, |
| 283 "var ta1 = new %s(ab);" | 281 "var ta1 = new %s(ab);" |
| 284 "var ta2 = new %s(ab);" | 282 "var ta2 = new %s(ab);" |
| 285 "var ta3 = new %s(ab)", | 283 "var ta3 = new %s(ab)", |
| 286 constructor, constructor, constructor); | 284 constructor, constructor, constructor); |
| 287 | 285 |
| 288 CompileRun(source.start()); | 286 CompileRun(source.start()); |
| 289 v8::Handle<v8::ArrayBuffer> ab = | 287 v8::Handle<v8::ArrayBuffer> ab = |
| 290 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 288 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 291 v8::Handle<TypedArray> ta1 = | 289 v8::Handle<TypedArray> ta1 = |
| 292 v8::Handle<TypedArray>::Cast(CompileRun("ta1")); | 290 v8::Handle<TypedArray>::Cast(CompileRun("ta1")); |
| 293 v8::Handle<TypedArray> ta2 = | 291 v8::Handle<TypedArray> ta2 = |
| 294 v8::Handle<TypedArray>::Cast(CompileRun("ta2")); | 292 v8::Handle<TypedArray>::Cast(CompileRun("ta2")); |
| 295 v8::Handle<TypedArray> ta3 = | 293 v8::Handle<TypedArray> ta3 = |
| 296 v8::Handle<TypedArray>::Cast(CompileRun("ta3")); | 294 v8::Handle<TypedArray>::Cast(CompileRun("ta3")); |
| 297 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 295 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 298 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 296 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 299 CHECK_EQ(3, CountViews(*iab)); | 297 CHECK_EQ(3, CountViews(*iab)); |
| 300 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); | 298 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1))); |
| 301 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); | 299 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2))); |
| 302 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); | 300 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3))); |
| 303 } | 301 } |
| 304 | 302 |
| 305 i::OS::SNPrintF(source, "ta%d = null;", i); | 303 i::OS::SNPrintF(source, "ta%d = null;", i); |
| 306 CompileRun(source.start()); | 304 CompileRun(source.start()); |
| 307 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 305 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 308 | 306 |
| 309 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 307 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 310 | 308 |
| 311 { | 309 { |
| 312 v8::HandleScope s2(context->GetIsolate()); | 310 v8::HandleScope s2(context->GetIsolate()); |
| 313 v8::Handle<v8::ArrayBuffer> ab = | 311 v8::Handle<v8::ArrayBuffer> ab = |
| 314 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 312 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 315 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 313 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 316 CHECK_EQ(2, CountViews(*iab)); | 314 CHECK_EQ(2, CountViews(*iab)); |
| 317 for (int j = 1; j <= 3; j++) { | 315 for (int j = 1; j <= 3; j++) { |
| 318 if (j == i) continue; | 316 if (j == i) continue; |
| 319 i::OS::SNPrintF(source, "ta%d", j); | 317 i::OS::SNPrintF(source, "ta%d", j); |
| 320 v8::Handle<TypedArray> ta = | 318 v8::Handle<TypedArray> ta = |
| 321 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); | 319 v8::Handle<TypedArray>::Cast(CompileRun(source.start())); |
| 322 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); | 320 CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta))); |
| 323 } | 321 } |
| 324 } | 322 } |
| 325 | 323 |
| 326 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); | 324 CompileRun("ta1 = null; ta2 = null; ta3 = null;"); |
| 327 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 325 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 328 | 326 |
| 329 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 327 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap())); |
| 330 | 328 |
| 331 { | 329 { |
| 332 v8::HandleScope s3(context->GetIsolate()); | 330 v8::HandleScope s3(context->GetIsolate()); |
| 333 v8::Handle<v8::ArrayBuffer> ab = | 331 v8::Handle<v8::ArrayBuffer> ab = |
| 334 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 332 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 335 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 333 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
| 336 CHECK_EQ(0, CountViews(*iab)); | 334 CHECK_EQ(0, CountViews(*iab)); |
| 337 } | 335 } |
| 338 } | 336 } |
| 339 } | 337 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 378 |
| 381 | 379 |
| 382 TEST(Uint8ClampedArrayFromScript) { | 380 TEST(Uint8ClampedArrayFromScript) { |
| 383 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); | 381 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); |
| 384 } | 382 } |
| 385 | 383 |
| 386 | 384 |
| 387 TEST(DataViewFromScript) { | 385 TEST(DataViewFromScript) { |
| 388 TestTypedArrayFromScript<v8::DataView>("DataView"); | 386 TestTypedArrayFromScript<v8::DataView>("DataView"); |
| 389 } | 387 } |
| OLD | NEW |