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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 Dart_NewString(""), 2815 Dart_NewString(""),
2816 Dart_NewString("main"), 2816 Dart_NewString("main"),
2817 0, 2817 0,
2818 NULL); 2818 NULL);
2819 EXPECT_VALID(result); 2819 EXPECT_VALID(result);
2820 2820
2821 Dart_ExitScope(); // Exit the Dart API scope. 2821 Dart_ExitScope(); // Exit the Dart API scope.
2822 } 2822 }
2823 Dart_ShutdownIsolate(); 2823 Dart_ShutdownIsolate();
2824 } 2824 }
2825
2826
2827 static void* RunLoopTest_InitCallback(void* data) {
2828 const char* kScriptChars =
2829 "#import('builtin');\n"
2830 "class MyIsolate extends Isolate {\n"
2831 " MyIsolate() : super() { }\n"
2832 " void main() {\n"
2833 " port.receive((message, replyTo) {\n"
2834 " if (message) {\n"
2835 " port.close();\n"
2836 " } else {\n"
2837 " throw new Exception('foo');\n" // This will make vm exit.
2838 " }\n"
2839 " });\n"
2840 " }\n"
2841 "}\n"
2842 "\n"
2843 "void main(message) {\n"
2844 " new MyIsolate().spawn().then((port) {\n"
2845 " port.call(message).close();\n"
2846 " });\n"
2847 "}\n";
2848
2849 Dart_EnterScope();
2850 Dart_Handle url = Dart_NewString(TestCase::url());
2851 Dart_Handle source = Dart_NewString(kScriptChars);
2852 Dart_Handle lib = Dart_LoadScript(url, source, library_handler);
2853 EXPECT_VALID(lib);
2854 Dart_ExitScope();
2855 return NULL;
2856 }
2857
2858
2859 UNIT_TEST_CASE(RunLoop_Success) {
2860 Dart_IsolateInitCallback saved = Isolate::InitCallback();
2861 Isolate::SetInitCallback(RunLoopTest_InitCallback);
2862 Dart_CreateIsolate(NULL, NULL);
2863 Dart_EnterScope();
2864
2865 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url()));
2866 EXPECT_VALID(lib);
2867 Dart_Handle result;
2868 Dart_Handle args[1];
2869 args[0] = Dart_True(); // No exception in isolate.
2870 result = Dart_InvokeStatic(lib,
2871 Dart_NewString(""),
2872 Dart_NewString("main"),
2873 1,
2874 args);
2875 EXPECT_VALID(result);
2876 // Start an isolate, send it one message. RunLoop will terminate.
2877 result = Dart_RunLoop();
2878 EXPECT_VALID(result);
2879
2880 Dart_ExitScope();
2881 Dart_ShutdownIsolate();
2882
2883 Isolate::SetInitCallback(saved);
2884 }
2885
2886
2887 UNIT_TEST_CASE(RunLoop_Exception) {
2888 Dart_IsolateInitCallback saved = Isolate::InitCallback();
2889 Isolate::SetInitCallback(RunLoopTest_InitCallback);
2890 Dart_CreateIsolate(NULL, NULL);
2891 Dart_EnterScope();
2892
2893 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url()));
2894 EXPECT_VALID(lib);
2895 Dart_Handle result;
2896 Dart_Handle args[1];
2897 args[0] = Dart_False(); // Causes exception in isolate.
2898 result = Dart_InvokeStatic(lib,
2899 Dart_NewString(""),
2900 Dart_NewString("main"),
2901 1,
2902 args);
2903 EXPECT_VALID(result);
2904 result = Dart_RunLoop();
2905 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
2906
2907 Dart_ExitScope();
2908 Dart_ShutdownIsolate();
2909
2910 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.
2911 }
2912
2825 #endif // TARGET_ARCH_IA32. 2913 #endif // TARGET_ARCH_IA32.
2826 2914
2827 } // namespace dart 2915 } // namespace dart
OLDNEW
« 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