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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 1663613002: Dart_SetReturnValue now accepts and propagates error handles. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code review Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/native_arguments.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 0f8995254df1898bcb06d2a46c531e6ddc325103..9feeea4f995accda741e989c0e9a2aeb5380dff9 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -500,15 +500,29 @@ TEST_CASE(UnhandleExceptionError) {
}
+// Should we propagate the error via Dart_SetReturnValue?
+static bool use_set_return = false;
+
+// Should we propagate the error via Dart_ThrowException?
+static bool use_throw_exception = false;
+
+
void PropagateErrorNative(Dart_NativeArguments args) {
- Dart_EnterScope();
Dart_Handle closure = Dart_GetNativeArgument(args, 0);
EXPECT(Dart_IsClosure(closure));
Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL);
EXPECT(Dart_IsError(result));
- result = Dart_PropagateError(result);
- EXPECT_VALID(result); // We do not expect to reach here.
- UNREACHABLE();
+ if (use_set_return) {
+ Dart_SetReturnValue(args, result);
+ } else if (use_throw_exception) {
+ result = Dart_ThrowException(result);
+ EXPECT_VALID(result); // We do not expect to reach here.
+ UNREACHABLE();
+ } else {
+ result = Dart_PropagateError(result);
+ EXPECT_VALID(result); // We do not expect to reach here.
+ UNREACHABLE();
+ }
}
@@ -543,6 +557,38 @@ TEST_CASE(Dart_PropagateError) {
kScriptChars, &PropagateError_native_lookup);
Dart_Handle result;
+ // Use Dart_PropagateError to propagate the error.
+ use_throw_exception = false;
+ use_set_return = false;
+
+ result = Dart_Invoke(lib, NewString("Func1"), 0, NULL);
+ EXPECT(Dart_IsError(result));
+ EXPECT(!Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result));
+
+ result = Dart_Invoke(lib, NewString("Func2"), 0, NULL);
+ EXPECT(Dart_IsError(result));
+ EXPECT(Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("myException", Dart_GetError(result));
+
+ // Use Dart_SetReturnValue to propagate the error.
+ use_throw_exception = false;
+ use_set_return = true;
+
+ result = Dart_Invoke(lib, NewString("Func1"), 0, NULL);
+ EXPECT(Dart_IsError(result));
+ EXPECT(!Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result));
+
+ result = Dart_Invoke(lib, NewString("Func2"), 0, NULL);
+ EXPECT(Dart_IsError(result));
+ EXPECT(Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("myException", Dart_GetError(result));
+
+ // Use Dart_ThrowException to propagate the error.
+ use_throw_exception = true;
+ use_set_return = false;
+
result = Dart_Invoke(lib, NewString("Func1"), 0, NULL);
EXPECT(Dart_IsError(result));
EXPECT(!Dart_ErrorHasException(result));
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/native_arguments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698