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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 CompileRun("var obj = {};"); | 606 CompileRun("var obj = {};"); |
607 Handle<Value> instance = CompileRun("obj"); | 607 Handle<Value> instance = CompileRun("obj"); |
608 { | 608 { |
609 LocalContext context2(CcTest::isolate()); | 609 LocalContext context2(CcTest::isolate()); |
610 context2->SetSecurityToken(foo); | 610 context2->SetSecurityToken(foo); |
611 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), | 611 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), |
612 instance); | 612 instance); |
613 CHECK(CompileRun("Object.getNotifier(obj)")->IsObject()); | 613 CHECK(CompileRun("Object.getNotifier(obj)")->IsObject()); |
614 } | 614 } |
615 } | 615 } |
| 616 |
| 617 |
| 618 static int GetGlobalObjectsCount() { |
| 619 CcTest::heap()->EnsureHeapIsIterable(); |
| 620 int count = 0; |
| 621 i::HeapIterator it(CcTest::heap()); |
| 622 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) |
| 623 if (object->IsJSGlobalObject()) count++; |
| 624 return count; |
| 625 } |
| 626 |
| 627 |
| 628 static void CheckSurvivingGlobalObjectsCount(int expected) { |
| 629 // We need to collect all garbage twice to be sure that everything |
| 630 // has been collected. This is because inline caches are cleared in |
| 631 // the first garbage collection but some of the maps have already |
| 632 // been marked at that point. Therefore some of the maps are not |
| 633 // collected until the second garbage collection. |
| 634 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 635 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); |
| 636 int count = GetGlobalObjectsCount(); |
| 637 #ifdef DEBUG |
| 638 if (count != expected) CcTest::heap()->TracePathToGlobal(); |
| 639 #endif |
| 640 CHECK_EQ(expected, count); |
| 641 } |
| 642 |
| 643 |
| 644 TEST(DontLeakContextOnObserve) { |
| 645 HandleScope scope(CcTest::isolate()); |
| 646 Handle<Value> foo = String::NewFromUtf8(CcTest::isolate(), "foo"); |
| 647 LocalContext context(CcTest::isolate()); |
| 648 context->SetSecurityToken(foo); |
| 649 CompileRun("var obj = {};"); |
| 650 Handle<Value> object = CompileRun("obj"); |
| 651 { |
| 652 HandleScope scope(CcTest::isolate()); |
| 653 LocalContext context2(CcTest::isolate()); |
| 654 context2->SetSecurityToken(foo); |
| 655 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), |
| 656 object); |
| 657 CompileRun("function observer() {};" |
| 658 "Object.observe(obj, observer, ['foo', 'bar', 'baz']);" |
| 659 "Object.unobserve(obj, observer);"); |
| 660 } |
| 661 |
| 662 v8::V8::ContextDisposedNotification(); |
| 663 CheckSurvivingGlobalObjectsCount(1); |
| 664 } |
| 665 |
| 666 |
| 667 TEST(DontLeakContextOnGetNotifier) { |
| 668 HandleScope scope(CcTest::isolate()); |
| 669 Handle<Value> foo = String::NewFromUtf8(CcTest::isolate(), "foo"); |
| 670 LocalContext context(CcTest::isolate()); |
| 671 context->SetSecurityToken(foo); |
| 672 CompileRun("var obj = {};"); |
| 673 Handle<Value> object = CompileRun("obj"); |
| 674 { |
| 675 HandleScope scope(CcTest::isolate()); |
| 676 LocalContext context2(CcTest::isolate()); |
| 677 context2->SetSecurityToken(foo); |
| 678 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), |
| 679 object); |
| 680 CompileRun("Object.getNotifier(obj);"); |
| 681 } |
| 682 |
| 683 v8::V8::ContextDisposedNotification(); |
| 684 CheckSurvivingGlobalObjectsCount(1); |
| 685 } |
| 686 |
| 687 |
| 688 TEST(DontLeakContextOnNotifierPerformChange) { |
| 689 HandleScope scope(CcTest::isolate()); |
| 690 Handle<Value> foo = String::NewFromUtf8(CcTest::isolate(), "foo"); |
| 691 LocalContext context(CcTest::isolate()); |
| 692 context->SetSecurityToken(foo); |
| 693 CompileRun("var obj = {};"); |
| 694 Handle<Value> object = CompileRun("obj"); |
| 695 { |
| 696 HandleScope scope(CcTest::isolate()); |
| 697 LocalContext context2(CcTest::isolate()); |
| 698 context2->SetSecurityToken(foo); |
| 699 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), |
| 700 object); |
| 701 CompileRun("var n = Object.getNotifier(obj);" |
| 702 "n.performChange('foo', function() {});"); |
| 703 } |
| 704 |
| 705 v8::V8::ContextDisposedNotification(); |
| 706 CheckSurvivingGlobalObjectsCount(1); |
| 707 } |
OLD | NEW |