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