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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int64_t result = 0; | 59 int64_t result = 0; |
60 int arg_count = Dart_GetNativeArgumentCount(args); | 60 int arg_count = Dart_GetNativeArgumentCount(args); |
61 // Test the lower level macro GET_NATIVE_ARGUMENT. | 61 // Test the lower level macro GET_NATIVE_ARGUMENT. |
62 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 62 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
63 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. | 63 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. |
64 for (int i = 0; i < arg_count; i++) { | 64 for (int i = 0; i < arg_count; i++) { |
65 Dart_Handle arg = Dart_GetNativeArgument(args, i); | 65 Dart_Handle arg = Dart_GetNativeArgument(args, i); |
66 GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i)); | 66 GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i)); |
67 EXPECT(argument.IsInteger()); // May be null. | 67 EXPECT(argument.IsInteger()); // May be null. |
68 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null. | 68 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null. |
69 int64_t arg_value = -1; | 69 int64_t arg_value = -1; |
70 if (argument.IsNull()) { | 70 if (argument.IsNull()) { |
71 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value), | 71 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value), |
72 "Dart_IntegerToInt64 expects argument 'integer' " | 72 "Dart_IntegerToInt64 expects argument 'integer' " |
73 "to be non-null."); | 73 "to be non-null."); |
74 } else { | 74 } else { |
75 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | 75 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); |
76 EXPECT_EQ(arg_value, argument.AsInt64Value()); | 76 EXPECT_EQ(arg_value, argument.AsInt64Value()); |
77 // Ignoring overflow in the addition below. | 77 // Ignoring overflow in the addition below. |
78 result += arg_value; | 78 result += arg_value; |
79 } | 79 } |
80 } | 80 } |
81 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 81 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
82 } | 82 } |
83 | 83 |
84 } // namespace dart | 84 } // namespace dart |
OLD | NEW |