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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 6232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6243 Dart_Handle source = NewString(kScriptChars); | 6243 Dart_Handle source = NewString(kScriptChars); |
6244 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 6244 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
6245 EXPECT_VALID(result); | 6245 EXPECT_VALID(result); |
6246 Dart_Handle lib = Dart_LoadScript(url, source); | 6246 Dart_Handle lib = Dart_LoadScript(url, source); |
6247 EXPECT_VALID(lib); | 6247 EXPECT_VALID(lib); |
6248 Dart_ExitScope(); | 6248 Dart_ExitScope(); |
6249 return true; | 6249 return true; |
6250 } | 6250 } |
6251 | 6251 |
6252 | 6252 |
| 6253 // The error string from the last unhandled exception. This value is only |
| 6254 // valid until the next Dart_ExitScope(). |
| 6255 static char* last_exception = NULL; |
| 6256 |
| 6257 |
| 6258 static void RunLoopUnhandledExceptionCallback(Dart_Handle exception) { |
| 6259 Dart_Handle error_string = Dart_ToString(exception); |
| 6260 EXPECT_VALID(error_string); |
| 6261 const char* error_text; |
| 6262 Dart_Handle result = Dart_StringToCString(error_string, &error_text); |
| 6263 // Duplicate the string since error text is freed when callback is finished. |
| 6264 last_exception = strdup(error_text); |
| 6265 EXPECT_VALID(result); |
| 6266 } |
| 6267 |
| 6268 |
6253 // Common code for RunLoop_Success/RunLoop_Failure. | 6269 // Common code for RunLoop_Success/RunLoop_Failure. |
6254 static void RunLoopTest(bool throw_exception_child, | 6270 static void RunLoopTest(bool throw_exception_child, |
6255 bool throw_exception_parent) { | 6271 bool throw_exception_parent) { |
6256 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 6272 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
6257 Isolate::SetCreateCallback(RunLoopTestCallback); | 6273 Isolate::SetCreateCallback(RunLoopTestCallback); |
| 6274 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); |
6258 RunLoopTestCallback(NULL, NULL, NULL, NULL); | 6275 RunLoopTestCallback(NULL, NULL, NULL, NULL); |
6259 | 6276 |
6260 Dart_EnterScope(); | 6277 Dart_EnterScope(); |
6261 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 6278 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
6262 EXPECT_VALID(lib); | 6279 EXPECT_VALID(lib); |
6263 | 6280 |
6264 Dart_Handle result; | 6281 Dart_Handle result; |
6265 Dart_Handle args[2]; | 6282 Dart_Handle args[2]; |
6266 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); | 6283 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); |
6267 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); | 6284 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); |
6268 result = Dart_Invoke(lib, NewString("main"), 2, args); | 6285 result = Dart_Invoke(lib, NewString("main"), 2, args); |
6269 EXPECT_VALID(result); | 6286 EXPECT_VALID(result); |
6270 result = Dart_RunLoop(); | 6287 if (throw_exception_child) { |
6271 if (throw_exception_parent) { | 6288 EXPECT_NOTNULL(last_exception); |
6272 EXPECT_ERROR(result, "Exception: MakeParentExit"); | 6289 EXPECT_STREQ("UnhandledException", last_exception); |
6273 } else { | 6290 } else { |
6274 EXPECT_VALID(result); | 6291 result = Dart_RunLoop(); |
| 6292 if (throw_exception_parent) { |
| 6293 EXPECT_ERROR(result, "Exception: MakeParentExit"); |
| 6294 EXPECT_NOTNULL(last_exception); |
| 6295 EXPECT_STREQ("UnhandledException", last_exception); |
| 6296 } else { |
| 6297 EXPECT_VALID(result); |
| 6298 EXPECT(last_exception == NULL); |
| 6299 } |
| 6300 } |
| 6301 if (last_exception != NULL) { |
| 6302 free(last_exception); |
| 6303 last_exception = NULL; |
6275 } | 6304 } |
6276 | 6305 |
6277 Dart_ExitScope(); | 6306 Dart_ExitScope(); |
6278 Dart_ShutdownIsolate(); | 6307 Dart_ShutdownIsolate(); |
6279 | 6308 |
6280 Isolate::SetCreateCallback(saved); | 6309 Isolate::SetCreateCallback(saved); |
6281 } | 6310 } |
6282 | 6311 |
6283 | 6312 |
6284 UNIT_TEST_CASE(RunLoop_Success) { | 6313 UNIT_TEST_CASE(RunLoop_Success) { |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7380 Dart_LoadSource(TestCase::lib(), url, source); | 7409 Dart_LoadSource(TestCase::lib(), url, source); |
7381 | 7410 |
7382 dart_args[0] = Dart_NewInteger(1); | 7411 dart_args[0] = Dart_NewInteger(1); |
7383 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7412 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
7384 EXPECT_VALID(result); | 7413 EXPECT_VALID(result); |
7385 } | 7414 } |
7386 | 7415 |
7387 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7416 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7388 | 7417 |
7389 } // namespace dart | 7418 } // namespace dart |
OLD | NEW |