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" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
13 #include "vm/stub_code.h" | 13 #include "vm/stub_code.h" |
14 #include "vm/unit_test.h" | 14 #include "vm/unit_test.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 | |
19 // A native call for test purposes. | 18 // A native call for test purposes. |
20 // Arg0: a smi. | 19 // Arg0: a smi. |
21 // Arg1: a smi. | 20 // Arg1: a smi. |
22 // Result: a smi representing arg0 - arg1. | 21 // Result: a smi representing arg0 - arg1. |
23 void TestSmiSub(Dart_NativeArguments args) { | 22 void TestSmiSub(Dart_NativeArguments args) { |
24 Dart_Handle left = Dart_GetNativeArgument(args, 0); | 23 Dart_Handle left = Dart_GetNativeArgument(args, 0); |
25 Dart_Handle right = Dart_GetNativeArgument(args, 1); | 24 Dart_Handle right = Dart_GetNativeArgument(args, 1); |
26 int64_t left_value = -1; | 25 int64_t left_value = -1; |
27 int64_t right_value = -1; | 26 int64_t right_value = -1; |
28 EXPECT_VALID(Dart_IntegerToInt64(left, &left_value)); | 27 EXPECT_VALID(Dart_IntegerToInt64(left, &left_value)); |
29 EXPECT_VALID(Dart_IntegerToInt64(right, &right_value)); | 28 EXPECT_VALID(Dart_IntegerToInt64(right, &right_value)); |
30 | 29 |
31 // Ignoring overflow in the calculation below. | 30 // Ignoring overflow in the calculation below. |
32 int64_t result = left_value - right_value; | 31 int64_t result = left_value - right_value; |
33 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 32 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
34 } | 33 } |
35 | 34 |
36 | |
37 // A native call for test purposes. | 35 // A native call for test purposes. |
38 // Arg0-4: 5 smis. | 36 // Arg0-4: 5 smis. |
39 // Result: a smi representing the sum of all arguments. | 37 // Result: a smi representing the sum of all arguments. |
40 void TestSmiSum(Dart_NativeArguments args) { | 38 void TestSmiSum(Dart_NativeArguments args) { |
41 int64_t result = 0; | 39 int64_t result = 0; |
42 int arg_count = Dart_GetNativeArgumentCount(args); | 40 int arg_count = Dart_GetNativeArgumentCount(args); |
43 for (int i = 0; i < arg_count; i++) { | 41 for (int i = 0; i < arg_count; i++) { |
44 Dart_Handle arg = Dart_GetNativeArgument(args, i); | 42 Dart_Handle arg = Dart_GetNativeArgument(args, i); |
45 int64_t arg_value = -1; | 43 int64_t arg_value = -1; |
46 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | 44 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); |
47 | 45 |
48 // Ignoring overflow in the addition below. | 46 // Ignoring overflow in the addition below. |
49 result += arg_value; | 47 result += arg_value; |
50 } | 48 } |
51 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 49 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
52 } | 50 } |
53 | 51 |
54 | |
55 // Test for accepting null arguments in native function. | 52 // Test for accepting null arguments in native function. |
56 // Arg0-4: 5 smis or null. | 53 // Arg0-4: 5 smis or null. |
57 // Result: a smi representing the sum of all non-null arguments. | 54 // Result: a smi representing the sum of all non-null arguments. |
58 void TestNonNullSmiSum(Dart_NativeArguments args) { | 55 void TestNonNullSmiSum(Dart_NativeArguments args) { |
59 int64_t result = 0; | 56 int64_t result = 0; |
60 int arg_count = Dart_GetNativeArgumentCount(args); | 57 int arg_count = Dart_GetNativeArgumentCount(args); |
61 // Test the lower level macro GET_NATIVE_ARGUMENT. | 58 // Test the lower level macro GET_NATIVE_ARGUMENT. |
62 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 59 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
63 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. | 60 Zone* zone = Thread::Current()->zone(); // Used by GET_NATIVE_ARGUMENT. |
64 for (int i = 0; i < arg_count; i++) { | 61 for (int i = 0; i < arg_count; i++) { |
(...skipping 10 matching lines...) Expand all Loading... |
75 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | 72 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); |
76 EXPECT_EQ(arg_value, argument.AsInt64Value()); | 73 EXPECT_EQ(arg_value, argument.AsInt64Value()); |
77 // Ignoring overflow in the addition below. | 74 // Ignoring overflow in the addition below. |
78 result += arg_value; | 75 result += arg_value; |
79 } | 76 } |
80 } | 77 } |
81 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 78 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
82 } | 79 } |
83 | 80 |
84 } // namespace dart | 81 } // namespace dart |
OLD | NEW |