OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/utils.h" | 7 #include "platform/utils.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); | 53 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); |
54 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); | 54 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); |
55 EXPECT_VALID(Dart_ErrorGetException(exception)); | 55 EXPECT_VALID(Dart_ErrorGetException(exception)); |
56 | 56 |
57 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); | 57 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); |
58 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 58 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); |
59 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 59 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); |
60 } | 60 } |
61 | 61 |
62 | |
63 void PropagateErrorNative(Dart_NativeArguments args) { | |
64 Dart_EnterScope(); | |
65 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | |
66 EXPECT(Dart_IsClosure(closure)); | |
67 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); | |
68 EXPECT(Dart_IsError(result)); | |
69 result = Dart_PropagateError(result); | |
70 EXPECT_VALID(result); // We do not expect to reach here. | |
71 UNREACHABLE(); | |
72 } | |
73 | |
74 | |
75 static Dart_NativeFunction PropagateError_native_lookup( | |
76 Dart_Handle name, int argument_count) { | |
77 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); | |
78 } | |
79 | |
80 | |
81 TEST_CASE(Dart_PropagateError) { | |
82 const char* kScriptChars = | |
83 "class Test {\n" | |
84 " static void raiseCompileError() {\n" | |
85 " return badIdent;\n" | |
86 " }\n" | |
87 "\n" | |
88 " static void throwException() {\n" | |
89 " throw new Exception('myException');\n" | |
90 " }\n" | |
91 " static void nativeFunc(closure) native 'Test_nativeFunc';\n" | |
92 "\n" | |
93 " static void Func1() {\n" | |
94 " nativeFunc(() => raiseCompileError());\n" | |
95 " }\n" | |
96 "\n" | |
97 " static void Func2() {\n" | |
98 " nativeFunc(() => throwException());\n" | |
99 " }\n" | |
100 "}\n"; | |
101 Dart_Handle lib = TestCase::LoadTestScript( | |
102 kScriptChars, &PropagateError_native_lookup); | |
103 Dart_Handle result; | |
104 | |
105 result = Dart_InvokeStatic(lib, | |
106 Dart_NewString("Test"), | |
107 Dart_NewString("Func1"), | |
108 0, | |
109 NULL); | |
110 EXPECT(Dart_IsError(result)); | |
111 EXPECT(!Dart_ErrorHasException(result)); | |
112 EXPECT_SUBSTRING("badIdent", Dart_GetError(result)); | |
113 | |
114 result = Dart_InvokeStatic(lib, | |
115 Dart_NewString("Test"), | |
116 Dart_NewString("Func2"), | |
117 0, | |
118 NULL); | |
119 EXPECT(Dart_IsError(result)); | |
120 EXPECT(Dart_ErrorHasException(result)); | |
121 EXPECT_SUBSTRING("myException", Dart_GetError(result)); | |
122 } | |
123 | |
124 #endif | 62 #endif |
125 | 63 |
126 | 64 |
127 TEST_CASE(Dart_Error) { | 65 TEST_CASE(Dart_Error) { |
128 Dart_Handle error = Dart_Error("An %s", "error"); | 66 Dart_Handle error = Dart_Error("An %s", "error"); |
129 EXPECT(Dart_IsError(error)); | 67 EXPECT(Dart_IsError(error)); |
130 EXPECT_STREQ("An error", Dart_GetError(error)); | 68 EXPECT_STREQ("An error", Dart_GetError(error)); |
131 } | 69 } |
132 | 70 |
133 | 71 |
(...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3217 // We should have received the expected number of interrupts. | 3155 // We should have received the expected number of interrupts. |
3218 EXPECT_EQ(kInterruptCount, interrupt_count); | 3156 EXPECT_EQ(kInterruptCount, interrupt_count); |
3219 | 3157 |
3220 // Give the spawned thread enough time to properly exit. | 3158 // Give the spawned thread enough time to properly exit. |
3221 Isolate::SetInterruptCallback(saved); | 3159 Isolate::SetInterruptCallback(saved); |
3222 } | 3160 } |
3223 | 3161 |
3224 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3162 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
3225 | 3163 |
3226 } // namespace dart | 3164 } // namespace dart |
OLD | NEW |