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

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1481763002: [Interpreter] Adds support for throw to bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed nits Created 5 years 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
« no previous file with comments | « src/compiler/bytecode-graph-builder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Ensure handler table is generated. 81 // Ensure handler table is generated.
82 isolate->interpreter()->Initialize(); 82 isolate->interpreter()->Initialize();
83 } 83 }
84 virtual ~BytecodeGraphTester() {} 84 virtual ~BytecodeGraphTester() {}
85 85
86 template <class... A> 86 template <class... A>
87 BytecodeGraphCallable<A...> GetCallable() { 87 BytecodeGraphCallable<A...> GetCallable() {
88 return BytecodeGraphCallable<A...>(isolate_, GetFunction()); 88 return BytecodeGraphCallable<A...>(isolate_, GetFunction());
89 } 89 }
90 90
91 Local<Message> CheckThrowsReturnMessage() {
92 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_));
93 auto callable = GetCallable<>();
94 MaybeHandle<Object> no_result = callable();
95 CHECK(isolate_->has_pending_exception());
96 CHECK(try_catch.HasCaught());
97 CHECK(no_result.is_null());
98 isolate_->OptionalRescheduleException(true);
99 CHECK(!try_catch.Message().IsEmpty());
100 return try_catch.Message();
101 }
102
91 static Handle<Object> NewObject(const char* script) { 103 static Handle<Object> NewObject(const char* script) {
92 return v8::Utils::OpenHandle(*CompileRun(script)); 104 return v8::Utils::OpenHandle(*CompileRun(script));
93 } 105 }
94 106
95 private: 107 private:
96 Isolate* isolate_; 108 Isolate* isolate_;
97 Zone* zone_; 109 Zone* zone_;
98 const char* script_; 110 const char* script_;
99 111
100 Handle<JSFunction> GetFunction() { 112 Handle<JSFunction> GetFunction() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 SEP() \ 159 SEP() \
148 REPEAT_32(SEP, __VA_ARGS__) \ 160 REPEAT_32(SEP, __VA_ARGS__) \
149 SEP() \ 161 SEP() \
150 REPEAT_16(SEP, __VA_ARGS__) \ 162 REPEAT_16(SEP, __VA_ARGS__) \
151 SEP() \ 163 SEP() \
152 REPEAT_8(SEP, __VA_ARGS__) \ 164 REPEAT_8(SEP, __VA_ARGS__) \
153 SEP() \ 165 SEP() \
154 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__ 166 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__
155 167
156 168
157 template <int N> 169 template <int N, typename T = Handle<Object>>
158 struct ExpectedSnippet { 170 struct ExpectedSnippet {
159 const char* code_snippet; 171 const char* code_snippet;
160 Handle<Object> return_value_and_parameters[N + 1]; 172 T return_value_and_parameters[N + 1];
161 173
162 inline Handle<Object> return_value() const { 174 inline T return_value() const { return return_value_and_parameters[0]; }
163 return return_value_and_parameters[0];
164 }
165 175
166 inline Handle<Object> parameter(int i) const { 176 inline T parameter(int i) const {
167 DCHECK_GE(i, 0); 177 DCHECK_GE(i, 0);
168 DCHECK_LT(i, N); 178 DCHECK_LT(i, N);
169 return return_value_and_parameters[1 + i]; 179 return return_value_and_parameters[1 + i];
170 } 180 }
171 }; 181 };
172 182
173 183
174 TEST(BytecodeGraphBuilderReturnStatements) { 184 TEST(BytecodeGraphBuilderReturnStatements) {
175 HandleAndZoneScope scope; 185 HandleAndZoneScope scope;
176 Isolate* isolate = scope.main_isolate(); 186 Isolate* isolate = scope.main_isolate();
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 .ToHandleChecked(); 954 .ToHandleChecked();
945 CHECK(return_value->SameValue(*snippets[i].return_value())); 955 CHECK(return_value->SameValue(*snippets[i].return_value()));
946 } 956 }
947 } 957 }
948 958
949 959
950 TEST(BytecodeGraphBuilderTestInstanceOf) { 960 TEST(BytecodeGraphBuilderTestInstanceOf) {
951 // TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported. 961 // TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported.
952 } 962 }
953 963
964
965 TEST(BytecodeGraphBuilderThrow) {
966 HandleAndZoneScope scope;
967 Isolate* isolate = scope.main_isolate();
968 Zone* zone = scope.main_zone();
969
970 // TODO(mythria): Add more tests when real try-catch and deoptimization
971 // information are supported.
972 ExpectedSnippet<0, const char*> snippets[] = {
973 {"throw undefined;", {"Uncaught undefined"}},
974 {"throw 1;", {"Uncaught 1"}},
975 {"throw 'Error';", {"Uncaught Error"}},
976 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}},
977 // TODO(mythria): Enable these tests when JumpIfTrue is supported.
978 // {"var a = true; if (a) { throw 'Error'; }", {"Error"}},
979 };
980
981 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
982 for (size_t i = 0; i < num_snippets; i++) {
983 ScopedVector<char> script(1024);
984 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
985 snippets[i].code_snippet, kFunctionName);
986 BytecodeGraphTester tester(isolate, zone, script.start());
987 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
988 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
989 CHECK(
990 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
991 .FromJust());
992 }
993 }
994
954 } // namespace compiler 995 } // namespace compiler
955 } // namespace internal 996 } // namespace internal
956 } // namespace v8 997 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/bytecode-graph-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698