Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1323)

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 8659012: Add Dart API scoping around the call to Dart_HandleMessage. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
===================================================================
--- runtime/vm/dart_api_impl_test.cc (revision 1902)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -2822,6 +2822,80 @@
}
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"
+ " throw new Exception('MakeVMExit');\n"
+ " } else {\n"
+ " replyTo.call('hello');\n"
+ " port.close();\n"
+ " }\n"
+ " });\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "void main(message) {\n"
+ " new MyIsolate().spawn().then((port) {\n"
+ " port.call(message).receive((message, replyTo) {\n"
+ " if (message != 'hello') throw new Exception('ShouldNotHappen');\n"
+ " });\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;
+}
+
+
+// Common code for RunLoop_Success/RunLoop_Failure.
+static void RunLoopTest(bool throw_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] = (throw_exception ? Dart_True() : Dart_False());
+ result = Dart_InvokeStatic(lib,
+ Dart_NewString(""),
+ Dart_NewString("main"),
+ 1,
+ args);
+ EXPECT_VALID(result);
+ result = Dart_RunLoop();
+ EXPECT_VALID(result);
+
+ Dart_ExitScope();
+ Dart_ShutdownIsolate();
+
+ Isolate::SetInitCallback(saved);
+}
+
+
+UNIT_TEST_CASE(RunLoop_Success) {
+ RunLoopTest(false);
+}
+
+
+UNIT_TEST_CASE(RunLoop_Exception) {
+ RunLoopTest(true);
+}
+
#endif // TARGET_ARCH_IA32.
} // namespace dart
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698