1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "test/cctest/compiler/function-tester.h"
9 using namespace v8::internal;
10 using namespace v8::internal::compiler;
13 i::FLAG_turbo_exceptions = true;
14 FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})");
16 T.CheckThrows(T.true_value(), T.NewObject("new Error"));
17 T.CheckCall(T.Val(23), T.false_value(), T.Val(23));
21 TEST(ThrowSourcePosition) {
22 static const char* src =
23 "(function(a, b) { \n"
24 " if (a == 1) throw 1; \n"
25 " if (a == 2) {throw 2} \n"
26 " if (a == 3) {0;throw 3}\n"
29 FunctionTester T(src);
30 v8::Handle<v8::Message> message;
32 message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined());
33 CHECK(!message.IsEmpty());
34 CHECK_EQ(2, message->GetLineNumber());
35 CHECK_EQ(40, message->GetStartPosition());
37 message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined());
38 CHECK(!message.IsEmpty());
39 CHECK_EQ(3, message->GetLineNumber());
40 CHECK_EQ(67, message->GetStartPosition());
42 message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined());
43 CHECK(!message.IsEmpty());
44 CHECK_EQ(4, message->GetLineNumber());
45 CHECK_EQ(95, message->GetStartPosition());
49 // TODO(mstarzinger): Increase test coverage by having similar tests within the
50 // mjsunit suite to also test integration with other components (e.g. OSR).
54 i::FLAG_turbo_exceptions = true;
66 FunctionTester T(src);
68 T.CheckCall(T.Val("-A-B-"));
73 i::FLAG_turbo_exceptions = true;
90 FunctionTester T(src);
92 T.CheckCall(T.Val("-A-B-C-"));
97 i::FLAG_turbo_exceptions = true;
113 FunctionTester T(src);
115 T.CheckCall(T.Val("-A-D-"), T.true_value(), T.false_value());
116 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value());
117 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value());
122 i::FLAG_turbo_exceptions = true;
133 FunctionTester T(src);
135 T.CheckCall(T.Val("-A-B-"));
140 i::FLAG_turbo_exceptions = true;
155 FunctionTester T(src);
157 T.CheckCall(T.Val("-A-"), T.true_value(), T.false_value());
158 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value());
159 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value());