| 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 "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
| 6 #include "bin/builtin.h" | 6 #include "bin/builtin.h" |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_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 "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 EXPECT_EQ(2, line_number); | 206 EXPECT_EQ(2, line_number); |
| 207 EXPECT_EQ(15, column_number); | 207 EXPECT_EQ(15, column_number); |
| 208 | 208 |
| 209 // Out-of-bounds frames. | 209 // Out-of-bounds frames. |
| 210 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 210 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
| 211 EXPECT(Dart_IsError(result)); | 211 EXPECT(Dart_IsError(result)); |
| 212 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 212 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
| 213 EXPECT(Dart_IsError(result)); | 213 EXPECT(Dart_IsError(result)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST_CASE(DartAPI_StackOverflowStackTraceInfo) { | 216 void VerifyStackOverflowStackTraceInfo(const char* script, |
| 217 const char* kScriptChars = | 217 const char* top_frame_func_name, |
| 218 "class C {\n" | 218 const char* entry_func_name, |
| 219 " static foo() => foo();\n" | 219 int expected_line_number, |
| 220 "}\n" | 220 int expected_column_number) { |
| 221 "testMain() => C.foo();\n"; | 221 Dart_Handle lib = TestCase::LoadTestScript(script, NULL); |
| 222 | 222 Dart_Handle error = Dart_Invoke(lib, NewString(entry_func_name), 0, NULL); |
| 223 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 224 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 225 | 223 |
| 226 EXPECT(Dart_IsError(error)); | 224 EXPECT(Dart_IsError(error)); |
| 227 | 225 |
| 228 Dart_StackTrace stacktrace; | 226 Dart_StackTrace stacktrace; |
| 229 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | 227 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); |
| 230 EXPECT_VALID(result); | 228 EXPECT_VALID(result); |
| 231 | 229 |
| 232 intptr_t frame_count = 0; | 230 intptr_t frame_count = 0; |
| 233 result = Dart_StackTraceLength(stacktrace, &frame_count); | 231 result = Dart_StackTraceLength(stacktrace, &frame_count); |
| 234 EXPECT_VALID(result); | 232 EXPECT_VALID(result); |
| 235 EXPECT_EQ(StackTrace::kPreallocatedStackdepth - 1, frame_count); | 233 EXPECT_EQ(StackTrace::kPreallocatedStackdepth - 1, frame_count); |
| 236 | 234 |
| 237 Dart_Handle function_name; | 235 Dart_Handle function_name; |
| 238 Dart_Handle script_url; | 236 Dart_Handle script_url; |
| 239 intptr_t line_number = 0; | 237 intptr_t line_number = 0; |
| 240 intptr_t column_number = 0; | 238 intptr_t column_number = 0; |
| 241 const char* cstr = ""; | 239 const char* cstr = ""; |
| 242 | 240 |
| 243 // Top frame at recursive call. | 241 // Top frame at recursive call. |
| 244 Dart_ActivationFrame frame; | 242 Dart_ActivationFrame frame; |
| 245 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | 243 result = Dart_GetActivationFrame(stacktrace, 0, &frame); |
| 246 EXPECT_VALID(result); | 244 EXPECT_VALID(result); |
| 247 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, | 245 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, |
| 248 &line_number, &column_number); | 246 &line_number, &column_number); |
| 249 EXPECT_VALID(result); | 247 EXPECT_VALID(result); |
| 250 Dart_StringToCString(function_name, &cstr); | 248 Dart_StringToCString(function_name, &cstr); |
| 251 EXPECT_STREQ("C.foo", cstr); | 249 EXPECT_STREQ(top_frame_func_name, cstr); |
| 252 Dart_StringToCString(script_url, &cstr); | 250 Dart_StringToCString(script_url, &cstr); |
| 253 EXPECT_STREQ("test-lib", cstr); | 251 EXPECT_STREQ("test-lib", cstr); |
| 254 EXPECT_EQ(2, line_number); | 252 EXPECT_EQ(expected_line_number, line_number); |
| 255 EXPECT_EQ(13, column_number); | 253 EXPECT_EQ(expected_column_number, column_number); |
| 256 | 254 |
| 257 // Out-of-bounds frames. | 255 // Out-of-bounds frames. |
| 258 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | 256 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); |
| 259 EXPECT(Dart_IsError(result)); | 257 EXPECT(Dart_IsError(result)); |
| 260 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | 258 result = Dart_GetActivationFrame(stacktrace, -1, &frame); |
| 261 EXPECT(Dart_IsError(result)); | 259 EXPECT(Dart_IsError(result)); |
| 262 } | 260 } |
| 263 | 261 |
| 262 TEST_CASE(DartAPI_StackOverflowStackTraceInfoBraceFunction1) { |
| 263 VerifyStackOverflowStackTraceInfo( |
| 264 "class C {\n" |
| 265 " static foo(int i) { foo(i); }\n" |
| 266 "}\n" |
| 267 "testMain() => C.foo(10);\n", |
| 268 "C.foo", "testMain", 2, 21); |
| 269 } |
| 270 |
| 271 TEST_CASE(DartAPI_StackOverflowStackTraceInfoBraceFunction2) { |
| 272 VerifyStackOverflowStackTraceInfo( |
| 273 "class C {\n" |
| 274 " static foo(int i, int j) {\n" |
| 275 " foo(i, j);\n" |
| 276 " }\n" |
| 277 "}\n" |
| 278 "testMain() => C.foo(10, 11);\n", |
| 279 "C.foo", "testMain", 2, 28); |
| 280 } |
| 281 |
| 282 TEST_CASE(DartAPI_StackOverflowStackTraceInfoArrowFunction) { |
| 283 VerifyStackOverflowStackTraceInfo( |
| 284 "class C {\n" |
| 285 " static foo(int i) => foo(i);\n" |
| 286 "}\n" |
| 287 "testMain() => C.foo(10);\n", |
| 288 "C.foo", "testMain", 2, 21); |
| 289 } |
| 290 |
| 264 TEST_CASE(DartAPI_OutOfMemoryStackTraceInfo) { | 291 TEST_CASE(DartAPI_OutOfMemoryStackTraceInfo) { |
| 265 const char* kScriptChars = | 292 const char* kScriptChars = |
| 266 "var number_of_ints = 134000000;\n" | 293 "var number_of_ints = 134000000;\n" |
| 267 "testMain() {\n" | 294 "testMain() {\n" |
| 268 " new List<int>(number_of_ints)\n" | 295 " new List<int>(number_of_ints)\n" |
| 269 "}\n"; | 296 "}\n"; |
| 270 | 297 |
| 271 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 298 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 272 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 299 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 273 | 300 |
| (...skipping 9412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9686 EXPECT_VALID(result); | 9713 EXPECT_VALID(result); |
| 9687 result = Dart_FinalizeLoading(false); | 9714 result = Dart_FinalizeLoading(false); |
| 9688 EXPECT_VALID(result); | 9715 EXPECT_VALID(result); |
| 9689 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9716 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
| 9690 EXPECT(Dart_IsError(result)); | 9717 EXPECT(Dart_IsError(result)); |
| 9691 } | 9718 } |
| 9692 | 9719 |
| 9693 #endif // !PRODUCT | 9720 #endif // !PRODUCT |
| 9694 | 9721 |
| 9695 } // namespace dart | 9722 } // namespace dart |
| OLD | NEW |