Chromium Code Reviews| 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("function observer() {};" | |
|
Toon Verwaest
2014/05/02 14:17:34
I guess you don't need the observer here.
rafaelw
2014/05/02 16:18:12
Done.
| |
| 681 "Object.getNotifier(obj);"); | |
| 682 } | |
| 683 | |
| 684 v8::V8::ContextDisposedNotification(); | |
| 685 CheckSurvivingGlobalObjectsCount(1); | |
| 686 } | |
| 687 | |
| 688 | |
| 689 TEST(DontLeakContextOnNotifierPerformChange) { | |
| 690 HandleScope scope(CcTest::isolate()); | |
| 691 Handle<Value> foo = String::NewFromUtf8(CcTest::isolate(), "foo"); | |
| 692 LocalContext context(CcTest::isolate()); | |
| 693 context->SetSecurityToken(foo); | |
| 694 CompileRun("var obj = {};"); | |
| 695 Handle<Value> object = CompileRun("obj"); | |
| 696 { | |
| 697 HandleScope scope(CcTest::isolate()); | |
| 698 LocalContext context2(CcTest::isolate()); | |
| 699 context2->SetSecurityToken(foo); | |
| 700 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), | |
| 701 object); | |
| 702 CompileRun("function observer() {};" | |
|
Toon Verwaest
2014/05/02 14:17:34
no observer needed here either
rafaelw
2014/05/02 16:18:12
Done.
| |
| 703 "var n = Object.getNotifier(obj);" | |
| 704 "n.performChange('foo', function() {});"); | |
| 705 } | |
| 706 | |
| 707 v8::V8::ContextDisposedNotification(); | |
| 708 CheckSurvivingGlobalObjectsCount(1); | |
| 709 } | |
| OLD | NEW |