OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 6254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6265 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); | 6265 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); |
6266 } | 6266 } |
6267 | 6267 |
6268 | 6268 |
6269 struct FlagAndPersistent { | 6269 struct FlagAndPersistent { |
6270 bool flag; | 6270 bool flag; |
6271 v8::Persistent<v8::Object> handle; | 6271 v8::Persistent<v8::Object> handle; |
6272 }; | 6272 }; |
6273 | 6273 |
6274 | 6274 |
6275 static void SetFlag(const v8::PhantomCallbackData<FlagAndPersistent>& data) { | 6275 static void SetFlag(const v8::WeakCallbackInfo<FlagAndPersistent>& data) { |
6276 data.GetParameter()->flag = true; | 6276 data.GetParameter()->flag = true; |
6277 } | 6277 } |
6278 | 6278 |
6279 | 6279 |
6280 static void IndependentWeakHandle(bool global_gc, bool interlinked) { | 6280 static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
6281 v8::Isolate* iso = CcTest::isolate(); | 6281 v8::Isolate* iso = CcTest::isolate(); |
6282 v8::HandleScope scope(iso); | 6282 v8::HandleScope scope(iso); |
6283 v8::Handle<Context> context = Context::New(iso); | 6283 v8::Handle<Context> context = Context::New(iso); |
6284 Context::Scope context_scope(context); | 6284 Context::Scope context_scope(context); |
6285 | 6285 |
(...skipping 18 matching lines...) Expand all Loading... |
6304 } | 6304 } |
6305 // We are relying on this creating a big flag array and reserving the space | 6305 // We are relying on this creating a big flag array and reserving the space |
6306 // up front. | 6306 // up front. |
6307 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); | 6307 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); |
6308 a->Set(v8_str("y"), big_array); | 6308 a->Set(v8_str("y"), big_array); |
6309 big_heap_size = CcTest::heap()->SizeOfObjects(); | 6309 big_heap_size = CcTest::heap()->SizeOfObjects(); |
6310 } | 6310 } |
6311 | 6311 |
6312 object_a.flag = false; | 6312 object_a.flag = false; |
6313 object_b.flag = false; | 6313 object_b.flag = false; |
6314 object_a.handle.SetPhantom(&object_a, &SetFlag); | 6314 object_a.handle.SetWeak(&object_a, &SetFlag, |
6315 object_b.handle.SetPhantom(&object_b, &SetFlag); | 6315 v8::WeakCallbackType::kParameter); |
| 6316 object_b.handle.SetWeak(&object_b, &SetFlag, |
| 6317 v8::WeakCallbackType::kParameter); |
6316 CHECK(!object_b.handle.IsIndependent()); | 6318 CHECK(!object_b.handle.IsIndependent()); |
6317 object_a.handle.MarkIndependent(); | 6319 object_a.handle.MarkIndependent(); |
6318 object_b.handle.MarkIndependent(); | 6320 object_b.handle.MarkIndependent(); |
6319 CHECK(object_b.handle.IsIndependent()); | 6321 CHECK(object_b.handle.IsIndependent()); |
6320 if (global_gc) { | 6322 if (global_gc) { |
6321 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 6323 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
6322 } else { | 6324 } else { |
6323 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6325 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
6324 } | 6326 } |
6325 // A single GC should be enough to reclaim the memory, since we are using | 6327 // A single GC should be enough to reclaim the memory, since we are using |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6360 int y() { return y_; } | 6362 int y() { return y_; } |
6361 void set_y(int y) { y_ = y; } | 6363 void set_y(int y) { y_ = y; } |
6362 | 6364 |
6363 private: | 6365 private: |
6364 int y_; | 6366 int y_; |
6365 int x_; | 6367 int x_; |
6366 }; | 6368 }; |
6367 | 6369 |
6368 | 6370 |
6369 void CheckInternalFields( | 6371 void CheckInternalFields( |
6370 const v8::PhantomCallbackData<v8::Persistent<v8::Object>>& data) { | 6372 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { |
6371 v8::Persistent<v8::Object>* handle = data.GetParameter(); | 6373 v8::Persistent<v8::Object>* handle = data.GetParameter(); |
6372 handle->Reset(); | 6374 handle->Reset(); |
6373 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField1()); | 6375 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField1()); |
6374 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField2()); | 6376 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField2()); |
6375 CHECK_EQ(42, t1->x()); | 6377 CHECK_EQ(42, t1->x()); |
6376 CHECK_EQ(103, t2->x()); | 6378 CHECK_EQ(103, t2->x()); |
6377 t1->set_x(1729); | 6379 t1->set_x(1729); |
6378 t2->set_x(33550336); | 6380 t2->set_x(33550336); |
6379 } | 6381 } |
6380 | 6382 |
(...skipping 19 matching lines...) Expand all Loading... |
6400 | 6402 |
6401 obj->SetAlignedPointerInInternalField(0, t1); | 6403 obj->SetAlignedPointerInInternalField(0, t1); |
6402 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); | 6404 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); |
6403 CHECK_EQ(42, t1->x()); | 6405 CHECK_EQ(42, t1->x()); |
6404 | 6406 |
6405 obj->SetAlignedPointerInInternalField(1, t2); | 6407 obj->SetAlignedPointerInInternalField(1, t2); |
6406 t2 = | 6408 t2 = |
6407 reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1)); | 6409 reinterpret_cast<Trivial2*>(obj->GetAlignedPointerFromInternalField(1)); |
6408 CHECK_EQ(103, t2->x()); | 6410 CHECK_EQ(103, t2->x()); |
6409 | 6411 |
6410 handle.SetPhantom<v8::Persistent<v8::Object>>(&handle, CheckInternalFields, | 6412 handle.SetWeak<v8::Persistent<v8::Object>>( |
6411 0, 1); | 6413 &handle, CheckInternalFields, v8::WeakCallbackType::kInternalFields); |
6412 if (!global_gc) { | 6414 if (!global_gc) { |
6413 handle.MarkIndependent(); | 6415 handle.MarkIndependent(); |
6414 } | 6416 } |
6415 } | 6417 } |
6416 if (global_gc) { | 6418 if (global_gc) { |
6417 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); | 6419 CcTest::heap()->CollectAllGarbage(TestHeap::Heap::kNoGCFlags); |
6418 } else { | 6420 } else { |
6419 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6421 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
6420 } | 6422 } |
6421 | 6423 |
(...skipping 15216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21638 } | 21640 } |
21639 { | 21641 { |
21640 v8::TryCatch try_catch; | 21642 v8::TryCatch try_catch; |
21641 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21643 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21642 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21644 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
21643 length).IsEmpty()); | 21645 length).IsEmpty()); |
21644 CHECK(try_catch.HasCaught()); | 21646 CHECK(try_catch.HasCaught()); |
21645 } | 21647 } |
21646 free(buffer); | 21648 free(buffer); |
21647 } | 21649 } |
OLD | NEW |