Chromium Code Reviews| Index: runtime/vm/dart_api_impl_test.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl_test.cc (revision 1867) |
| +++ runtime/vm/dart_api_impl_test.cc (working copy) |
| @@ -2822,6 +2822,94 @@ |
| } |
| Dart_ShutdownIsolate(); |
| } |
| + |
| + |
| +static void* RunLoopTest_InitCallback(void* data) { |
| + const char* kScriptChars = |
| + "#import('builtin');\n" |
| + "class MyIsolate extends Isolate {\n" |
| + " MyIsolate() : super() { }\n" |
| + " void main() {\n" |
| + " port.receive((message, replyTo) {\n" |
| + " if (message) {\n" |
| + " port.close();\n" |
| + " } else {\n" |
| + " throw new Exception('foo');\n" // This will make vm exit. |
| + " }\n" |
| + " });\n" |
| + " }\n" |
| + "}\n" |
| + "\n" |
| + "void main(message) {\n" |
| + " new MyIsolate().spawn().then((port) {\n" |
| + " port.call(message).close();\n" |
| + " });\n" |
| + "}\n"; |
| + |
| + Dart_EnterScope(); |
| + Dart_Handle url = Dart_NewString(TestCase::url()); |
| + Dart_Handle source = Dart_NewString(kScriptChars); |
| + Dart_Handle lib = Dart_LoadScript(url, source, library_handler); |
| + EXPECT_VALID(lib); |
| + Dart_ExitScope(); |
| + return NULL; |
| +} |
| + |
| + |
| +UNIT_TEST_CASE(RunLoop_Success) { |
| + Dart_IsolateInitCallback saved = Isolate::InitCallback(); |
| + Isolate::SetInitCallback(RunLoopTest_InitCallback); |
| + Dart_CreateIsolate(NULL, NULL); |
| + Dart_EnterScope(); |
| + |
| + Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| + EXPECT_VALID(lib); |
| + Dart_Handle result; |
| + Dart_Handle args[1]; |
| + args[0] = Dart_True(); // No exception in isolate. |
| + result = Dart_InvokeStatic(lib, |
| + Dart_NewString(""), |
| + Dart_NewString("main"), |
| + 1, |
| + args); |
| + EXPECT_VALID(result); |
| + // Start an isolate, send it one message. RunLoop will terminate. |
| + result = Dart_RunLoop(); |
| + EXPECT_VALID(result); |
| + |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + |
| + Isolate::SetInitCallback(saved); |
| +} |
| + |
| + |
| +UNIT_TEST_CASE(RunLoop_Exception) { |
| + Dart_IsolateInitCallback saved = Isolate::InitCallback(); |
| + Isolate::SetInitCallback(RunLoopTest_InitCallback); |
| + Dart_CreateIsolate(NULL, NULL); |
| + Dart_EnterScope(); |
| + |
| + Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| + EXPECT_VALID(lib); |
| + Dart_Handle result; |
| + Dart_Handle args[1]; |
| + args[0] = Dart_False(); // Causes exception in isolate. |
| + result = Dart_InvokeStatic(lib, |
| + Dart_NewString(""), |
| + Dart_NewString("main"), |
| + 1, |
| + args); |
| + EXPECT_VALID(result); |
| + result = Dart_RunLoop(); |
| + EXPECT_VALID(result); |
|
siva
2011/11/28 21:42:53
Should we verify that result is indeed an unhandle
turnidge
2011/11/29 20:46:58
It turns out that the main isolate doesn't have an
|
| + |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + |
| + Isolate::SetInitCallback(saved); |
|
siva
2011/11/28 21:42:53
The code in RunLoop_Sucess and RunLoop_Exception s
turnidge
2011/11/29 20:46:58
Done.
|
| +} |
| + |
| #endif // TARGET_ARCH_IA32. |
| } // namespace dart |