• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "src/v8.h"
6 
7 #include "test/cctest/compiler/function-tester.h"
8 
9 using namespace v8::internal;
10 using namespace v8::internal::compiler;
11 
TEST(Throw)12 TEST(Throw) {
13   FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})");
14 
15   T.CheckThrows(T.true_value(), T.NewObject("new Error"));
16   T.CheckCall(T.Val(23), T.false_value(), T.Val(23));
17 }
18 
19 
TEST(ThrowSourcePosition)20 TEST(ThrowSourcePosition) {
21   static const char* src =
22       "(function(a, b) {        \n"
23       "  if (a == 1) throw 1;   \n"
24       "  if (a == 2) {throw 2}  \n"
25       "  if (a == 3) {0;throw 3}\n"
26       "  throw 4;               \n"
27       "})                       ";
28   FunctionTester T(src);
29   v8::Handle<v8::Message> message;
30 
31   message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined());
32   CHECK(!message.IsEmpty());
33   CHECK_EQ(2, message->GetLineNumber());
34   CHECK_EQ(40, message->GetStartPosition());
35 
36   message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined());
37   CHECK(!message.IsEmpty());
38   CHECK_EQ(3, message->GetLineNumber());
39   CHECK_EQ(67, message->GetStartPosition());
40 
41   message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined());
42   CHECK(!message.IsEmpty());
43   CHECK_EQ(4, message->GetLineNumber());
44   CHECK_EQ(95, message->GetStartPosition());
45 }
46