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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/native_entry_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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));
72 EXPECT(argument.IsInteger()); // May be null.
73 EXPECT_EQ(Api::UnwrapHandle(arg), argument.raw()); // May be null.
74 int64_t arg_value = -1;
75 if (argument.IsNull()) {
76 EXPECT_ERROR(Dart_IntegerToInt64(arg, &arg_value),
77 "Dart_IntegerToInt64 expects argument 'integer' "
78 "to be non-null.");
79 } else {
80 EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value));
81 EXPECT_EQ(arg_value, argument.AsInt64Value());
82 // Ignoring overflow in the addition below.
83 result += arg_value;
84 }
85 }
86 Dart_SetReturnValue(args, Dart_NewInteger(result));
87 Dart_ExitScope();
88 }
89
90
58 // Test code patching. 91 // Test code patching.
59 void TestStaticCallPatching(Dart_NativeArguments args) { 92 void TestStaticCallPatching(Dart_NativeArguments args) {
60 Dart_EnterScope(); 93 Dart_EnterScope();
61 DartFrameIterator iterator; 94 DartFrameIterator iterator;
62 iterator.NextFrame(); // Skip native call. 95 iterator.NextFrame(); // Skip native call.
63 StackFrame* static_caller_frame = iterator.NextFrame(); 96 StackFrame* static_caller_frame = iterator.NextFrame();
64 uword target_address = 97 uword target_address =
65 CodePatcher::GetStaticCallTargetAt(static_caller_frame->pc()); 98 CodePatcher::GetStaticCallTargetAt(static_caller_frame->pc());
66 const Code& code = Code::Handle(static_caller_frame->LookupDartCode()); 99 const Code& code = Code::Handle(static_caller_frame->LookupDartCode());
67 const Function& target_function = 100 const Function& target_function =
68 Function::Handle(code.GetStaticCallTargetFunctionAt( 101 Function::Handle(code.GetStaticCallTargetFunctionAt(
69 static_caller_frame->pc())); 102 static_caller_frame->pc()));
70 EXPECT(String::Handle(target_function.name()). 103 EXPECT(String::Handle(target_function.name()).
71 Equals(String::Handle(String::New("NativePatchStaticCall")))); 104 Equals(String::Handle(String::New("NativePatchStaticCall"))));
72 const uword function_entry_address = 105 const uword function_entry_address =
73 Code::Handle(target_function.CurrentCode()).EntryPoint(); 106 Code::Handle(target_function.CurrentCode()).EntryPoint();
74 EXPECT_EQ(function_entry_address, target_address); 107 EXPECT_EQ(function_entry_address, target_address);
75 Dart_ExitScope(); 108 Dart_ExitScope();
76 } 109 }
77 110
78 } // namespace dart 111 } // namespace dart
OLDNEW
« 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