OLD | NEW |
---|---|
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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 .ToHandleChecked(); | 944 .ToHandleChecked(); |
945 CHECK(return_value->SameValue(*snippets[i].return_value())); | 945 CHECK(return_value->SameValue(*snippets[i].return_value())); |
946 } | 946 } |
947 } | 947 } |
948 | 948 |
949 | 949 |
950 TEST(BytecodeGraphBuilderTestInstanceOf) { | 950 TEST(BytecodeGraphBuilderTestInstanceOf) { |
951 // TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported. | 951 // TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported. |
952 } | 952 } |
953 | 953 |
954 | |
955 TEST(BytecodeGraphBuilderThrow) { | |
956 HandleAndZoneScope scope; | |
957 Isolate* isolate = scope.main_isolate(); | |
958 Zone* zone = scope.main_zone(); | |
959 Factory* factory = isolate->factory(); | |
960 | |
961 // TODO(mythria): modify these tests when real try-catch is supported. | |
962 ExpectedSnippet<0> snippets[] = { | |
963 {"throw undefined;", {factory->undefined_value()}}, | |
964 {"throw 1;", {factory->NewNumberFromInt(1)}}, | |
965 {"throw 'Error';", {factory->NewStringFromStaticChars("Error")}}, | |
966 {"throw 'Error1'; throw 'Error2'", | |
967 {factory->NewStringFromStaticChars("Error1")}}, | |
968 // TODO(mythria): Enable these tests when JumpIfTrue is supported. | |
969 // {"var a = true; if (a) { throw 'Error'; }", | |
970 // {factory->NewStringFromStaticChars("Error")}}, | |
971 // {"var a = false; if (a) { throw 'Error'; }", | |
972 // {factory->undefined_value()}}, | |
973 }; | |
974 | |
975 const char* try_wrapper = | |
976 "(function() { try { f(); } catch(e) { return e; }})()"; | |
977 | |
978 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | |
979 for (size_t i = 0; i < num_snippets; i++) { | |
980 ScopedVector<char> script(1024); | |
981 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | |
982 snippets[i].code_snippet, kFunctionName); | |
983 BytecodeGraphTester tester(isolate, zone, script.start()); | |
984 tester.GetCallable<>(); | |
985 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | |
Michael Starzinger
2015/11/26 17:27:45
suggestion: We could also use a v8::TryCatch scope
mythria
2015/11/27 14:54:47
Thanks, I changed it to TryCatch scope.
Done.
| |
986 CHECK(thrown_obj->SameValue(*snippets[i].return_value())); | |
987 } | |
988 } | |
989 | |
954 } // namespace compiler | 990 } // namespace compiler |
955 } // namespace internal | 991 } // namespace internal |
956 } // namespace v8 | 992 } // namespace v8 |
OLD | NEW |