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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 18862004: Call shutdown callback before the isolate is destroyed (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months 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/vm/dart_api_impl.cc ('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
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index c030ea60f6f51342d01b69107f37c9b70cbc0f04..abb0e8e01a9949859f80b2f85f2729ae2bfa6f8f 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -7079,6 +7079,72 @@ UNIT_TEST_CASE(IsolateShutdown) {
Isolate::SetShutdownCallback(saved);
}
+static int64_t add_result = 0;
+static void IsolateShutdownRunDartCodeTestCallback(void* callback_data) {
+ Dart_EnterScope();
+ Dart_Handle lib = Dart_RootLibrary();
+ EXPECT_VALID(lib);
+ Dart_Handle arg1 = Dart_NewInteger(90);
+ EXPECT_VALID(arg1);
+ Dart_Handle arg2 = Dart_NewInteger(9);
+ EXPECT_VALID(arg2);
+ Dart_Handle dart_args[2] = { arg1, arg2 };
+ Dart_Handle result = Dart_Invoke(lib, NewString("add"), 2, dart_args);
+ EXPECT_VALID(result);
+ result = Dart_IntegerToInt64(result, &add_result);
+ EXPECT_VALID(result);
+ Dart_ExitScope();
+}
+
+UNIT_TEST_CASE(IsolateShutdownRunDartCode) {
+ const char* kScriptChars =
+ "int add(int a, int b) {\n"
+ " return a + b;\n"
+ "}\n"
+ "\n"
+ "void main() {\n"
+ " add(4, 5);\n"
+ "}\n";
+
+ // Create an isolate.
+ char* err;
+ Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL,
+ bin::snapshot_buffer,
+ NULL, &err);
+ if (isolate == NULL) {
+ OS::Print("Creation of isolate failed '%s'\n", err);
+ free(err);
+ }
+ EXPECT(isolate != NULL);
+
+ Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback);
+
+ {
+ Dart_EnterScope();
+ Dart_Handle url = NewString(TestCase::url());
+ Dart_Handle source = NewString(kScriptChars);
+ Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
+ EXPECT_VALID(result);
+ Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
+ EXPECT_VALID(lib);
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+ Dart_ExitScope();
+ }
+
+
+ // The shutdown callback has not been called.
+ EXPECT_EQ(0, add_result);
+
+ EXPECT(isolate != NULL);
+
+ // Shutdown the isolate.
+ Dart_ShutdownIsolate();
+
+ // The shutdown callback has been called and ran Dart code.
+ EXPECT_EQ(99, add_result);
+}
+
static int64_t GetValue(Dart_Handle arg) {
EXPECT_VALID(arg);
EXPECT(Dart_IsInteger(arg));
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698