OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); | 55 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); |
56 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); | 56 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); |
57 EXPECT_VALID(Dart_ErrorGetException(exception)); | 57 EXPECT_VALID(Dart_ErrorGetException(exception)); |
58 | 58 |
59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); | 59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); |
60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); |
61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); |
62 } | 62 } |
63 | 63 |
64 | 64 |
| 65 TEST_CASE(StacktraceInfo) { |
| 66 const char* kScriptChars = |
| 67 "bar() => throw new Error();\n" |
| 68 "foo() => bar();\n" |
| 69 "testMain() => foo();\n"; |
| 70 |
| 71 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 72 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 73 |
| 74 EXPECT(Dart_IsError(error)); |
| 75 |
| 76 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(error); |
| 77 EXPECT_VALID(stacktrace); |
| 78 EXPECT(Dart_IsInstance(stacktrace)); |
| 79 |
| 80 intptr_t frame_count = 0; |
| 81 Dart_Handle result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 82 EXPECT_VALID(result); |
| 83 EXPECT_EQ(3, frame_count); |
| 84 |
| 85 Dart_Handle function_name; |
| 86 Dart_Handle script_url; |
| 87 intptr_t line_number = 0; |
| 88 intptr_t column_number = 0; |
| 89 const char* cstr = ""; |
| 90 |
| 91 result = Dart_StacktraceFrameInfo(stacktrace, |
| 92 0, |
| 93 &function_name, |
| 94 &script_url, |
| 95 &line_number, |
| 96 &column_number); |
| 97 EXPECT_VALID(result); |
| 98 Dart_StringToCString(function_name, &cstr); |
| 99 EXPECT_STREQ("bar", cstr); |
| 100 Dart_StringToCString(script_url, &cstr); |
| 101 EXPECT_STREQ("dart:test-lib", cstr); |
| 102 EXPECT_EQ(1, line_number); |
| 103 EXPECT_EQ(10, column_number); |
| 104 |
| 105 result = Dart_StacktraceFrameInfo(stacktrace, |
| 106 1, |
| 107 &function_name, |
| 108 &script_url, |
| 109 &line_number, |
| 110 &column_number); |
| 111 EXPECT_VALID(result); |
| 112 Dart_StringToCString(function_name, &cstr); |
| 113 EXPECT_STREQ("foo", cstr); |
| 114 Dart_StringToCString(script_url, &cstr); |
| 115 EXPECT_STREQ("dart:test-lib", cstr); |
| 116 EXPECT_EQ(2, line_number); |
| 117 EXPECT_EQ(13, column_number); |
| 118 |
| 119 result = Dart_StacktraceFrameInfo(stacktrace, |
| 120 2, |
| 121 &function_name, |
| 122 &script_url, |
| 123 &line_number, |
| 124 &column_number); |
| 125 EXPECT_VALID(result); |
| 126 Dart_StringToCString(function_name, &cstr); |
| 127 EXPECT_STREQ("testMain", cstr); |
| 128 Dart_StringToCString(script_url, &cstr); |
| 129 EXPECT_STREQ("dart:test-lib", cstr); |
| 130 EXPECT_EQ(3, line_number); |
| 131 EXPECT_EQ(18, column_number); |
| 132 |
| 133 result = Dart_StacktraceFrameInfo(stacktrace, |
| 134 frame_count + 1, |
| 135 &function_name, |
| 136 &script_url, |
| 137 &line_number, |
| 138 &column_number); |
| 139 EXPECT(Dart_IsError(result)); |
| 140 |
| 141 result = Dart_StacktraceFrameInfo(stacktrace, |
| 142 -1, |
| 143 &function_name, |
| 144 &script_url, |
| 145 &line_number, |
| 146 &column_number); |
| 147 EXPECT(Dart_IsError(result)); |
| 148 } |
| 149 |
| 150 |
| 151 TEST_CASE(StackOverflowStacktraceInfo) { |
| 152 const char* kScriptChars = |
| 153 "class C {\n" |
| 154 " static foo() => foo();\n" |
| 155 "}\n" |
| 156 "testMain() => C.foo();\n"; |
| 157 |
| 158 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 159 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 160 |
| 161 EXPECT(Dart_IsError(error)); |
| 162 |
| 163 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(error); |
| 164 EXPECT_VALID(stacktrace); |
| 165 EXPECT(Dart_IsInstance(stacktrace)); |
| 166 |
| 167 intptr_t frame_count = 0; |
| 168 Dart_Handle result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 169 EXPECT_VALID(result); |
| 170 EXPECT_EQ(Stacktrace::kPreallocatedStackdepth - 1, frame_count); |
| 171 |
| 172 Dart_Handle function_name; |
| 173 Dart_Handle script_url; |
| 174 intptr_t line_number = 0; |
| 175 intptr_t column_number = 0; |
| 176 const char* cstr = ""; |
| 177 |
| 178 result = Dart_StacktraceFrameInfo(stacktrace, |
| 179 0, |
| 180 &function_name, |
| 181 &script_url, |
| 182 &line_number, |
| 183 &column_number); |
| 184 EXPECT_VALID(result); |
| 185 Dart_StringToCString(function_name, &cstr); |
| 186 EXPECT_STREQ("C.foo", cstr); |
| 187 Dart_StringToCString(script_url, &cstr); |
| 188 EXPECT_STREQ("dart:test-lib", cstr); |
| 189 EXPECT_EQ(2, line_number); |
| 190 EXPECT_EQ(3, column_number); |
| 191 |
| 192 // Middle frames? |
| 193 |
| 194 result = Dart_StacktraceFrameInfo(stacktrace, |
| 195 frame_count + 1, |
| 196 &function_name, |
| 197 &script_url, |
| 198 &line_number, |
| 199 &column_number); |
| 200 EXPECT(Dart_IsError(result)); |
| 201 |
| 202 result = Dart_StacktraceFrameInfo(stacktrace, |
| 203 -1, |
| 204 &function_name, |
| 205 &script_url, |
| 206 &line_number, |
| 207 &column_number); |
| 208 EXPECT(Dart_IsError(result)); |
| 209 } |
| 210 |
| 211 |
| 212 TEST_CASE(OutOfMemoryStacktraceInfo) { |
| 213 const char* kScriptChars = |
| 214 "var number_of_ints = 134000000;\n" |
| 215 "testMain() {\n" |
| 216 " new List<int>(number_of_ints)\n" |
| 217 "}\n"; |
| 218 |
| 219 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 220 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 221 |
| 222 EXPECT(Dart_IsError(error)); |
| 223 |
| 224 Dart_Handle stacktrace = Dart_ErrorGetStacktrace(error); |
| 225 EXPECT(Dart_IsError(stacktrace)); // No Stacktrace for OutOfMemory. |
| 226 } |
| 227 |
| 228 |
65 TEST_CASE(ErrorHandleTypes) { | 229 TEST_CASE(ErrorHandleTypes) { |
66 Isolate* isolate = Isolate::Current(); | 230 Isolate* isolate = Isolate::Current(); |
67 const String& compile_message = String::Handle(String::New("CompileError")); | 231 const String& compile_message = String::Handle(String::New("CompileError")); |
68 const String& fatal_message = String::Handle(String::New("FatalError")); | 232 const String& fatal_message = String::Handle(String::New("FatalError")); |
69 | 233 |
70 Dart_Handle not_error = NewString("NotError"); | 234 Dart_Handle not_error = NewString("NotError"); |
71 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 235 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
72 Dart_Handle exception_error = | 236 Dart_Handle exception_error = |
73 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 237 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
74 Dart_Handle compile_error = | 238 Dart_Handle compile_error = |
(...skipping 7324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7399 NewString("main"), | 7563 NewString("main"), |
7400 0, | 7564 0, |
7401 NULL); | 7565 NULL); |
7402 int64_t value = 0; | 7566 int64_t value = 0; |
7403 result = Dart_IntegerToInt64(result, &value); | 7567 result = Dart_IntegerToInt64(result, &value); |
7404 EXPECT_VALID(result); | 7568 EXPECT_VALID(result); |
7405 EXPECT_EQ(8, value); | 7569 EXPECT_EQ(8, value); |
7406 } | 7570 } |
7407 | 7571 |
7408 } // namespace dart | 7572 } // namespace dart |
OLD | NEW |