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 ASSERT(strcmp(last_exception, "UnhandledException") == 0); |
siva
2012/11/26 23:03:02
I think this should be :
EXPECT_NOTNULL(last_excep
Tom Ball
2012/11/26 23:14:50
Done.
| |
6272 EXPECT_ERROR(result, "Exception: MakeParentExit"); | |
6273 } else { | 6289 } else { |
6274 EXPECT_VALID(result); | 6290 result = Dart_RunLoop(); |
6291 if (throw_exception_parent) { | |
6292 EXPECT_ERROR(result, "Exception: MakeParentExit"); | |
6293 ASSERT(strcmp(last_exception, "UnhandledException") == 0); | |
siva
2012/11/26 23:03:02
Ditto comment.
Tom Ball
2012/11/26 23:14:50
Done.
| |
6294 } else { | |
6295 EXPECT_VALID(result); | |
6296 ASSERT(last_exception == NULL); | |
siva
2012/11/26 23:03:02
This should be :
EXPECT_EQ(NULL, last_exception);
Tom Ball
2012/11/26 23:14:50
Done.
| |
6297 } | |
6298 } | |
6299 if (last_exception != NULL) { | |
6300 free(last_exception); | |
6301 last_exception = NULL; | |
6275 } | 6302 } |
6276 | 6303 |
6277 Dart_ExitScope(); | 6304 Dart_ExitScope(); |
6278 Dart_ShutdownIsolate(); | 6305 Dart_ShutdownIsolate(); |
6279 | 6306 |
6280 Isolate::SetCreateCallback(saved); | 6307 Isolate::SetCreateCallback(saved); |
6281 } | 6308 } |
6282 | 6309 |
6283 | 6310 |
6284 UNIT_TEST_CASE(RunLoop_Success) { | 6311 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); | 7407 Dart_LoadSource(TestCase::lib(), url, source); |
7381 | 7408 |
7382 dart_args[0] = Dart_NewInteger(1); | 7409 dart_args[0] = Dart_NewInteger(1); |
7383 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7410 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
7384 EXPECT_VALID(result); | 7411 EXPECT_VALID(result); |
7385 } | 7412 } |
7386 | 7413 |
7387 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7414 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7388 | 7415 |
7389 } // namespace dart | 7416 } // namespace dart |
OLD | NEW |