9731c1c254
Api::NewHandle now takes a RawObject* intead of an Object&. - This makes the code shorter and easier to read. - This allows us to drop the DARTSCOPE from Dart_GetNativeArgument. (6% speedup on Benchmark_UseDartApi) Review URL: https://chromiumcodereview.appspot.com//10014002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6283 260f80e4-7a28-3924-810f-c04153c831b5
35 lines
1.3 KiB
C++
35 lines
1.3 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.h"
|
|
|
|
#include "include/dart_api.h"
|
|
|
|
#include "vm/dart_api_impl.h"
|
|
|
|
namespace dart {
|
|
|
|
DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives");
|
|
|
|
NativeFunction NativeEntry::ResolveNative(const Class& cls,
|
|
const String& function_name,
|
|
int number_of_arguments) {
|
|
// Now resolve the native function to the corresponding native entrypoint.
|
|
const Library& library = Library::Handle(cls.library());
|
|
if (library.native_entry_resolver() == 0) {
|
|
// Native methods are not allowed in the library to which this
|
|
// class belongs in.
|
|
return NULL;
|
|
}
|
|
Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries.
|
|
Dart_NativeEntryResolver resolver = library.native_entry_resolver();
|
|
Dart_NativeFunction native_function =
|
|
resolver(Api::NewHandle(Isolate::Current(), function_name.raw()),
|
|
number_of_arguments);
|
|
Dart_ExitScope(); // Exit the Dart API scope.
|
|
return reinterpret_cast<NativeFunction>(native_function);
|
|
}
|
|
|
|
} // namespace dart
|