Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/cctest/test-api.cc

Issue 6711027: [Isolates] Merge 7201:7258 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 static const bool kLogThreading = true; 42 static const bool kLogThreading = true;
43 43
44 static bool IsNaN(double x) { 44 static bool IsNaN(double x) {
45 #ifdef WIN32 45 #ifdef WIN32
46 return _isnan(x); 46 return _isnan(x);
47 #else 47 #else
48 return isnan(x); 48 return isnan(x);
49 #endif 49 #endif
50 } 50 }
51 51
52 using ::v8::AccessorInfo;
53 using ::v8::Context;
54 using ::v8::Extension;
55 using ::v8::Function;
56 using ::v8::HandleScope;
57 using ::v8::Local;
58 using ::v8::Object;
52 using ::v8::ObjectTemplate; 59 using ::v8::ObjectTemplate;
60 using ::v8::Persistent;
61 using ::v8::Script;
62 using ::v8::String;
53 using ::v8::Value; 63 using ::v8::Value;
54 using ::v8::Context; 64 using ::v8::V8;
55 using ::v8::Local;
56 using ::v8::String;
57 using ::v8::Script;
58 using ::v8::Function;
59 using ::v8::AccessorInfo;
60 using ::v8::Extension;
61 65
62 namespace i = ::i; 66 namespace i = ::i;
63 67
64 68
65 static void ExpectString(const char* code, const char* expected) { 69 static void ExpectString(const char* code, const char* expected) {
66 Local<Value> result = CompileRun(code); 70 Local<Value> result = CompileRun(code);
67 CHECK(result->IsString()); 71 CHECK(result->IsString());
68 String::AsciiValue ascii(result); 72 String::AsciiValue ascii(result);
69 CHECK_EQ(expected, *ascii); 73 CHECK_EQ(expected, *ascii);
70 } 74 }
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 { 1785 {
1782 v8::HandleScope scope; 1786 v8::HandleScope scope;
1783 Local<String> str = v8_str("str"); 1787 Local<String> str = v8_str("str");
1784 global = v8::Persistent<String>::New(str); 1788 global = v8::Persistent<String>::New(str);
1785 } 1789 }
1786 CHECK_EQ(global->Length(), 3); 1790 CHECK_EQ(global->Length(), 3);
1787 global.Dispose(); 1791 global.Dispose();
1788 } 1792 }
1789 1793
1790 1794
1795 static int NumberOfWeakCalls = 0;
1796 static void WeakPointerCallback(Persistent<Value> handle, void* id) {
1797 CHECK_EQ(reinterpret_cast<void*>(1234), id);
1798 NumberOfWeakCalls++;
1799 handle.Dispose();
1800 }
1801
1802 THREADED_TEST(ApiObjectGroups) {
1803 HandleScope scope;
1804 LocalContext env;
1805
1806 NumberOfWeakCalls = 0;
1807
1808 Persistent<Object> g1s1;
1809 Persistent<Object> g1s2;
1810 Persistent<Object> g1c1;
1811 Persistent<Object> g2s1;
1812 Persistent<Object> g2s2;
1813 Persistent<Object> g2c1;
1814
1815 {
1816 HandleScope scope;
1817 g1s1 = Persistent<Object>::New(Object::New());
1818 g1s2 = Persistent<Object>::New(Object::New());
1819 g1c1 = Persistent<Object>::New(Object::New());
1820 g1s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1821 g1s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1822 g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1823
1824 g2s1 = Persistent<Object>::New(Object::New());
1825 g2s2 = Persistent<Object>::New(Object::New());
1826 g2c1 = Persistent<Object>::New(Object::New());
1827 g2s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1828 g2s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1829 g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1830 }
1831
1832 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root.
1833
1834 // Connect group 1 and 2, make a cycle.
1835 CHECK(g1s2->Set(0, g2s2));
1836 CHECK(g2s1->Set(0, g1s1));
1837
1838 {
1839 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
1840 Persistent<Value> g1_children[] = { g1c1 };
1841 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
1842 Persistent<Value> g2_children[] = { g2c1 };
1843 V8::AddObjectGroup(g1_objects, 2);
1844 V8::AddImplicitReferences(g1s1, g1_children, 1);
1845 V8::AddObjectGroup(g2_objects, 2);
1846 V8::AddImplicitReferences(g2s2, g2_children, 1);
1847 }
1848 // Do a full GC
1849 HEAP->CollectGarbage(i::OLD_POINTER_SPACE);
1850
1851 // All object should be alive.
1852 CHECK_EQ(0, NumberOfWeakCalls);
1853
1854 // Weaken the root.
1855 root.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1856 // But make children strong roots---all the objects (except for children)
1857 // should be collectable now.
1858 g1c1.ClearWeak();
1859 g2c1.ClearWeak();
1860
1861 // Groups are deleted, rebuild groups.
1862 {
1863 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
1864 Persistent<Value> g1_children[] = { g1c1 };
1865 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
1866 Persistent<Value> g2_children[] = { g2c1 };
1867 V8::AddObjectGroup(g1_objects, 2);
1868 V8::AddImplicitReferences(g1s1, g1_children, 1);
1869 V8::AddObjectGroup(g2_objects, 2);
1870 V8::AddImplicitReferences(g2s2, g2_children, 1);
1871 }
1872
1873 HEAP->CollectGarbage(i::OLD_POINTER_SPACE);
1874
1875 // All objects should be gone. 5 global handles in total.
1876 CHECK_EQ(5, NumberOfWeakCalls);
1877
1878 // And now make children weak again and collect them.
1879 g1c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1880 g2c1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1881
1882 HEAP->CollectGarbage(i::OLD_POINTER_SPACE);
1883 CHECK_EQ(7, NumberOfWeakCalls);
1884 }
1885
1886
1887 THREADED_TEST(ApiObjectGroupsCycle) {
1888 HandleScope scope;
1889 LocalContext env;
1890
1891 NumberOfWeakCalls = 0;
1892
1893 Persistent<Object> g1s1;
1894 Persistent<Object> g1s2;
1895 Persistent<Object> g2s1;
1896 Persistent<Object> g2s2;
1897 Persistent<Object> g3s1;
1898 Persistent<Object> g3s2;
1899
1900 {
1901 HandleScope scope;
1902 g1s1 = Persistent<Object>::New(Object::New());
1903 g1s2 = Persistent<Object>::New(Object::New());
1904 g1s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1905 g1s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1906
1907 g2s1 = Persistent<Object>::New(Object::New());
1908 g2s2 = Persistent<Object>::New(Object::New());
1909 g2s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1910 g2s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1911
1912 g3s1 = Persistent<Object>::New(Object::New());
1913 g3s2 = Persistent<Object>::New(Object::New());
1914 g3s1.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1915 g3s2.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1916 }
1917
1918 Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root.
1919
1920 // Connect groups. We're building the following cycle:
1921 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
1922 // groups.
1923 {
1924 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
1925 Persistent<Value> g1_children[] = { g2s1 };
1926 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
1927 Persistent<Value> g2_children[] = { g3s1 };
1928 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
1929 Persistent<Value> g3_children[] = { g1s1 };
1930 V8::AddObjectGroup(g1_objects, 2);
1931 V8::AddImplicitReferences(g1s1, g1_children, 1);
1932 V8::AddObjectGroup(g2_objects, 2);
1933 V8::AddImplicitReferences(g2s1, g2_children, 1);
1934 V8::AddObjectGroup(g3_objects, 2);
1935 V8::AddImplicitReferences(g3s1, g3_children, 1);
1936 }
1937 // Do a full GC
1938 HEAP->CollectGarbage(i::OLD_POINTER_SPACE);
1939
1940 // All object should be alive.
1941 CHECK_EQ(0, NumberOfWeakCalls);
1942
1943 // Weaken the root.
1944 root.MakeWeak(reinterpret_cast<void*>(1234), &WeakPointerCallback);
1945
1946 // Groups are deleted, rebuild groups.
1947 {
1948 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
1949 Persistent<Value> g1_children[] = { g2s1 };
1950 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
1951 Persistent<Value> g2_children[] = { g3s1 };
1952 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
1953 Persistent<Value> g3_children[] = { g1s1 };
1954 V8::AddObjectGroup(g1_objects, 2);
1955 V8::AddImplicitReferences(g1s1, g1_children, 1);
1956 V8::AddObjectGroup(g2_objects, 2);
1957 V8::AddImplicitReferences(g2s1, g2_children, 1);
1958 V8::AddObjectGroup(g3_objects, 2);
1959 V8::AddImplicitReferences(g3s1, g3_children, 1);
1960 }
1961
1962 HEAP->CollectGarbage(i::OLD_POINTER_SPACE);
1963
1964 // All objects should be gone. 7 global handles in total.
1965 CHECK_EQ(7, NumberOfWeakCalls);
1966 }
1967
1968
1791 THREADED_TEST(ScriptException) { 1969 THREADED_TEST(ScriptException) {
1792 v8::HandleScope scope; 1970 v8::HandleScope scope;
1793 LocalContext env; 1971 LocalContext env;
1794 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); 1972 Local<Script> script = Script::Compile(v8_str("throw 'panama!';"));
1795 v8::TryCatch try_catch; 1973 v8::TryCatch try_catch;
1796 Local<Value> result = script->Run(); 1974 Local<Value> result = script->Run();
1797 CHECK(result.IsEmpty()); 1975 CHECK(result.IsEmpty());
1798 CHECK(try_catch.HasCaught()); 1976 CHECK(try_catch.HasCaught());
1799 String::AsciiValue exception_value(try_catch.Exception()); 1977 String::AsciiValue exception_value(try_catch.Exception());
1800 CHECK_EQ(*exception_value, "panama!"); 1978 CHECK_EQ(*exception_value, "panama!");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 CHECK(!array->Has(0)); 2070 CHECK(!array->Has(0));
1893 CHECK(!array->Has(1)); 2071 CHECK(!array->Has(1));
1894 CHECK(array->Has(2)); 2072 CHECK(array->Has(2));
1895 CHECK_EQ(7, array->Get(2)->Int32Value()); 2073 CHECK_EQ(7, array->Get(2)->Int32Value());
1896 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); 2074 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run();
1897 Local<v8::Array> arr = obj.As<v8::Array>(); 2075 Local<v8::Array> arr = obj.As<v8::Array>();
1898 CHECK_EQ(3, arr->Length()); 2076 CHECK_EQ(3, arr->Length());
1899 CHECK_EQ(1, arr->Get(0)->Int32Value()); 2077 CHECK_EQ(1, arr->Get(0)->Int32Value());
1900 CHECK_EQ(2, arr->Get(1)->Int32Value()); 2078 CHECK_EQ(2, arr->Get(1)->Int32Value());
1901 CHECK_EQ(3, arr->Get(2)->Int32Value()); 2079 CHECK_EQ(3, arr->Get(2)->Int32Value());
2080 array = v8::Array::New(27);
2081 CHECK_EQ(27, array->Length());
2082 array = v8::Array::New(-27);
2083 CHECK_EQ(0, array->Length());
1902 } 2084 }
1903 2085
1904 2086
1905 v8::Handle<Value> HandleF(const v8::Arguments& args) { 2087 v8::Handle<Value> HandleF(const v8::Arguments& args) {
1906 v8::HandleScope scope; 2088 v8::HandleScope scope;
1907 ApiTestFuzzer::Fuzz(); 2089 ApiTestFuzzer::Fuzz();
1908 Local<v8::Array> result = v8::Array::New(args.Length()); 2090 Local<v8::Array> result = v8::Array::New(args.Length());
1909 for (int i = 0; i < args.Length(); i++) 2091 for (int i = 0; i < args.Length(); i++)
1910 result->Set(i, args[i]); 2092 result->Set(i, args[i]);
1911 return scope.Close(result); 2093 return scope.Close(result);
(...skipping 11381 matching lines...) Expand 10 before | Expand all | Expand 10 after
13293 v8::Handle<v8::Function> define_property = 13475 v8::Handle<v8::Function> define_property =
13294 CompileRun("(function() {" 13476 CompileRun("(function() {"
13295 " Object.defineProperty(" 13477 " Object.defineProperty("
13296 " this," 13478 " this,"
13297 " 1," 13479 " 1,"
13298 " { configurable: true, enumerable: true, value: 3 });" 13480 " { configurable: true, enumerable: true, value: 3 });"
13299 "})").As<Function>(); 13481 "})").As<Function>();
13300 context->DetachGlobal(); 13482 context->DetachGlobal();
13301 define_property->Call(proxy, 0, NULL); 13483 define_property->Call(proxy, 0, NULL);
13302 } 13484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698