OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/native_entry_test.h" | 5 #include "vm/native_entry_test.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 result += arg_value; | 49 result += arg_value; |
50 } | 50 } |
51 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 51 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 // Test for accepting null arguments in native function. | 55 // Test for accepting null arguments in native function. |
56 // Arg0-4: 5 smis or null. | 56 // Arg0-4: 5 smis or null. |
57 // Result: a smi representing the sum of all non-null arguments. | 57 // Result: a smi representing the sum of all non-null arguments. |
58 void TestNonNullSmiSum(Dart_NativeArguments args) { | 58 void TestNonNullSmiSum(Dart_NativeArguments args) { |
59 Isolate* isolate = Isolate::Current(); // Used by GET_NATIVE_ARGUMENT. | |
60 int64_t result = 0; | 59 int64_t result = 0; |
61 int arg_count = Dart_GetNativeArgumentCount(args); | 60 int arg_count = Dart_GetNativeArgumentCount(args); |
62 // Test the lower level macro GET_NATIVE_ARGUMENT. | 61 // Test the lower level macro GET_NATIVE_ARGUMENT. |
63 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 62 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
64 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. | 63 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. |
65 for (int i = 0; i < arg_count; i++) { | 64 for (int i = 0; i < arg_count; i++) { |
66 Dart_Handle arg = Dart_GetNativeArgument(args, i); | 65 Dart_Handle arg = Dart_GetNativeArgument(args, i); |
67 GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i)); | 66 GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i)); |
68 EXPECT(argument.IsInteger()); // May be null. | 67 EXPECT(argument.IsInteger()); // May be null. |
69 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null. | 68 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null. |
70 int64_t arg_value = -1; | 69 int64_t arg_value = -1; |
71 if (argument.IsNull()) { | 70 if (argument.IsNull()) { |
72 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value), | 71 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value), |
73 "Dart_IntegerToInt64 expects argument 'integer' " | 72 "Dart_IntegerToInt64 expects argument 'integer' " |
74 "to be non-null."); | 73 "to be non-null."); |
75 } else { | 74 } else { |
76 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | 75 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); |
77 EXPECT_EQ(arg_value, argument.AsInt64Value()); | 76 EXPECT_EQ(arg_value, argument.AsInt64Value()); |
78 // Ignoring overflow in the addition below. | 77 // Ignoring overflow in the addition below. |
79 result += arg_value; | 78 result += arg_value; |
80 } | 79 } |
81 } | 80 } |
82 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 81 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
83 } | 82 } |
84 | 83 |
85 } // namespace dart | 84 } // namespace dart |
OLD | NEW |