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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 9316071: Dart_PropagateError, take 2. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.h » ('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) 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
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 }
70 132
71 133
(...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3155 // We should have received the expected number of interrupts. 3217 // We should have received the expected number of interrupts.
3156 EXPECT_EQ(kInterruptCount, interrupt_count); 3218 EXPECT_EQ(kInterruptCount, interrupt_count);
3157 3219
3158 // Give the spawned thread enough time to properly exit. 3220 // Give the spawned thread enough time to properly exit.
3159 Isolate::SetInterruptCallback(saved); 3221 Isolate::SetInterruptCallback(saved);
3160 } 3222 }
3161 3223
3162 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3224 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3163 3225
3164 } // namespace dart 3226 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698