OLD | NEW |
---|---|
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 static const bool kLogThreading = true; | 43 static const bool kLogThreading = true; |
44 | 44 |
45 static bool IsNaN(double x) { | 45 static bool IsNaN(double x) { |
46 #ifdef WIN32 | 46 #ifdef WIN32 |
47 return _isnan(x); | 47 return _isnan(x); |
48 #else | 48 #else |
49 return isnan(x); | 49 return isnan(x); |
50 #endif | 50 #endif |
51 } | 51 } |
52 | 52 |
53 using ::v8::AccessorInfo; | |
54 using ::v8::Context; | |
55 using ::v8::Extension; | |
56 using ::v8::Function; | |
57 using ::v8::HandleScope; | |
58 using ::v8::Local; | |
59 using ::v8::Object; | |
53 using ::v8::ObjectTemplate; | 60 using ::v8::ObjectTemplate; |
61 using ::v8::Persistent; | |
62 using ::v8::Script; | |
63 using ::v8::String; | |
54 using ::v8::Value; | 64 using ::v8::Value; |
55 using ::v8::Context; | 65 using ::v8::V8; |
56 using ::v8::Local; | |
57 using ::v8::String; | |
58 using ::v8::Script; | |
59 using ::v8::Function; | |
60 using ::v8::AccessorInfo; | |
61 using ::v8::Extension; | |
62 | 66 |
63 namespace i = ::i; | 67 namespace i = ::i; |
64 | 68 |
65 | 69 |
66 static void ExpectString(const char* code, const char* expected) { | 70 static void ExpectString(const char* code, const char* expected) { |
67 Local<Value> result = CompileRun(code); | 71 Local<Value> result = CompileRun(code); |
68 CHECK(result->IsString()); | 72 CHECK(result->IsString()); |
69 String::AsciiValue ascii(result); | 73 String::AsciiValue ascii(result); |
70 CHECK_EQ(expected, *ascii); | 74 CHECK_EQ(expected, *ascii); |
71 } | 75 } |
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1782 { | 1786 { |
1783 v8::HandleScope scope; | 1787 v8::HandleScope scope; |
1784 Local<String> str = v8_str("str"); | 1788 Local<String> str = v8_str("str"); |
1785 global = v8::Persistent<String>::New(str); | 1789 global = v8::Persistent<String>::New(str); |
1786 } | 1790 } |
1787 CHECK_EQ(global->Length(), 3); | 1791 CHECK_EQ(global->Length(), 3); |
1788 global.Dispose(); | 1792 global.Dispose(); |
1789 } | 1793 } |
1790 | 1794 |
1791 | 1795 |
1796 static int NumberOfWeakCalls = 0; | |
1797 static void WeakPointerCallback(Persistent<Value> handle, void* id) { | |
1798 CHECK_EQ(reinterpret_cast<void*>(1234), id); | |
1799 NumberOfWeakCalls++; | |
1800 handle.Dispose(); | |
1801 } | |
1802 | |
1803 THREADED_TEST(ApiObjectGroups) { | |
1804 HandleScope scope; | |
1805 LocalContext env; | |
1806 | |
1807 NumberOfWeakCalls = 0; | |
1808 | |
1809 Persistent<Object> g1s1; | |
1810 Persistent<Object> g1s2; | |
1811 Persistent<Object> g1c1; | |
1812 Persistent<Object> g2s1; | |
1813 Persistent<Object> g2s2; | |
1814 Persistent<Object> g2c1; | |
1815 | |
1816 { | |
1817 HandleScope scope; | |
1818 g1s1 = Persistent<Object>::New(Object::New()); | |
1819 g1s2 = Persistent<Object>::New(Object::New()); | |
1820 g1c1 = Persistent<Object>::New(Object::New()); | |
1821 g1s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1822 g1s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1823 g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1824 | |
1825 g2s1 = Persistent<Object>::New(Object::New()); | |
1826 g2s2 = Persistent<Object>::New(Object::New()); | |
1827 g2c1 = Persistent<Object>::New(Object::New()); | |
1828 g2s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1829 g2s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1830 g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1831 } | |
1832 | |
1833 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root. | |
1834 | |
1835 // Connect group 1 and 2, make a cycle. | |
1836 CHECK(g1s2->Set(0, g2s2)); | |
1837 CHECK(g2s1->Set(0, g1s1)); | |
1838 | |
1839 { | |
1840 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
1841 Persistent<Value> g1_children[] = { g1c1 }; | |
1842 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
1843 Persistent<Value> g2_children[] = { g2c1 }; | |
1844 V8::AddObjectGroup(g1_objects, 2); | |
1845 V8::AddImplicitRefGroup(g1s1, g1_children, 1); | |
1846 V8::AddObjectGroup(g2_objects, 2); | |
1847 V8::AddImplicitRefGroup(g2s2, g2_children, 1); | |
Vitaly Repeshko
2011/03/15 18:45:35
It would be interesting to test longer chains of i
| |
1848 } | |
1849 // Do a full GC | |
1850 i::Heap::CollectGarbage(i::OLD_POINTER_SPACE); | |
1851 | |
1852 // All object should be alive. | |
1853 CHECK_EQ(0, NumberOfWeakCalls); | |
1854 | |
1855 // Weaken the root. | |
1856 root.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1857 // But make children strong roots---all the objects (except for children) | |
1858 // should be collectable now. | |
1859 g1c1.ClearWeak(); | |
1860 g2c1.ClearWeak(); | |
1861 | |
1862 // Groups are deleted, rebuild groups. | |
1863 { | |
1864 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
1865 Persistent<Value> g1_children[] = { g1c1 }; | |
1866 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
1867 Persistent<Value> g2_children[] = { g2c1 }; | |
1868 V8::AddObjectGroup(g1_objects, 2); | |
1869 V8::AddImplicitRefGroup(g1s1, g1_children, 1); | |
1870 V8::AddObjectGroup(g2_objects, 2); | |
1871 V8::AddImplicitRefGroup(g2s2, g2_children, 1); | |
1872 } | |
1873 | |
1874 i::Heap::CollectGarbage(i::OLD_POINTER_SPACE); | |
1875 | |
1876 // All objects should be gone. 5 global handles in total. | |
1877 CHECK_EQ(5, NumberOfWeakCalls); | |
1878 | |
1879 // And now make children weak again and collect them. | |
1880 g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1881 g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback); | |
1882 | |
1883 i::Heap::CollectGarbage(i::OLD_POINTER_SPACE); | |
1884 CHECK_EQ(7, NumberOfWeakCalls); | |
1885 } | |
1886 | |
1887 | |
1792 THREADED_TEST(ScriptException) { | 1888 THREADED_TEST(ScriptException) { |
1793 v8::HandleScope scope; | 1889 v8::HandleScope scope; |
1794 LocalContext env; | 1890 LocalContext env; |
1795 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); | 1891 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); |
1796 v8::TryCatch try_catch; | 1892 v8::TryCatch try_catch; |
1797 Local<Value> result = script->Run(); | 1893 Local<Value> result = script->Run(); |
1798 CHECK(result.IsEmpty()); | 1894 CHECK(result.IsEmpty()); |
1799 CHECK(try_catch.HasCaught()); | 1895 CHECK(try_catch.HasCaught()); |
1800 String::AsciiValue exception_value(try_catch.Exception()); | 1896 String::AsciiValue exception_value(try_catch.Exception()); |
1801 CHECK_EQ(*exception_value, "panama!"); | 1897 CHECK_EQ(*exception_value, "panama!"); |
(...skipping 11126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12928 v8::Handle<v8::Function> define_property = | 13024 v8::Handle<v8::Function> define_property = |
12929 CompileRun("(function() {" | 13025 CompileRun("(function() {" |
12930 " Object.defineProperty(" | 13026 " Object.defineProperty(" |
12931 " this," | 13027 " this," |
12932 " 1," | 13028 " 1," |
12933 " { configurable: true, enumerable: true, value: 3 });" | 13029 " { configurable: true, enumerable: true, value: 3 });" |
12934 "})").As<Function>(); | 13030 "})").As<Function>(); |
12935 context->DetachGlobal(); | 13031 context->DetachGlobal(); |
12936 define_property->Call(proxy, 0, NULL); | 13032 define_property->Call(proxy, 0, NULL); |
12937 } | 13033 } |
OLD | NEW |