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

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

Issue 1410863002: [Interpreter] Add support for Throw. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 1992
1993 // TODO(rmcilroy): modify tests when we have real try finally support. 1993 // TODO(rmcilroy): modify tests when we have real try finally support.
1994 std::string source(InterpreterTester::SourceForBody( 1994 std::string source(InterpreterTester::SourceForBody(
1995 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); 1995 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;"));
1996 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1996 InterpreterTester tester(handles.main_isolate(), source.c_str());
1997 auto callable = tester.GetCallable<>(); 1997 auto callable = tester.GetCallable<>();
1998 1998
1999 Handle<Object> return_val = callable().ToHandleChecked(); 1999 Handle<Object> return_val = callable().ToHandleChecked();
2000 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); 2000 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
2001 } 2001 }
2002
2003
2004 TEST(InterpreterThrow) {
2005 HandleAndZoneScope handles;
2006 i::Isolate* isolate = handles.main_isolate();
2007 i::Factory* factory = isolate->factory();
2008
2009 // TODO(rmcilroy): modify tests when we have real try catch support.
2010 std::pair<const char*, Handle<Object>> throws[6] = {
2011 std::make_pair("throw undefined;\n",
2012 factory->undefined_value()),
2013 std::make_pair("throw 1;\n",
2014 Handle<Object>(Smi::FromInt(1), isolate)),
2015 std::make_pair("throw 'Error';\n",
2016 factory->NewStringFromStaticChars("Error")),
2017 std::make_pair("var a = true; if (a) { throw 'Error'; }\n",
2018 factory->NewStringFromStaticChars("Error")),
2019 std::make_pair("var a = false; if (a) { throw 'Error'; }\n",
2020 factory->undefined_value()),
2021 std::make_pair("throw 'Error1'; throw 'Error2'\n",
2022 factory->NewStringFromStaticChars("Error1")),
2023 };
2024
2025 const char* try_wrapper =
2026 "(function() { try { f(); } catch(e) { return e; }})()";
2027
2028 for (size_t i = 0; i < arraysize(throws); i++) {
2029 std::string source(InterpreterTester::SourceForBody(throws[i].first));
2030 InterpreterTester tester(handles.main_isolate(), source.c_str());
2031 tester.GetCallable<>();
2032 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
2033 CHECK(thrown_obj->SameValue(*throws[i].second));
2034 }
2035 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698