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

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

Powered by Google App Engine
This is Rietveld 408576698