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

Side by Side Diff: vm/bootstrap_natives.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, 3 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
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/bootstrap.h" 5 #include "vm/bootstrap.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/bootstrap_natives.h" 9 #include "vm/bootstrap_natives.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/object_store.h" 12 #include "vm/object_store.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 // Helper macros for declaring and defining native entries.
17 #define REGISTER_NATIVE_ENTRY(name, count) \
18 { ""#name, BootstrapNatives::DN_##name, count },
19
20
16 // List all native functions implemented in the vm or core bootstrap dart 21 // 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 22 // libraries so that we can resolve the native function to it's entry
18 // point. 23 // point.
19 static struct NativeEntries { 24 static struct NativeEntries {
20 const char* name_; 25 const char* name_;
21 Dart_NativeFunction function_; 26 Dart_NativeFunction function_;
22 int argument_count_; 27 int argument_count_;
23 } BootStrapEntries[] = { 28 } BootStrapEntries[] = {
24 BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) 29 BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY)
25 }; 30 };
26 31
27 32
28 static Dart_NativeFunction NativeLookup(Dart_Handle name, 33 Dart_NativeFunction BootstrapNatives::Lookup(Dart_Handle name,
29 int argument_count) { 34 int argument_count) {
30 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); 35 const Object& obj = Object::Handle(Api::UnwrapHandle(name));
31 if (!obj.IsString()) { 36 if (!obj.IsString()) {
32 return NULL; 37 return NULL;
33 } 38 }
34 const char* function_name = obj.ToCString(); 39 const char* function_name = obj.ToCString();
35 ASSERT(function_name != NULL); 40 ASSERT(function_name != NULL);
36 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); 41 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries);
37 for (int i = 0; i < num_entries; i++) { 42 for (int i = 0; i < num_entries; i++) {
38 struct NativeEntries* entry = &(BootStrapEntries[i]); 43 struct NativeEntries* entry = &(BootStrapEntries[i]);
39 if (!strncmp(function_name, entry->name_, strlen(entry->name_)) && 44 if (!strncmp(function_name, entry->name_, strlen(entry->name_)) &&
40 (entry->argument_count_ == argument_count)) { 45 (entry->argument_count_ == argument_count)) {
41 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 46 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
42 } 47 }
43 } 48 }
44 return NULL; 49 return NULL;
45 } 50 }
46 51
47 52
48 void Bootstrap::SetupNativeResolver() { 53 void Bootstrap::SetupNativeResolver() {
49 Library& library = Library::Handle(); 54 Library& library = Library::Handle();
50 55
56 Dart_NativeEntryResolver resolver =
57 reinterpret_cast<Dart_NativeEntryResolver>(BootstrapNatives::Lookup);
58
51 library = Library::CoreLibrary(); 59 library = Library::CoreLibrary();
52 ASSERT(!library.IsNull()); 60 ASSERT(!library.IsNull());
53 library.set_native_entry_resolver( 61 library.set_native_entry_resolver(resolver);
54 reinterpret_cast<Dart_NativeEntryResolver>(NativeLookup));
55 62
56 library = Library::CoreImplLibrary(); 63 library = Library::CoreImplLibrary();
57 ASSERT(!library.IsNull()); 64 ASSERT(!library.IsNull());
58 library.set_native_entry_resolver( 65 library.set_native_entry_resolver(resolver);
59 reinterpret_cast<Dart_NativeEntryResolver>(NativeLookup));
60 66
61 library = Library::MirrorsLibrary(); 67 library = Library::MirrorsLibrary();
62 ASSERT(!library.IsNull()); 68 ASSERT(!library.IsNull());
63 library.set_native_entry_resolver( 69 library.set_native_entry_resolver(resolver);
64 reinterpret_cast<Dart_NativeEntryResolver>(NativeLookup));
65 70
66 library = Library::IsolateLibrary(); 71 library = Library::IsolateLibrary();
67 ASSERT(!library.IsNull()); 72 ASSERT(!library.IsNull());
68 library.set_native_entry_resolver( 73 library.set_native_entry_resolver(resolver);
69 reinterpret_cast<Dart_NativeEntryResolver>(NativeLookup));
70 } 74 }
71 75
72 } // namespace dart 76 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698