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

Unified Diff: runtime/vm/native_entry_test.cc

Issue 11468016: Rename GET_NATIVE_ARGUMENT macro to GET_NON_NULL_NATIVE_ARGUMENT. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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/native_entry_test.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/native_entry_test.cc
===================================================================
--- runtime/vm/native_entry_test.cc (revision 15918)
+++ runtime/vm/native_entry_test.cc (working copy)
@@ -6,6 +6,7 @@
#include "vm/assembler.h"
#include "vm/code_patcher.h"
+#include "vm/dart_api_impl.h"
#include "vm/native_entry.h"
#include "vm/object.h"
#include "vm/stack_frame.h"
@@ -55,6 +56,38 @@
}
+// Test for accepting null arguments in native function.
+// Arg0-4: 5 smis or null.
+// Result: a smi representing the sum of all non-null arguments.
+void TestNonNullSmiSum(Dart_NativeArguments args) {
+ Dart_EnterScope();
+ Isolate* isolate = Isolate::Current();
+ int64_t result = 0;
+ int arg_count = Dart_GetNativeArgumentCount(args);
+ // Test the lower level macro GET_NATIVE_ARGUMENT.
+ NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
+ for (int i = 0; i < arg_count; i++) {
+ Dart_Handle arg = Dart_GetNativeArgument(args, i);
+ GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i));
+ EXPECT(argument.IsInteger()); // May be null.
+ EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null.
+ int64_t arg_value = -1;
+ if (argument.IsNull()) {
+ EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value),
+ "Dart_IntegerToInt64 expects argument 'integer' "
+ "to be non-null.");
+ } else {
+ EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value));
+ EXPECT_EQ(arg_value, argument.AsInt64Value());
+ // Ignoring overflow in the addition below.
+ result += arg_value;
+ }
+ }
+ Dart_SetReturnValue(args, Dart_NewInteger(result));
+ Dart_ExitScope();
+}
+
+
// Test code patching.
void TestStaticCallPatching(Dart_NativeArguments args) {
Dart_EnterScope();
« no previous file with comments | « runtime/vm/native_entry_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698