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 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 if (obj->IsGlobalObject()) count++; | 1654 if (obj->IsGlobalObject()) count++; |
1655 } | 1655 } |
1656 return count; | 1656 return count; |
1657 } | 1657 } |
1658 | 1658 |
1659 | 1659 |
1660 // Test that we don't embed maps from foreign contexts into | 1660 // Test that we don't embed maps from foreign contexts into |
1661 // optimized code. | 1661 // optimized code. |
1662 TEST(LeakNativeContextViaMap) { | 1662 TEST(LeakNativeContextViaMap) { |
1663 i::FLAG_allow_natives_syntax = true; | 1663 i::FLAG_allow_natives_syntax = true; |
1664 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1664 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1665 v8::HandleScope outer_scope(isolate); | 1665 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); |
1666 v8::Persistent<v8::Context> ctx1; | 1666 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); |
1667 v8::Persistent<v8::Context> ctx2; | |
1668 { | |
1669 v8::HandleScope scope(isolate); | |
1670 ctx1.Reset(isolate, v8::Context::New(isolate)); | |
1671 ctx2.Reset(isolate, v8::Context::New(isolate)); | |
1672 } | |
1673 ctx1->Enter(); | 1667 ctx1->Enter(); |
1674 | 1668 |
1675 HEAP->CollectAllAvailableGarbage(); | 1669 HEAP->CollectAllAvailableGarbage(); |
1676 CHECK_EQ(4, NumberOfGlobalObjects()); | 1670 CHECK_EQ(4, NumberOfGlobalObjects()); |
1677 | 1671 |
1678 { | 1672 { |
1679 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); | 1673 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); |
1680 CompileRun("var v = {x: 42}"); | 1674 CompileRun("var v = {x: 42}"); |
1681 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); | 1675 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); |
1682 ctx2->Enter(); | 1676 ctx2->Enter(); |
(...skipping 15 matching lines...) Expand all Loading... |
1698 ctx2.Dispose(ctx2->GetIsolate()); | 1692 ctx2.Dispose(ctx2->GetIsolate()); |
1699 HEAP->CollectAllAvailableGarbage(); | 1693 HEAP->CollectAllAvailableGarbage(); |
1700 CHECK_EQ(0, NumberOfGlobalObjects()); | 1694 CHECK_EQ(0, NumberOfGlobalObjects()); |
1701 } | 1695 } |
1702 | 1696 |
1703 | 1697 |
1704 // Test that we don't embed functions from foreign contexts into | 1698 // Test that we don't embed functions from foreign contexts into |
1705 // optimized code. | 1699 // optimized code. |
1706 TEST(LeakNativeContextViaFunction) { | 1700 TEST(LeakNativeContextViaFunction) { |
1707 i::FLAG_allow_natives_syntax = true; | 1701 i::FLAG_allow_natives_syntax = true; |
1708 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1702 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1709 v8::HandleScope outer_scope(isolate); | 1703 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); |
1710 v8::Persistent<v8::Context> ctx1; | 1704 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); |
1711 v8::Persistent<v8::Context> ctx2; | |
1712 { | |
1713 v8::HandleScope scope(isolate); | |
1714 ctx1.Reset(isolate, v8::Context::New(isolate)); | |
1715 ctx2.Reset(isolate, v8::Context::New(isolate)); | |
1716 } | |
1717 ctx1->Enter(); | 1705 ctx1->Enter(); |
1718 | 1706 |
1719 HEAP->CollectAllAvailableGarbage(); | 1707 HEAP->CollectAllAvailableGarbage(); |
1720 CHECK_EQ(4, NumberOfGlobalObjects()); | 1708 CHECK_EQ(4, NumberOfGlobalObjects()); |
1721 | 1709 |
1722 { | 1710 { |
1723 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); | 1711 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); |
1724 CompileRun("var v = function() { return 42; }"); | 1712 CompileRun("var v = function() { return 42; }"); |
1725 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); | 1713 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); |
1726 ctx2->Enter(); | 1714 ctx2->Enter(); |
(...skipping 13 matching lines...) Expand all Loading... |
1740 HEAP->CollectAllAvailableGarbage(); | 1728 HEAP->CollectAllAvailableGarbage(); |
1741 CHECK_EQ(2, NumberOfGlobalObjects()); | 1729 CHECK_EQ(2, NumberOfGlobalObjects()); |
1742 ctx2.Dispose(ctx2->GetIsolate()); | 1730 ctx2.Dispose(ctx2->GetIsolate()); |
1743 HEAP->CollectAllAvailableGarbage(); | 1731 HEAP->CollectAllAvailableGarbage(); |
1744 CHECK_EQ(0, NumberOfGlobalObjects()); | 1732 CHECK_EQ(0, NumberOfGlobalObjects()); |
1745 } | 1733 } |
1746 | 1734 |
1747 | 1735 |
1748 TEST(LeakNativeContextViaMapKeyed) { | 1736 TEST(LeakNativeContextViaMapKeyed) { |
1749 i::FLAG_allow_natives_syntax = true; | 1737 i::FLAG_allow_natives_syntax = true; |
1750 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1738 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1751 v8::HandleScope outer_scope(isolate); | 1739 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); |
1752 v8::Persistent<v8::Context> ctx1; | 1740 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); |
1753 v8::Persistent<v8::Context> ctx2; | |
1754 { | |
1755 v8::HandleScope scope(isolate); | |
1756 ctx1.Reset(isolate, v8::Context::New(isolate)); | |
1757 ctx2.Reset(isolate, v8::Context::New(isolate)); | |
1758 } | |
1759 ctx1->Enter(); | 1741 ctx1->Enter(); |
1760 | 1742 |
1761 HEAP->CollectAllAvailableGarbage(); | 1743 HEAP->CollectAllAvailableGarbage(); |
1762 CHECK_EQ(4, NumberOfGlobalObjects()); | 1744 CHECK_EQ(4, NumberOfGlobalObjects()); |
1763 | 1745 |
1764 { | 1746 { |
1765 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); | 1747 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); |
1766 CompileRun("var v = [42, 43]"); | 1748 CompileRun("var v = [42, 43]"); |
1767 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); | 1749 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); |
1768 ctx2->Enter(); | 1750 ctx2->Enter(); |
(...skipping 13 matching lines...) Expand all Loading... |
1782 HEAP->CollectAllAvailableGarbage(); | 1764 HEAP->CollectAllAvailableGarbage(); |
1783 CHECK_EQ(2, NumberOfGlobalObjects()); | 1765 CHECK_EQ(2, NumberOfGlobalObjects()); |
1784 ctx2.Dispose(ctx2->GetIsolate()); | 1766 ctx2.Dispose(ctx2->GetIsolate()); |
1785 HEAP->CollectAllAvailableGarbage(); | 1767 HEAP->CollectAllAvailableGarbage(); |
1786 CHECK_EQ(0, NumberOfGlobalObjects()); | 1768 CHECK_EQ(0, NumberOfGlobalObjects()); |
1787 } | 1769 } |
1788 | 1770 |
1789 | 1771 |
1790 TEST(LeakNativeContextViaMapProto) { | 1772 TEST(LeakNativeContextViaMapProto) { |
1791 i::FLAG_allow_natives_syntax = true; | 1773 i::FLAG_allow_natives_syntax = true; |
1792 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 1774 v8::HandleScope outer_scope(v8::Isolate::GetCurrent()); |
1793 v8::HandleScope outer_scope(isolate); | 1775 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); |
1794 v8::Persistent<v8::Context> ctx1; | 1776 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); |
1795 v8::Persistent<v8::Context> ctx2; | |
1796 { | |
1797 v8::HandleScope scope(isolate); | |
1798 ctx1.Reset(isolate, v8::Context::New(isolate)); | |
1799 ctx2.Reset(isolate, v8::Context::New(isolate)); | |
1800 } | |
1801 ctx1->Enter(); | 1777 ctx1->Enter(); |
1802 | 1778 |
1803 HEAP->CollectAllAvailableGarbage(); | 1779 HEAP->CollectAllAvailableGarbage(); |
1804 CHECK_EQ(4, NumberOfGlobalObjects()); | 1780 CHECK_EQ(4, NumberOfGlobalObjects()); |
1805 | 1781 |
1806 { | 1782 { |
1807 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); | 1783 v8::HandleScope inner_scope(v8::Isolate::GetCurrent()); |
1808 CompileRun("var v = { y: 42}"); | 1784 CompileRun("var v = { y: 42}"); |
1809 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); | 1785 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v")); |
1810 ctx2->Enter(); | 1786 ctx2->Enter(); |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3089 } | 3065 } |
3090 // An entire block of handles has been filled. | 3066 // An entire block of handles has been filled. |
3091 // Next handle would require a new block. | 3067 // Next handle would require a new block. |
3092 ASSERT(data->next == data->limit); | 3068 ASSERT(data->next == data->limit); |
3093 | 3069 |
3094 DeferredHandleScope deferred(isolate); | 3070 DeferredHandleScope deferred(isolate); |
3095 DummyVisitor visitor; | 3071 DummyVisitor visitor; |
3096 isolate->handle_scope_implementer()->Iterate(&visitor); | 3072 isolate->handle_scope_implementer()->Iterate(&visitor); |
3097 deferred.Detach(); | 3073 deferred.Detach(); |
3098 } | 3074 } |
OLD | NEW |