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 | |
62 #endif | 124 #endif |
63 | 125 |
64 | 126 |
65 TEST_CASE(Dart_Error) { | 127 TEST_CASE(Dart_Error) { |
66 Dart_Handle error = Dart_Error("An %s", "error"); | 128 Dart_Handle error = Dart_Error("An %s", "error"); |
67 EXPECT(Dart_IsError(error)); | 129 EXPECT(Dart_IsError(error)); |
68 EXPECT_STREQ("An error", Dart_GetError(error)); | 130 EXPECT_STREQ("An error", Dart_GetError(error)); |
69 } | 131 } |
siva
2012/01/31 00:52:34
Missing blank lines?
turnidge
2012/01/31 21:56:31
Added lines.
| |
70 | |
71 | |
72 TEST_CASE(Null) { | 132 TEST_CASE(Null) { |
73 Dart_Handle null = Dart_Null(); | 133 Dart_Handle null = Dart_Null(); |
74 EXPECT_VALID(null); | 134 EXPECT_VALID(null); |
75 EXPECT(Dart_IsNull(null)); | 135 EXPECT(Dart_IsNull(null)); |
76 | 136 |
77 Dart_Handle str = Dart_NewString("test"); | 137 Dart_Handle str = Dart_NewString("test"); |
78 EXPECT_VALID(str); | 138 EXPECT_VALID(str); |
79 EXPECT(!Dart_IsNull(str)); | 139 EXPECT(!Dart_IsNull(str)); |
80 } | 140 } |
81 | 141 |
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3009 // We should have received the expected number of interrupts. | 3069 // We should have received the expected number of interrupts. |
3010 EXPECT_EQ(kInterruptCount, interrupt_count); | 3070 EXPECT_EQ(kInterruptCount, interrupt_count); |
3011 | 3071 |
3012 // Give the spawned thread enough time to properly exit. | 3072 // Give the spawned thread enough time to properly exit. |
3013 Isolate::SetInterruptCallback(saved); | 3073 Isolate::SetInterruptCallback(saved); |
3014 } | 3074 } |
3015 | 3075 |
3016 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3076 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
3017 | 3077 |
3018 } // namespace dart | 3078 } // namespace dart |
OLD | NEW |