Chromium Code Reviews| 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/native_entry.h" | 10 #include "vm/native_entry.h" |
| 10 #include "vm/object.h" | 11 #include "vm/object.h" |
| 11 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
| 12 #include "vm/stub_code.h" | 13 #include "vm/stub_code.h" |
| 13 #include "vm/unit_test.h" | 14 #include "vm/unit_test.h" |
| 14 | 15 |
| 15 namespace dart { | 16 namespace dart { |
| 16 | 17 |
| 17 | 18 |
| 18 // A native call for test purposes. | 19 // A native call for test purposes. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 48 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | 49 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); |
| 49 | 50 |
| 50 // Ignoring overflow in the addition below. | 51 // Ignoring overflow in the addition below. |
| 51 result += arg_value; | 52 result += arg_value; |
| 52 } | 53 } |
| 53 Dart_SetReturnValue(args, Dart_NewInteger(result)); | 54 Dart_SetReturnValue(args, Dart_NewInteger(result)); |
| 54 Dart_ExitScope(); | 55 Dart_ExitScope(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 | 58 |
| 59 // Test for accepting null arguments in native function. | |
| 60 // Arg0-4: 5 smis or null. | |
| 61 // Result: a smi representing the sum of all non-null arguments. | |
| 62 void TestNonNullSmiSum(Dart_NativeArguments args) { | |
| 63 Dart_EnterScope(); | |
| 64 Isolate* isolate = Isolate::Current(); | |
| 65 int64_t result = 0; | |
| 66 int arg_count = Dart_GetNativeArgumentCount(args); | |
| 67 // Test the lower level macro GET_NATIVE_ARGUMENT. | |
| 68 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | |
| 69 for (int i = 0; i < arg_count; i++) { | |
| 70 Dart_Handle arg = Dart_GetNativeArgument(args, i); | |
| 71 GET_NATIVE_ARGUMENT(Integer, argument, arguments->NativeArgAt(i)); | |
|
siva
2012/12/07 02:28:40
EXPECT(argument.IsInteger());
Does that make sens
regis
2012/12/10 17:58:42
Done.
| |
| 72 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null. | |
| 73 int64_t arg_value = -1; | |
| 74 if (argument.IsNull()) { | |
| 75 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value), | |
| 76 "Dart_IntegerToInt64 expects argument 'integer' " | |
| 77 "to be non-null."); | |
| 78 } else { | |
| 79 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value)); | |
| 80 EXPECT_EQ(arg_value, argument.AsInt64Value()); | |
| 81 // Ignoring overflow in the addition below. | |
| 82 result += arg_value; | |
| 83 } | |
| 84 } | |
| 85 Dart_SetReturnValue(args, Dart_NewInteger(result)); | |
| 86 Dart_ExitScope(); | |
| 87 } | |
| 88 | |
| 89 | |
| 58 // Test code patching. | 90 // Test code patching. |
| 59 void TestStaticCallPatching(Dart_NativeArguments args) { | 91 void TestStaticCallPatching(Dart_NativeArguments args) { |
| 60 Dart_EnterScope(); | 92 Dart_EnterScope(); |
| 61 DartFrameIterator iterator; | 93 DartFrameIterator iterator; |
| 62 iterator.NextFrame(); // Skip native call. | 94 iterator.NextFrame(); // Skip native call. |
| 63 StackFrame* static_caller_frame = iterator.NextFrame(); | 95 StackFrame* static_caller_frame = iterator.NextFrame(); |
| 64 uword target_address = | 96 uword target_address = |
| 65 CodePatcher::GetStaticCallTargetAt(static_caller_frame->pc()); | 97 CodePatcher::GetStaticCallTargetAt(static_caller_frame->pc()); |
| 66 const Code& code = Code::Handle(static_caller_frame->LookupDartCode()); | 98 const Code& code = Code::Handle(static_caller_frame->LookupDartCode()); |
| 67 const Function& target_function = | 99 const Function& target_function = |
| 68 Function::Handle(code.GetStaticCallTargetFunctionAt( | 100 Function::Handle(code.GetStaticCallTargetFunctionAt( |
| 69 static_caller_frame->pc())); | 101 static_caller_frame->pc())); |
| 70 EXPECT(String::Handle(target_function.name()). | 102 EXPECT(String::Handle(target_function.name()). |
| 71 Equals(String::Handle(String::New("NativePatchStaticCall")))); | 103 Equals(String::Handle(String::New("NativePatchStaticCall")))); |
| 72 const uword function_entry_address = | 104 const uword function_entry_address = |
| 73 Code::Handle(target_function.CurrentCode()).EntryPoint(); | 105 Code::Handle(target_function.CurrentCode()).EntryPoint(); |
| 74 EXPECT_EQ(function_entry_address, target_address); | 106 EXPECT_EQ(function_entry_address, target_address); |
| 75 Dart_ExitScope(); | 107 Dart_ExitScope(); |
| 76 } | 108 } |
| 77 | 109 |
| 78 } // namespace dart | 110 } // namespace dart |
| OLD | NEW |