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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 6e933b9b4725e5738926bd7e7cff4663f0cf4bbe..fec18e094f3ffa6de3e71ef98c34b3c77d53d796 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -1999,3 +1999,37 @@ TEST(InterpreterTryFinally) {
Handle<Object> return_val = callable().ToHandleChecked();
CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
}
+
+
+TEST(InterpreterThrow) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ // TODO(rmcilroy): modify tests when we have real try catch support.
+ std::pair<const char*, Handle<Object>> throws[6] = {
+ std::make_pair("throw undefined;\n",
+ factory->undefined_value()),
+ std::make_pair("throw 1;\n",
+ Handle<Object>(Smi::FromInt(1), isolate)),
+ std::make_pair("throw 'Error';\n",
+ factory->NewStringFromStaticChars("Error")),
+ std::make_pair("var a = true; if (a) { throw 'Error'; }\n",
+ factory->NewStringFromStaticChars("Error")),
+ std::make_pair("var a = false; if (a) { throw 'Error'; }\n",
+ factory->undefined_value()),
+ std::make_pair("throw 'Error1'; throw 'Error2'\n",
+ factory->NewStringFromStaticChars("Error1")),
+ };
+
+ const char* try_wrapper =
+ "(function() { try { f(); } catch(e) { return e; }})()";
+
+ for (size_t i = 0; i < arraysize(throws); i++) {
+ std::string source(InterpreterTester::SourceForBody(throws[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ tester.GetCallable<>();
+ Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
+ CHECK(thrown_obj->SameValue(*throws[i].second));
+ }
+}
« 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