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

Side by Side Diff: runtime/bin/builtin_in.cc

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 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 <assert.h> 5 #include <assert.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const char* name_; 59 const char* name_;
60 Dart_NativeFunction function_; 60 Dart_NativeFunction function_;
61 int argument_count_; 61 int argument_count_;
62 } BuiltinEntries[] = { 62 } BuiltinEntries[] = {
63 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) 63 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)
64 }; 64 };
65 65
66 66
67 static Dart_NativeFunction native_lookup(Dart_Handle name, 67 static Dart_NativeFunction native_lookup(Dart_Handle name,
68 int argument_count) { 68 int argument_count) {
69 Dart_Result result = Dart_StringToCString(name); 69 const char* function_name = NULL;
70 assert(Dart_IsValidResult(result)); 70 Dart_Handle result = Dart_StringToCString(name, &function_name);
71 const char* function_name = Dart_GetResultAsCString(result); 71 ASSERT(Dart_IsValid(result));
72 assert(function_name != NULL); 72 ASSERT(function_name != NULL);
73 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 73 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
74 for (int i = 0; i < num_entries; i++) { 74 for (int i = 0; i < num_entries; i++) {
75 struct NativeEntries* entry = &(BuiltinEntries[i]); 75 struct NativeEntries* entry = &(BuiltinEntries[i]);
76 if (!strcmp(function_name, entry->name_)) { 76 if (!strcmp(function_name, entry->name_)) {
77 if (entry->argument_count_ == argument_count) { 77 if (entry->argument_count_ == argument_count) {
78 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 78 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
79 } else { 79 } else {
80 // Wrong number of arguments. 80 // Wrong number of arguments.
81 // TODO(regis): Should we pass a buffer for error reporting? 81 // TODO(regis): Should we pass a buffer for error reporting?
82 return NULL; 82 return NULL;
83 } 83 }
84 } 84 }
85 } 85 }
86 return NULL; 86 return NULL;
87 } 87 }
88 88
89 89
90 void Builtin_LoadLibrary() { 90 void Builtin_LoadLibrary() {
91 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); 91 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL);
92 Dart_Result result = Dart_LookupLibrary(url); 92 Dart_Handle result = Dart_LookupLibrary(url);
93 if (Dart_IsValidResult(result)) { 93 if (Dart_IsValid(result)) {
94 // Builtin library already loaded. 94 // Builtin library already loaded.
95 return; 95 return;
96 } 96 }
97 97
98 // Load the library. 98 // Load the library.
99 Dart_Handle source = Dart_NewString(Builtin_source_); 99 Dart_Handle source = Dart_NewString(Builtin_source_);
100 result = Dart_LoadLibrary(url, source); 100 Dart_Handle builtin_lib = Dart_LoadLibrary(url, source);
101 assert(Dart_IsValidResult(result)); 101 ASSERT(Dart_IsValid(builtin_lib));
102 Dart_Handle builtin_lib = Dart_GetResult(result);
103 102
104 // Lookup the core libraries and inject the builtin library into them. 103 // Lookup the core libraries and inject the builtin library into them.
105 result = Dart_LookupLibrary(Dart_NewString("dart:core")); 104 Dart_Handle core_lib = Dart_LookupLibrary(Dart_NewString("dart:core"));
106 assert(Dart_IsValidResult(result)); 105 ASSERT(Dart_IsValid(core_lib));
107 Dart_Handle core_lib = Dart_GetResult(result);
108 result = Dart_LibraryImportLibrary(core_lib, builtin_lib); 106 result = Dart_LibraryImportLibrary(core_lib, builtin_lib);
109 assert(Dart_IsValidResult(result)); 107 ASSERT(Dart_IsValid(result));
110 108
111 result = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); 109 Dart_Handle coreimpl_lib =
112 assert(Dart_IsValidResult(result)); 110 Dart_LookupLibrary(Dart_NewString("dart:coreimpl"));
113 Dart_Handle coreimpl_lib = Dart_GetResult(result); 111 ASSERT(Dart_IsValid(coreimpl_lib));
114 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); 112 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib);
115 assert(Dart_IsValidResult(result)); 113 ASSERT(Dart_IsValid(result));
116 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); 114 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib);
117 assert(Dart_IsValidResult(result)); 115 ASSERT(Dart_IsValid(result));
118 116
119 // Create a native wrapper "FileNativeWrapper" so that we can add a 117 // Create a native wrapper "FileNativeWrapper" so that we can add a
120 // native field to store the OS file handle for implementing all the 118 // native field to store the OS file handle for implementing all the
121 // file operations. The class "File" extends "FileNativeWrapper". 119 // file operations. The class "File" extends "FileNativeWrapper".
122 Dart_Handle name = Dart_NewString("FileNativeWrapper"); 120 Dart_Handle name = Dart_NewString("FileNativeWrapper");
123 const int kNumFileFields = 1; 121 const int kNumFileFields = 1;
124 result = Dart_CreateNativeWrapperClass(builtin_lib, name, kNumFileFields); 122 result = Dart_CreateNativeWrapperClass(builtin_lib, name, kNumFileFields);
125 assert(Dart_IsValidResult(result)); 123 ASSERT(Dart_IsValid(result));
126 124
127 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a 125 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a
128 // native field to store the event handle for implementing all 126 // native field to store the event handle for implementing all
129 // event operations. 127 // event operations.
130 name = Dart_NewString("EventHandlerNativeWrapper"); 128 name = Dart_NewString("EventHandlerNativeWrapper");
131 const int kNumEventHandlerFields = 1; 129 const int kNumEventHandlerFields = 1;
132 result = Dart_CreateNativeWrapperClass(builtin_lib, 130 result = Dart_CreateNativeWrapperClass(builtin_lib,
133 name, 131 name,
134 kNumEventHandlerFields); 132 kNumEventHandlerFields);
135 assert(Dart_IsValidResult(result)); 133 ASSERT(Dart_IsValid(result));
136 } 134 }
137 135
138 136
139 void Builtin_ImportLibrary(Dart_Handle library) { 137 void Builtin_ImportLibrary(Dart_Handle library) {
140 Builtin_LoadLibrary(); 138 Builtin_LoadLibrary();
141 139
142 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); 140 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL);
143 Dart_Result result = Dart_LookupLibrary(url); 141 Dart_Handle builtin_lib = Dart_LookupLibrary(url);
144 assert(Dart_IsValidResult(result)); 142 ASSERT(Dart_IsValid(builtin_lib));
145 Dart_Handle builtin_lib = Dart_GetResult(result); 143 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib);
146 result = Dart_LibraryImportLibrary(library, builtin_lib); 144 ASSERT(Dart_IsValid(result));
147 assert(Dart_IsValidResult(result));
148 } 145 }
149 146
150 147
151 void Builtin_SetNativeResolver() { 148 void Builtin_SetNativeResolver() {
152 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); 149 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL);
153 Dart_Result result = Dart_LookupLibrary(url); 150 Dart_Handle builtin_lib = Dart_LookupLibrary(url);
154 assert(Dart_IsValidResult(result)); 151 ASSERT(Dart_IsValid(builtin_lib));
155 Dart_Handle builtin_lib = Dart_GetResult(result); 152 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup);
156 result = Dart_SetNativeResolver(builtin_lib, native_lookup); 153 ASSERT(Dart_IsValid(result));
157 assert(Dart_IsValidResult(result));
158 } 154 }
OLDNEW
« no previous file with comments | « runtime/bin/builtin.cc ('k') | runtime/bin/dartutils.cc » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698