14f614da12
based on Siva's earlier suggestion (he actually suggested putting it in the generated stub, which I haven't done). Added SetReturnUnsafe and use it exactly one place so far. Review URL: https://chromiumcodereview.appspot.com//10874072 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11633 260f80e4-7a28-3924-810f-c04153c831b5
78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/native_entry_test.h"
|
|
|
|
#include "vm/assembler.h"
|
|
#include "vm/code_patcher.h"
|
|
#include "vm/native_entry.h"
|
|
#include "vm/object.h"
|
|
#include "vm/stack_frame.h"
|
|
#include "vm/stub_code.h"
|
|
#include "vm/unit_test.h"
|
|
|
|
namespace dart {
|
|
|
|
|
|
// A native call for test purposes.
|
|
// Arg0: a smi.
|
|
// Arg1: a smi.
|
|
// Result: a smi representing arg0 - arg1.
|
|
void TestSmiSub(Dart_NativeArguments args) {
|
|
Dart_EnterScope();
|
|
Dart_Handle left = Dart_GetNativeArgument(args, 0);
|
|
Dart_Handle right = Dart_GetNativeArgument(args, 1);
|
|
int64_t left_value = -1;
|
|
int64_t right_value = -1;
|
|
EXPECT_VALID(Dart_IntegerToInt64(left, &left_value));
|
|
EXPECT_VALID(Dart_IntegerToInt64(right, &right_value));
|
|
|
|
// Ignoring overflow in the calculation below.
|
|
int64_t result = left_value - right_value;
|
|
Dart_SetReturnValue(args, Dart_NewInteger(result));
|
|
Dart_ExitScope();
|
|
}
|
|
|
|
|
|
// A native call for test purposes.
|
|
// Arg0-4: 5 smis.
|
|
// Result: a smi representing the sum of all arguments.
|
|
void TestSmiSum(Dart_NativeArguments args) {
|
|
Dart_EnterScope();
|
|
int64_t result = 0;
|
|
int arg_count = Dart_GetNativeArgumentCount(args);
|
|
for (int i = 0; i < arg_count; i++) {
|
|
Dart_Handle arg = Dart_GetNativeArgument(args, i);
|
|
int64_t arg_value = -1;
|
|
EXPECT_VALID(Dart_IntegerToInt64(arg, &arg_value));
|
|
|
|
// Ignoring overflow in the addition below.
|
|
result += arg_value;
|
|
}
|
|
Dart_SetReturnValue(args, Dart_NewInteger(result));
|
|
Dart_ExitScope();
|
|
}
|
|
|
|
|
|
// Test code patching.
|
|
void TestStaticCallPatching(Dart_NativeArguments args) {
|
|
Dart_EnterScope();
|
|
uword target_address = 0;
|
|
Function& target_function = Function::Handle();
|
|
DartFrameIterator iterator;
|
|
iterator.NextFrame(); // Skip native call.
|
|
StackFrame* static_caller_frame = iterator.NextFrame();
|
|
CodePatcher::GetStaticCallAt(static_caller_frame->pc(),
|
|
&target_function,
|
|
&target_address);
|
|
EXPECT(String::Handle(target_function.name()).
|
|
Equals(String::Handle(String::New("NativePatchStaticCall"))));
|
|
const uword function_entry_address =
|
|
Code::Handle(target_function.CurrentCode()).EntryPoint();
|
|
EXPECT_EQ(function_entry_address, target_address);
|
|
Dart_ExitScope();
|
|
}
|
|
|
|
} // namespace dart
|