Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/thread.h" | 10 #include "vm/thread.h" |
| (...skipping 2877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2888 Dart_Handle result = Dart_InvokeStatic(lib, | 2888 Dart_Handle result = Dart_InvokeStatic(lib, |
| 2889 Dart_NewString(""), | 2889 Dart_NewString(""), |
| 2890 Dart_NewString("main"), | 2890 Dart_NewString("main"), |
| 2891 0, | 2891 0, |
| 2892 NULL); | 2892 NULL); |
| 2893 EXPECT(Dart_IsError(result)); | 2893 EXPECT(Dart_IsError(result)); |
| 2894 EXPECT(Dart_ErrorHasException(result)); | 2894 EXPECT(Dart_ErrorHasException(result)); |
| 2895 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", | 2895 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", |
| 2896 Dart_GetError(result)); | 2896 Dart_GetError(result)); |
| 2897 | 2897 |
| 2898 // Tell the other thread that we are done. | 2898 // Tell the other thread that we are done. |
|
Ivan Posva
2011/12/19 16:27:50
This block should move after the isolate has been
Søren Gjesse
2011/12/20 09:21:26
Done.
| |
| 2899 { | 2899 { |
| 2900 MonitorLocker ml(sync); | 2900 MonitorLocker ml(sync); |
| 2901 shared_isolate = NULL; | 2901 shared_isolate = NULL; |
| 2902 ml.Notify(); | 2902 ml.Notify(); |
| 2903 } | 2903 } |
| 2904 | 2904 |
| 2905 Dart_ExitScope(); | 2905 Dart_ExitScope(); |
| 2906 Dart_ShutdownIsolate(); | 2906 Dart_ShutdownIsolate(); |
| 2907 } | 2907 } |
| 2908 | 2908 |
| 2909 | 2909 |
| 2910 // This callback handles isolate interrupts for the IsolateInterrupt | 2910 // This callback handles isolate interrupts for the IsolateInterrupt |
| 2911 // test. It ignores the first two interrupts and throws an exception | 2911 // test. It ignores the first two interrupts and throws an exception |
| 2912 // on the third interrupt. | 2912 // on the third interrupt. |
| 2913 static int interrupt_count = 0; | 2913 static int interrupt_count = 0; |
| 2914 static bool IsolateInterruptTestCallback() { | 2914 static bool IsolateInterruptTestCallback() { |
| 2915 interrupt_count++; | 2915 { |
| 2916 MonitorLocker ml(sync); | |
| 2917 interrupt_count++; | |
| 2918 ml.Notify(); | |
| 2919 } | |
| 2916 OS::Print(" =========== Interrupt callback called #%d\n", interrupt_count); | 2920 OS::Print(" =========== Interrupt callback called #%d\n", interrupt_count); |
| 2917 if (interrupt_count >= 3) { | 2921 if (interrupt_count >= 3) { |
| 2918 Dart_EnterScope(); | 2922 Dart_EnterScope(); |
| 2919 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); | 2923 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| 2920 EXPECT_VALID(lib); | 2924 EXPECT_VALID(lib); |
| 2921 Dart_Handle exc = Dart_NewString("foo"); | 2925 Dart_Handle exc = Dart_NewString("foo"); |
| 2922 EXPECT_VALID(exc); | 2926 EXPECT_VALID(exc); |
| 2923 Dart_Handle result = Dart_ThrowException(exc); | 2927 Dart_Handle result = Dart_ThrowException(exc); |
| 2924 EXPECT_VALID(result); | 2928 EXPECT_VALID(result); |
| 2925 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. | 2929 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2941 MonitorLocker ml(sync); | 2945 MonitorLocker ml(sync); |
| 2942 // Wait for the other isolate to start. | 2946 // Wait for the other isolate to start. |
| 2943 while (shared_isolate == NULL) { | 2947 while (shared_isolate == NULL) { |
| 2944 ml.Wait(); | 2948 ml.Wait(); |
| 2945 } | 2949 } |
| 2946 } | 2950 } |
| 2947 | 2951 |
| 2948 // Send three interrupts to the other isolate. The first two allow | 2952 // Send three interrupts to the other isolate. The first two allow |
| 2949 // execution to continue. The third causes an exception in the | 2953 // execution to continue. The third causes an exception in the |
| 2950 // isolate. | 2954 // isolate. |
| 2951 Dart_InterruptIsolate(shared_isolate); | 2955 for (int i = 0; i < 3; i++) { |
| 2952 OS::Sleep(5); | 2956 Dart_InterruptIsolate(shared_isolate); |
| 2953 Dart_InterruptIsolate(shared_isolate); | 2957 OS::Sleep(5); |
| 2954 OS::Sleep(5); | 2958 { |
| 2955 Dart_InterruptIsolate(shared_isolate); | 2959 MonitorLocker ml(sync); |
| 2960 // Wait for interrupt_count to be increased. | |
| 2961 while (interrupt_count == i) { | |
| 2962 ml.Wait(); | |
| 2963 } | |
| 2964 } | |
| 2965 } | |
| 2956 | 2966 |
| 2957 { | 2967 { |
| 2958 MonitorLocker ml(sync); | 2968 MonitorLocker ml(sync); |
| 2959 // Wait for our isolate to finish. | 2969 // Wait for our isolate to finish. |
| 2960 while (shared_isolate != NULL) { | 2970 while (shared_isolate != NULL) { |
| 2961 ml.Wait(); | 2971 ml.Wait(); |
| 2962 } | 2972 } |
| 2963 } | 2973 } |
| 2964 | 2974 |
| 2965 // We should have received 3 interrupts. | 2975 // We should have received 3 interrupts. |
| 2966 EXPECT_EQ(3, interrupt_count); | 2976 EXPECT_EQ(3, interrupt_count); |
| 2967 | 2977 |
| 2968 // Give the spawned thread enough time to properly exit. | 2978 // Give the spawned thread enough time to properly exit. |
| 2969 OS::Sleep(20); | 2979 OS::Sleep(20); |
| 2970 Isolate::SetInterruptCallback(saved); | 2980 Isolate::SetInterruptCallback(saved); |
| 2971 } | 2981 } |
| 2972 | 2982 |
| 2973 #endif // TARGET_ARCH_IA32. | 2983 #endif // TARGET_ARCH_IA32. |
| 2974 | 2984 |
| 2975 } // namespace dart | 2985 } // namespace dart |
| OLD | NEW |