OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "bin/vmservice_impl.h" | 5 #include "bin/vmservice_impl.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #define SHUTDOWN_ON_ERROR(handle) \ | 25 #define SHUTDOWN_ON_ERROR(handle) \ |
26 if (Dart_IsError(handle)) { \ | 26 if (Dart_IsError(handle)) { \ |
27 error_msg_ = strdup(Dart_GetError(handle)); \ | 27 error_msg_ = strdup(Dart_GetError(handle)); \ |
28 Dart_ExitScope(); \ | 28 Dart_ExitScope(); \ |
29 Dart_ShutdownIsolate(); \ | 29 Dart_ShutdownIsolate(); \ |
30 return false; \ | 30 return false; \ |
31 } | 31 } |
32 | 32 |
33 #define kLibrarySourceNamePrefix "/vmservice" | 33 #define kLibrarySourceNamePrefix "/vmservice" |
| 34 static const char* kVMServiceIOLibraryUri = "dart:vmservice_io"; |
34 static const char* kVMServiceIOLibraryScriptResourceName = "vmservice_io.dart"; | 35 static const char* kVMServiceIOLibraryScriptResourceName = "vmservice_io.dart"; |
35 | 36 |
36 struct ResourcesEntry { | 37 struct ResourcesEntry { |
37 const char* path_; | 38 const char* path_; |
38 const char* resource_; | 39 const char* resource_; |
39 int length_; | 40 int length_; |
40 }; | 41 }; |
41 | 42 |
42 extern ResourcesEntry __service_bin_resources_[]; | 43 extern ResourcesEntry __service_bin_resources_[]; |
43 | 44 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 154 } |
154 return NULL; | 155 return NULL; |
155 } | 156 } |
156 | 157 |
157 | 158 |
158 const char* VmService::error_msg_ = NULL; | 159 const char* VmService::error_msg_ = NULL; |
159 char VmService::server_ip_[kServerIpStringBufferSize]; | 160 char VmService::server_ip_[kServerIpStringBufferSize]; |
160 intptr_t VmService::server_port_ = 0; | 161 intptr_t VmService::server_port_ = 0; |
161 | 162 |
162 | 163 |
163 bool VmService::Setup(const char* server_ip, intptr_t server_port) { | 164 bool VmService::LoadForGenPrecompiled() { |
| 165 Dart_Handle result; |
| 166 Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 167 Dart_Handle library = LoadLibrary(kVMServiceIOLibraryScriptResourceName); |
| 168 ASSERT(library != Dart_Null()); |
| 169 SHUTDOWN_ON_ERROR(library); |
| 170 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); |
| 171 SHUTDOWN_ON_ERROR(result); |
| 172 result = Dart_FinalizeLoading(false); |
| 173 SHUTDOWN_ON_ERROR(result); |
| 174 return true; |
| 175 } |
| 176 |
| 177 |
| 178 bool VmService::Setup(const char* server_ip, |
| 179 intptr_t server_port, |
| 180 bool running_precompiled) { |
164 Dart_Isolate isolate = Dart_CurrentIsolate(); | 181 Dart_Isolate isolate = Dart_CurrentIsolate(); |
165 ASSERT(isolate != NULL); | 182 ASSERT(isolate != NULL); |
166 SetServerIPAndPort("", 0); | 183 SetServerIPAndPort("", 0); |
167 | 184 |
168 Dart_Handle result; | 185 Dart_Handle result; |
169 | 186 |
170 Dart_Handle builtin_lib = | 187 Dart_Handle builtin_lib = |
171 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 188 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
172 SHUTDOWN_ON_ERROR(builtin_lib); | 189 SHUTDOWN_ON_ERROR(builtin_lib); |
173 | 190 |
174 // Prepare for script loading by setting up the 'print' and 'timer' | 191 // Prepare for script loading by setting up the 'print' and 'timer' |
175 // closures and setting up 'package root' for URI resolution. | 192 // closures and setting up 'package root' for URI resolution. |
176 result = DartUtils::PrepareForScriptLoading( | 193 result = DartUtils::PrepareForScriptLoading( |
177 NULL, NULL, NULL, true, false, builtin_lib); | 194 NULL, NULL, NULL, true, false, builtin_lib); |
178 SHUTDOWN_ON_ERROR(result); | 195 SHUTDOWN_ON_ERROR(result); |
179 | 196 |
180 // Load main script. | 197 if (running_precompiled) { |
181 Dart_SetLibraryTagHandler(LibraryTagHandler); | 198 Dart_Handle url = DartUtils::NewString(kVMServiceIOLibraryUri); |
182 Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName); | 199 Dart_Handle library = Dart_LookupLibrary(url); |
183 ASSERT(library != Dart_Null()); | 200 SHUTDOWN_ON_ERROR(library); |
184 SHUTDOWN_ON_ERROR(library); | 201 result = Dart_SetRootLibrary(library); |
185 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); | 202 SHUTDOWN_ON_ERROR(library); |
186 SHUTDOWN_ON_ERROR(result); | 203 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); |
187 result = Dart_FinalizeLoading(false); | 204 SHUTDOWN_ON_ERROR(result); |
188 SHUTDOWN_ON_ERROR(result); | 205 } else { |
| 206 // Load main script. |
| 207 Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 208 Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName); |
| 209 ASSERT(library != Dart_Null()); |
| 210 SHUTDOWN_ON_ERROR(library); |
| 211 result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL); |
| 212 SHUTDOWN_ON_ERROR(result); |
| 213 result = Dart_FinalizeLoading(false); |
| 214 SHUTDOWN_ON_ERROR(result); |
| 215 } |
189 | 216 |
190 // Make runnable. | 217 // Make runnable. |
191 Dart_ExitScope(); | 218 Dart_ExitScope(); |
192 Dart_ExitIsolate(); | 219 Dart_ExitIsolate(); |
193 bool retval = Dart_IsolateMakeRunnable(isolate); | 220 bool retval = Dart_IsolateMakeRunnable(isolate); |
194 if (!retval) { | 221 if (!retval) { |
195 Dart_EnterIsolate(isolate); | 222 Dart_EnterIsolate(isolate); |
196 Dart_ShutdownIsolate(); | 223 Dart_ShutdownIsolate(); |
197 error_msg_ = "Invalid isolate state - Unable to make it runnable."; | 224 error_msg_ = "Invalid isolate state - Unable to make it runnable."; |
198 return false; | 225 return false; |
199 } | 226 } |
200 Dart_EnterIsolate(isolate); | 227 Dart_EnterIsolate(isolate); |
201 Dart_EnterScope(); | 228 Dart_EnterScope(); |
202 | 229 |
203 library = Dart_RootLibrary(); | 230 Dart_Handle library = Dart_RootLibrary(); |
204 SHUTDOWN_ON_ERROR(library); | 231 SHUTDOWN_ON_ERROR(library); |
205 | 232 |
206 // Set HTTP server state. | 233 // Set HTTP server state. |
207 result = DartUtils::SetStringField(library, "_ip", server_ip); | 234 result = DartUtils::SetStringField(library, "_ip", server_ip); |
208 SHUTDOWN_ON_ERROR(result); | 235 SHUTDOWN_ON_ERROR(result); |
209 // If we have a port specified, start the server immediately. | 236 // If we have a port specified, start the server immediately. |
210 bool auto_start = server_port >= 0; | 237 bool auto_start = server_port >= 0; |
211 if (server_port < 0) { | 238 if (server_port < 0) { |
212 // Adjust server_port to port 0 which will result in the first available | 239 // Adjust server_port to port 0 which will result in the first available |
213 // port when the HTTP server is started. | 240 // port when the HTTP server is started. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 int r = Resources::ResourceLookup(buffer, &vmservice_source); | 299 int r = Resources::ResourceLookup(buffer, &vmservice_source); |
273 if (r == Resources::kNoSuchInstance) { | 300 if (r == Resources::kNoSuchInstance) { |
274 FATAL1("vm-service: Could not find embedded source file: %s ", buffer); | 301 FATAL1("vm-service: Could not find embedded source file: %s ", buffer); |
275 } | 302 } |
276 ASSERT(r != Resources::kNoSuchInstance); | 303 ASSERT(r != Resources::kNoSuchInstance); |
277 return Dart_NewStringFromCString(vmservice_source); | 304 return Dart_NewStringFromCString(vmservice_source); |
278 } | 305 } |
279 | 306 |
280 | 307 |
281 Dart_Handle VmService::LoadScript(const char* name) { | 308 Dart_Handle VmService::LoadScript(const char* name) { |
282 Dart_Handle url = Dart_NewStringFromCString("dart:vmservice_io"); | 309 Dart_Handle uri = Dart_NewStringFromCString(kVMServiceIOLibraryUri); |
283 Dart_Handle source = GetSource(name); | 310 Dart_Handle source = GetSource(name); |
284 return Dart_LoadScript(url, source, 0, 0); | 311 return Dart_LoadScript(uri, source, 0, 0); |
| 312 } |
| 313 |
| 314 |
| 315 Dart_Handle VmService::LoadLibrary(const char* name) { |
| 316 Dart_Handle uri = Dart_NewStringFromCString(kVMServiceIOLibraryUri); |
| 317 Dart_Handle source = GetSource(name); |
| 318 return Dart_LoadLibrary(uri, source, 0, 0); |
285 } | 319 } |
286 | 320 |
287 | 321 |
288 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { | 322 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { |
289 Dart_Handle url = Dart_NewStringFromCString(name); | 323 Dart_Handle uri = Dart_NewStringFromCString(name); |
290 Dart_Handle source = GetSource(name); | 324 Dart_Handle source = GetSource(name); |
291 return Dart_LoadSource(library, url, source, 0, 0); | 325 return Dart_LoadSource(library, uri, source, 0, 0); |
292 } | 326 } |
293 | 327 |
294 | 328 |
295 Dart_Handle VmService::LoadResource(Dart_Handle library, | 329 Dart_Handle VmService::LoadResource(Dart_Handle library, |
296 const char* resource_name) { | 330 const char* resource_name) { |
297 // Prepare for invoke call. | 331 // Prepare for invoke call. |
298 Dart_Handle name = Dart_NewStringFromCString(resource_name); | 332 Dart_Handle name = Dart_NewStringFromCString(resource_name); |
299 RETURN_ERROR_HANDLE(name); | 333 RETURN_ERROR_HANDLE(name); |
300 const char* data_buffer = NULL; | 334 const char* data_buffer = NULL; |
301 int data_buffer_length = Resources::ResourceLookup(resource_name, | 335 int data_buffer_length = Resources::ResourceLookup(resource_name, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 Dart_Handle source = GetSource(url_string); | 415 Dart_Handle source = GetSource(url_string); |
382 if (Dart_IsError(source)) { | 416 if (Dart_IsError(source)) { |
383 return source; | 417 return source; |
384 } | 418 } |
385 return Dart_LoadSource(library, url, source, 0, 0); | 419 return Dart_LoadSource(library, url, source, 0, 0); |
386 } | 420 } |
387 | 421 |
388 | 422 |
389 } // namespace bin | 423 } // namespace bin |
390 } // namespace dart | 424 } // namespace dart |
OLD | NEW |