OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { | 1805 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { |
1806 ApiTestFuzzer::Fuzz(); | 1806 ApiTestFuzzer::Fuzz(); |
1807 return v8::ThrowException(v8_str("konto")); | 1807 return v8::ThrowException(v8_str("konto")); |
1808 } | 1808 } |
1809 | 1809 |
1810 | 1810 |
1811 v8::Handle<Value> CCatcher(const v8::Arguments& args) { | 1811 v8::Handle<Value> CCatcher(const v8::Arguments& args) { |
1812 if (args.Length() < 1) return v8::Boolean::New(false); | 1812 if (args.Length() < 1) return v8::Boolean::New(false); |
1813 v8::HandleScope scope; | 1813 v8::HandleScope scope; |
1814 v8::TryCatch try_catch; | 1814 v8::TryCatch try_catch; |
1815 v8::Script::Compile(args[0]->ToString())->Run(); | 1815 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); |
| 1816 CHECK(!try_catch.HasCaught() || result.IsEmpty()); |
1816 return v8::Boolean::New(try_catch.HasCaught()); | 1817 return v8::Boolean::New(try_catch.HasCaught()); |
1817 } | 1818 } |
1818 | 1819 |
1819 | 1820 |
1820 THREADED_TEST(APICatch) { | 1821 THREADED_TEST(APICatch) { |
1821 v8::HandleScope scope; | 1822 v8::HandleScope scope; |
1822 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1823 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1823 templ->Set(v8_str("ThrowFromC"), | 1824 templ->Set(v8_str("ThrowFromC"), |
1824 v8::FunctionTemplate::New(ThrowFromC)); | 1825 v8::FunctionTemplate::New(ThrowFromC)); |
1825 LocalContext context(0, templ); | 1826 LocalContext context(0, templ); |
(...skipping 16 matching lines...) Expand all Loading... |
1842 v8::FunctionTemplate::New(ThrowFromC)); | 1843 v8::FunctionTemplate::New(ThrowFromC)); |
1843 LocalContext context(0, templ); | 1844 LocalContext context(0, templ); |
1844 v8::TryCatch try_catch; | 1845 v8::TryCatch try_catch; |
1845 CompileRun("ThrowFromC();"); | 1846 CompileRun("ThrowFromC();"); |
1846 CHECK(try_catch.HasCaught()); | 1847 CHECK(try_catch.HasCaught()); |
1847 } | 1848 } |
1848 | 1849 |
1849 | 1850 |
1850 // Test that a try-finally block doesn't shadow a try-catch block | 1851 // Test that a try-finally block doesn't shadow a try-catch block |
1851 // when setting up an external handler. | 1852 // when setting up an external handler. |
1852 THREADED_TEST(TryCatchInTryFinally) { | 1853 // |
| 1854 // BUG(271): Some of the exception propagation does not work on the |
| 1855 // ARM simulator because the simulator separates the C++ stack and the |
| 1856 // JS stack. This test therefore fails on the simulator. The test is |
| 1857 // not threaded to allow the threading tests to run on the simulator. |
| 1858 TEST(TryCatchInTryFinally) { |
1853 v8::HandleScope scope; | 1859 v8::HandleScope scope; |
1854 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1860 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1855 templ->Set(v8_str("CCatcher"), | 1861 templ->Set(v8_str("CCatcher"), |
1856 v8::FunctionTemplate::New(CCatcher)); | 1862 v8::FunctionTemplate::New(CCatcher)); |
1857 LocalContext context(0, templ); | 1863 LocalContext context(0, templ); |
1858 Local<Value> result = CompileRun("try {" | 1864 Local<Value> result = CompileRun("try {" |
1859 " try {" | 1865 " try {" |
1860 " CCatcher('throw 7;');" | 1866 " CCatcher('throw 7;');" |
1861 " } finally {" | 1867 " } finally {" |
1862 " }" | 1868 " }" |
1863 "} catch (e) {" | 1869 "} catch (e) {" |
1864 "}"); | 1870 "}"); |
1865 CHECK(result->IsTrue()); | 1871 CHECK(result->IsTrue()); |
1866 } | 1872 } |
1867 | 1873 |
1868 | 1874 |
1869 static void receive_message(v8::Handle<v8::Message> message, | 1875 static void receive_message(v8::Handle<v8::Message> message, |
1870 v8::Handle<v8::Value> data) { | 1876 v8::Handle<v8::Value> data) { |
| 1877 message->Get(); |
1871 message_received = true; | 1878 message_received = true; |
1872 } | 1879 } |
1873 | 1880 |
1874 | 1881 |
1875 TEST(APIThrowMessage) { | 1882 TEST(APIThrowMessage) { |
1876 message_received = false; | 1883 message_received = false; |
1877 v8::HandleScope scope; | 1884 v8::HandleScope scope; |
1878 v8::V8::AddMessageListener(receive_message); | 1885 v8::V8::AddMessageListener(receive_message); |
1879 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1886 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1880 templ->Set(v8_str("ThrowFromC"), | 1887 templ->Set(v8_str("ThrowFromC"), |
1881 v8::FunctionTemplate::New(ThrowFromC)); | 1888 v8::FunctionTemplate::New(ThrowFromC)); |
1882 LocalContext context(0, templ); | 1889 LocalContext context(0, templ); |
1883 CompileRun("ThrowFromC();"); | 1890 CompileRun("ThrowFromC();"); |
1884 CHECK(message_received); | 1891 CHECK(message_received); |
1885 v8::V8::RemoveMessageListeners(check_message); | 1892 v8::V8::RemoveMessageListeners(check_message); |
1886 } | 1893 } |
1887 | 1894 |
1888 | 1895 |
1889 TEST(APIThrowMessageAndVerboseTryCatch) { | 1896 TEST(APIThrowMessageAndVerboseTryCatch) { |
1890 message_received = false; | 1897 message_received = false; |
1891 v8::HandleScope scope; | 1898 v8::HandleScope scope; |
1892 v8::V8::AddMessageListener(receive_message); | 1899 v8::V8::AddMessageListener(receive_message); |
1893 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1900 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1894 templ->Set(v8_str("ThrowFromC"), | 1901 templ->Set(v8_str("ThrowFromC"), |
1895 v8::FunctionTemplate::New(ThrowFromC)); | 1902 v8::FunctionTemplate::New(ThrowFromC)); |
1896 LocalContext context(0, templ); | 1903 LocalContext context(0, templ); |
1897 v8::TryCatch try_catch; | 1904 v8::TryCatch try_catch; |
1898 try_catch.SetVerbose(true); | 1905 try_catch.SetVerbose(true); |
1899 CompileRun("ThrowFromC();"); | 1906 Local<Value> result = CompileRun("ThrowFromC();"); |
1900 CHECK(try_catch.HasCaught()); | 1907 CHECK(try_catch.HasCaught()); |
| 1908 CHECK(result.IsEmpty()); |
1901 CHECK(message_received); | 1909 CHECK(message_received); |
1902 v8::V8::RemoveMessageListeners(check_message); | 1910 v8::V8::RemoveMessageListeners(check_message); |
1903 } | 1911 } |
1904 | 1912 |
1905 | 1913 |
1906 THREADED_TEST(ExternalScriptException) { | 1914 THREADED_TEST(ExternalScriptException) { |
1907 v8::HandleScope scope; | 1915 v8::HandleScope scope; |
1908 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1916 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1909 templ->Set(v8_str("ThrowFromC"), | 1917 templ->Set(v8_str("ThrowFromC"), |
1910 v8::FunctionTemplate::New(ThrowFromC)); | 1918 v8::FunctionTemplate::New(ThrowFromC)); |
(...skipping 25 matching lines...) Expand all Loading... |
1936 args[1], | 1944 args[1], |
1937 args[2], | 1945 args[2], |
1938 args[3] }; | 1946 args[3] }; |
1939 if (count % cInterval == 0) { | 1947 if (count % cInterval == 0) { |
1940 v8::TryCatch try_catch; | 1948 v8::TryCatch try_catch; |
1941 Local<Value> result = | 1949 Local<Value> result = |
1942 v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); | 1950 v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); |
1943 int expected = args[3]->Int32Value(); | 1951 int expected = args[3]->Int32Value(); |
1944 if (try_catch.HasCaught()) { | 1952 if (try_catch.HasCaught()) { |
1945 CHECK_EQ(expected, count); | 1953 CHECK_EQ(expected, count); |
| 1954 CHECK(result.IsEmpty()); |
1946 CHECK(!i::Top::has_scheduled_exception()); | 1955 CHECK(!i::Top::has_scheduled_exception()); |
1947 } else { | 1956 } else { |
1948 CHECK_NE(expected, count); | 1957 CHECK_NE(expected, count); |
1949 } | 1958 } |
1950 return result; | 1959 return result; |
1951 } else { | 1960 } else { |
1952 return v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); | 1961 return v8::Handle<Function>::Cast(fun)->Call(global, 4, argv); |
1953 } | 1962 } |
1954 } | 1963 } |
1955 } | 1964 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 // no other activations do. The right activation is always the topmost one with | 2002 // no other activations do. The right activation is always the topmost one with |
1994 // a handler, regardless of whether it is in JavaScript or C. | 2003 // a handler, regardless of whether it is in JavaScript or C. |
1995 // | 2004 // |
1996 // The notation used to describe a test case looks like this: | 2005 // The notation used to describe a test case looks like this: |
1997 // | 2006 // |
1998 // *JS[4] *C[3] @JS[2] C[1] JS[0] | 2007 // *JS[4] *C[3] @JS[2] C[1] JS[0] |
1999 // | 2008 // |
2000 // Each entry is an activation, either JS or C. The index is the count at that | 2009 // Each entry is an activation, either JS or C. The index is the count at that |
2001 // level. Stars identify activations with exception handlers, the @ identifies | 2010 // level. Stars identify activations with exception handlers, the @ identifies |
2002 // the exception handler that should catch the exception. | 2011 // the exception handler that should catch the exception. |
2003 THREADED_TEST(ExceptionOrder) { | 2012 // |
| 2013 // BUG(271): Some of the exception propagation does not work on the |
| 2014 // ARM simulator because the simulator separates the C++ stack and the |
| 2015 // JS stack. This test therefore fails on the simulator. The test is |
| 2016 // not threaded to allow the threading tests to run on the simulator. |
| 2017 TEST(ExceptionOrder) { |
2004 v8::HandleScope scope; | 2018 v8::HandleScope scope; |
2005 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 2019 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
2006 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); | 2020 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); |
2007 templ->Set(v8_str("CThrowCountDown"), | 2021 templ->Set(v8_str("CThrowCountDown"), |
2008 v8::FunctionTemplate::New(CThrowCountDown)); | 2022 v8::FunctionTemplate::New(CThrowCountDown)); |
2009 LocalContext context(0, templ); | 2023 LocalContext context(0, templ); |
2010 CompileRun( | 2024 CompileRun( |
2011 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" | 2025 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" |
2012 " if (count == 0) throw 'FromJS';" | 2026 " if (count == 0) throw 'FromJS';" |
2013 " if (count % jsInterval == 0) {" | 2027 " if (count % jsInterval == 0) {" |
(...skipping 4101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6115 // Check without 'eval' or 'with'. | 6129 // Check without 'eval' or 'with'. |
6116 v8::Handle<v8::Value> res = | 6130 v8::Handle<v8::Value> res = |
6117 CompileRun("function f() { x = 42; return x; }; f()"); | 6131 CompileRun("function f() { x = 42; return x; }; f()"); |
6118 // Check with 'eval'. | 6132 // Check with 'eval'. |
6119 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); | 6133 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); |
6120 CHECK_EQ(v8::Integer::New(42), res); | 6134 CHECK_EQ(v8::Integer::New(42), res); |
6121 // Check with 'with'. | 6135 // Check with 'with'. |
6122 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); | 6136 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); |
6123 CHECK_EQ(v8::Integer::New(42), res); | 6137 CHECK_EQ(v8::Integer::New(42), res); |
6124 } | 6138 } |
OLD | NEW |