| 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.h" | 5 #include "vm/native_entry.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives"); | 13 DEFINE_FLAG(bool, trace_natives, false, "Trace invocation of natives"); |
| 14 | 14 |
| 15 NativeFunction NativeEntry::ResolveNative(const Class& cls, | 15 NativeFunction NativeEntry::ResolveNative(const Class& cls, |
| 16 const String& function_name, | 16 const String& function_name, |
| 17 int number_of_arguments) { | 17 int number_of_arguments) { |
| 18 // Now resolve the native function to the corresponding native entrypoint. | 18 // Now resolve the native function to the corresponding native entrypoint. |
| 19 const Library& library = Library::Handle(cls.library()); | 19 const Library& library = Library::Handle(cls.library()); |
| 20 if (library.native_entry_resolver() == 0) { | 20 if (library.native_entry_resolver() == 0) { |
| 21 // Native methods are not allowed in the library to which this | 21 // Native methods are not allowed in the library to which this |
| 22 // class belongs in. | 22 // class belongs in. |
| 23 return NULL; | 23 return NULL; |
| 24 } | 24 } |
| 25 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. | 25 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. |
| 26 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 26 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
| 27 Dart_NativeFunction native_function = | 27 Dart_NativeFunction native_function = |
| 28 resolver(Api::NewLocalHandle(Isolate::Current(), function_name), | 28 resolver(Api::NewHandle(Isolate::Current(), function_name.raw()), |
| 29 number_of_arguments); | 29 number_of_arguments); |
| 30 Dart_ExitScope(); // Exit the Dart API scope. | 30 Dart_ExitScope(); // Exit the Dart API scope. |
| 31 return reinterpret_cast<NativeFunction>(native_function); | 31 return reinterpret_cast<NativeFunction>(native_function); |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace dart | 34 } // namespace dart |
| OLD | NEW |