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

Side by Side Diff: vm/native_entry_test.cc

Issue 10874072: Use the return value of vm native methods to set the return value, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 months 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
« vm/native_entry.h ('K') | « vm/native_entry.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/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 // A native call for test purposes. 45 // A native call for test purposes.
46 // Arg0: a smi. 46 // Arg0: a smi.
47 // Arg1: a smi. 47 // Arg1: a smi.
48 // Result: a smi representing arg0 - arg1. 48 // Result: a smi representing arg0 - arg1.
49 DEFINE_NATIVE_ENTRY(TestSmiSub, 2) { 49 DEFINE_NATIVE_ENTRY(TestSmiSub, 2) {
50 const Smi& left = Smi::CheckedHandle(arguments->At(0)); 50 const Smi& left = Smi::CheckedHandle(arguments->At(0));
51 const Smi& right = Smi::CheckedHandle(arguments->At(1)); 51 const Smi& right = Smi::CheckedHandle(arguments->At(1));
52 // Ignoring overflow in the calculation below. 52 // Ignoring overflow in the calculation below.
53 intptr_t result = left.Value() - right.Value(); 53 intptr_t result = left.Value() - right.Value();
54 arguments->SetReturn(Smi::Handle(Smi::New(result))); 54 return Smi::New(result);
55 } 55 }
56 56
57 57
58 // A native call for test purposes. 58 // A native call for test purposes.
59 // Arg0-4: 5 smis. 59 // Arg0-4: 5 smis.
60 // Result: a smi representing the sum of all arguments. 60 // Result: a smi representing the sum of all arguments.
61 DEFINE_NATIVE_ENTRY(TestSmiSum, 5) { 61 DEFINE_NATIVE_ENTRY(TestSmiSum, 5) {
62 intptr_t result = 0; 62 intptr_t result = 0;
63 for (int i = 0; i < arguments->Count(); i++) { 63 for (int i = 0; i < arguments->Count(); i++) {
64 const Smi& arg = Smi::CheckedHandle(arguments->At(i)); 64 const Smi& arg = Smi::CheckedHandle(arguments->At(i));
65 // Ignoring overflow in the addition below. 65 // Ignoring overflow in the addition below.
66 result += arg.Value(); 66 result += arg.Value();
67 } 67 }
68 arguments->SetReturn(Smi::Handle(Smi::New(result))); 68 return Smi::New(result);
69 } 69 }
70 70
71 71
72 // Test code patching. 72 // Test code patching.
73 DEFINE_NATIVE_ENTRY(TestStaticCallPatching, 0) { 73 DEFINE_NATIVE_ENTRY(TestStaticCallPatching, 0) {
74 uword target_address = 0; 74 uword target_address = 0;
75 Function& target_function = Function::Handle(); 75 Function& target_function = Function::Handle();
76 DartFrameIterator iterator; 76 DartFrameIterator iterator;
77 iterator.NextFrame(); // Skip native call. 77 iterator.NextFrame(); // Skip native call.
78 StackFrame* static_caller_frame = iterator.NextFrame(); 78 StackFrame* static_caller_frame = iterator.NextFrame();
79 CodePatcher::GetStaticCallAt(static_caller_frame->pc(), 79 CodePatcher::GetStaticCallAt(static_caller_frame->pc(),
80 &target_function, 80 &target_function,
81 &target_address); 81 &target_address);
82 EXPECT(String::Handle(target_function.name()). 82 EXPECT(String::Handle(target_function.name()).
83 Equals(String::Handle(String::New("NativePatchStaticCall")))); 83 Equals(String::Handle(String::New("NativePatchStaticCall"))));
84 const uword function_entry_address = 84 const uword function_entry_address =
85 Code::Handle(target_function.CurrentCode()).EntryPoint(); 85 Code::Handle(target_function.CurrentCode()).EntryPoint();
86 EXPECT_EQ(function_entry_address, target_address); 86 EXPECT_EQ(function_entry_address, target_address);
87 return Object::null();
87 } 88 }
88 89
89 } // namespace dart 90 } // namespace dart
OLDNEW
« vm/native_entry.h ('K') | « vm/native_entry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698