Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "vm/bootstrap.h" | |
| 6 | |
| 7 #include "include/dart_api.h" | |
| 8 | |
| 9 #include "vm/bootstrap_natives.h" | |
| 10 #include "vm/dart_api_impl.h" | |
| 11 #include "vm/object.h" | |
| 12 #include "vm/object_store.h" | |
| 13 | |
| 14 namespace dart { | |
| 15 | |
| 16 // List all native functions implemented in the vm or core bootstrap dart | |
| 17 // libraries so that we can resolve the native function to it's entry | |
| 18 // point. | |
| 19 static struct NativeEntries { | |
| 20 const char* name_; | |
| 21 Dart_NativeFunction function_; | |
| 22 int argument_count_; | |
| 23 } BootStrapEntries[] = { | |
| 24 BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) | |
| 25 }; | |
| 26 | |
| 27 | |
| 28 static Dart_NativeFunction native_lookup(Dart_Handle name, | |
| 29 int argument_count) { | |
|
turnidge
2011/11/23 18:05:12
For parallelism with the Builtin class, you could
siva
2011/11/23 22:37:27
I renamed the function to NativeLookup but did not
| |
| 30 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | |
| 31 if (!obj.IsString()) { | |
| 32 return NULL; | |
| 33 } | |
| 34 const char* function_name = obj.ToCString(); | |
| 35 ASSERT(function_name != NULL); | |
| 36 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); | |
| 37 for (int i = 0; i < num_entries; i++) { | |
| 38 struct NativeEntries* entry = &(BootStrapEntries[i]); | |
| 39 if (!strncmp(function_name, entry->name_, strlen(entry->name_))) { | |
| 40 if (entry->argument_count_ == argument_count) { | |
| 41 return reinterpret_cast<Dart_NativeFunction>(entry->function_); | |
| 42 } else { | |
| 43 // Wrong number of arguments. | |
| 44 // TODO(regis): Should we pass a buffer for error reporting? | |
| 45 return NULL; | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 return NULL; | |
| 50 } | |
| 51 | |
| 52 | |
| 53 void Bootstrap::SetupNativeResolver() { | |
| 54 Library& library = Library::Handle(Library::CoreLibrary()); | |
| 55 ASSERT(!library.IsNull()); | |
|
turnidge
2011/11/23 18:05:12
Change these ASSERTs to DART_CHECK_VALID to get a
siva
2011/11/23 22:37:27
I am unable to change these to DART_CHECK_VALID as
| |
| 56 library.set_native_entry_resolver( | |
| 57 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | |
| 58 library = Library::CoreImplLibrary(); | |
| 59 ASSERT(!library.IsNull()); | |
| 60 library.set_native_entry_resolver( | |
| 61 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | |
| 62 } | |
| 63 | |
| 64 } // namespace dart | |
| OLD | NEW |