| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // Resolve the url within the context of the library's URL. | 257 // Resolve the url within the context of the library's URL. |
| 258 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 258 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 259 Dart_Handle library_url = Dart_LibraryUrl(library); | 259 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 260 if (Dart_IsError(library_url)) { | 260 if (Dart_IsError(library_url)) { |
| 261 return library_url; | 261 return library_url; |
| 262 } | 262 } |
| 263 Dart_Handle dart_args[2]; | 263 Dart_Handle dart_args[2]; |
| 264 dart_args[0] = library_url; | 264 dart_args[0] = library_url; |
| 265 dart_args[1] = url; | 265 dart_args[1] = url; |
| 266 if (is_dart_extension_url) { | 266 if (is_dart_extension_url) { |
| 267 return Dart_InvokeStatic(builtin_lib, | 267 return Dart_Invoke( |
| 268 Dart_NewString(""), | 268 builtin_lib, Dart_NewString("_resolveExtensionUri"), 2, dart_args); |
| 269 Dart_NewString("resolveExtensionUri"), | |
| 270 2, dart_args); | |
| 271 } else { | 269 } else { |
| 272 return Dart_InvokeStatic(builtin_lib, | 270 return Dart_Invoke( |
| 273 Dart_NewString(""), Dart_NewString("resolveUri"), | 271 builtin_lib, Dart_NewString("_resolveUri"), 2, dart_args); |
| 274 2, dart_args); | |
| 275 } | 272 } |
| 276 } | 273 } |
| 277 if (is_dart_scheme_url) { | 274 if (is_dart_scheme_url) { |
| 278 ASSERT(tag == kImportTag); | 275 ASSERT(tag == kImportTag); |
| 279 // Handle imports of other built-in libraries present in the SDK. | 276 // Handle imports of other built-in libraries present in the SDK. |
| 280 if (DartUtils::IsDartIOLibURL(url_string)) { | 277 if (DartUtils::IsDartIOLibURL(url_string)) { |
| 281 return Builtin::LoadLibrary(Builtin::kIOLibrary); | 278 return Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 282 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 279 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| 283 return Builtin::LoadLibrary(Builtin::kJsonLibrary); | 280 return Builtin::LoadLibrary(Builtin::kJsonLibrary); |
| 284 } else if (DartUtils::IsDartUriLibURL(url_string)) { | 281 } else if (DartUtils::IsDartUriLibURL(url_string)) { |
| 285 return Builtin::LoadLibrary(Builtin::kUriLibrary); | 282 return Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 286 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | 283 } else if (DartUtils::IsDartUtfLibURL(url_string)) { |
| 287 return Builtin::LoadLibrary(Builtin::kUtfLibrary); | 284 return Builtin::LoadLibrary(Builtin::kUtfLibrary); |
| 288 } else { | 285 } else { |
| 289 return Dart_Error("Do not know how to load '%s'", url_string); | 286 return Dart_Error("Do not know how to load '%s'", url_string); |
| 290 } | 287 } |
| 291 } else if (is_dart_extension_url) { | 288 } else if (is_dart_extension_url) { |
| 292 if (tag != kImportTag) { | 289 if (tag != kImportTag) { |
| 293 return Dart_Error("Dart extensions must use import: '%s'", url_string); | 290 return Dart_Error("Dart extensions must use import: '%s'", url_string); |
| 294 } | 291 } |
| 295 return Extensions::LoadExtension(url_string, library); | 292 return Extensions::LoadExtension(url_string, library); |
| 296 } else { | 293 } else { |
| 297 // Get the file path out of the url. | 294 // Get the file path out of the url. |
| 298 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 295 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 299 Dart_Handle dart_args[1]; | 296 Dart_Handle dart_args[1]; |
| 300 dart_args[0] = url; | 297 dart_args[0] = url; |
| 301 Dart_Handle file_path = Dart_InvokeStatic(builtin_lib, | 298 Dart_Handle file_path = Dart_Invoke( |
| 302 Dart_NewString(""), | 299 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args); |
| 303 Dart_NewString("filePathFromUri"), | |
| 304 1, dart_args); | |
| 305 if (Dart_IsError(file_path)) { | 300 if (Dart_IsError(file_path)) { |
| 306 return file_path; | 301 return file_path; |
| 307 } | 302 } |
| 308 Dart_StringToCString(file_path, &url_string); | 303 Dart_StringToCString(file_path, &url_string); |
| 309 } | 304 } |
| 310 result = DartUtils::LoadSource(NULL, | 305 result = DartUtils::LoadSource(NULL, |
| 311 library, | 306 library, |
| 312 url, | 307 url, |
| 313 tag, | 308 tag, |
| 314 url_string, | 309 url_string, |
| 315 import_map); | 310 import_map); |
| 316 if (!Dart_IsError(result) && (tag == kImportTag)) { | 311 if (!Dart_IsError(result) && (tag == kImportTag)) { |
| 317 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); | 312 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); |
| 318 } | 313 } |
| 319 return result; | 314 return result; |
| 320 } | 315 } |
| 321 | 316 |
| 322 | 317 |
| 323 static Dart_Handle LoadScript(Dart_Handle builtin_lib, | 318 static Dart_Handle LoadScript(Dart_Handle builtin_lib, |
| 324 CommandLineOptions* map) { | 319 CommandLineOptions* map) { |
| 325 Dart_Handle dart_args[3]; | 320 Dart_Handle dart_args[3]; |
| 326 dart_args[0] = Dart_NewString(original_working_directory); | 321 dart_args[0] = Dart_NewString(original_working_directory); |
| 327 dart_args[1] = Dart_NewString(original_script_name); | 322 dart_args[1] = Dart_NewString(original_script_name); |
| 328 #if !defined(TARGET_OS_WINDOWS) | 323 #if !defined(TARGET_OS_WINDOWS) |
| 329 dart_args[2] = Dart_False(); | 324 dart_args[2] = Dart_False(); |
| 330 #else // !defined(TARGET_OS_WINDOWS) | 325 #else // !defined(TARGET_OS_WINDOWS) |
| 331 dart_args[2] = Dart_True(); | 326 dart_args[2] = Dart_True(); |
| 332 #endif // !defined(TARGET_OS_WINDOWS) | 327 #endif // !defined(TARGET_OS_WINDOWS) |
| 333 Dart_Handle script_url = Dart_InvokeStatic(builtin_lib, | 328 Dart_Handle script_url = Dart_Invoke( |
| 334 Dart_NewString(""), | 329 builtin_lib, Dart_NewString("_resolveScriptUri"), 3, dart_args); |
| 335 Dart_NewString("resolveScriptUri"), | |
| 336 3, dart_args); | |
| 337 if (Dart_IsError(script_url)) { | 330 if (Dart_IsError(script_url)) { |
| 338 fprintf(stderr, "%s", Dart_GetError(script_url)); | 331 fprintf(stderr, "%s", Dart_GetError(script_url)); |
| 339 return script_url; | 332 return script_url; |
| 340 } | 333 } |
| 341 if (original_script_url == NULL) { | 334 if (original_script_url == NULL) { |
| 342 const char* script_url_cstr; | 335 const char* script_url_cstr; |
| 343 Dart_StringToCString(script_url, &script_url_cstr); | 336 Dart_StringToCString(script_url, &script_url_cstr); |
| 344 original_script_url = strdup(script_url_cstr); | 337 original_script_url = strdup(script_url_cstr); |
| 345 } | 338 } |
| 346 dart_args[0] = script_url; | 339 dart_args[0] = script_url; |
| 347 Dart_Handle script_path = Dart_InvokeStatic(builtin_lib, | 340 Dart_Handle script_path = Dart_Invoke( |
| 348 Dart_NewString(""), | 341 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args); |
| 349 Dart_NewString("filePathFromUri"), | |
| 350 1, dart_args); | |
| 351 if (Dart_IsError(script_path)) { | 342 if (Dart_IsError(script_path)) { |
| 352 return script_path; | 343 return script_path; |
| 353 } | 344 } |
| 354 const char* script_path_cstr; | 345 const char* script_path_cstr; |
| 355 Dart_StringToCString(script_path, &script_path_cstr); | 346 Dart_StringToCString(script_path, &script_path_cstr); |
| 356 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); | 347 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); |
| 357 if (Dart_IsError(source)) { | 348 if (Dart_IsError(source)) { |
| 358 return source; | 349 return source; |
| 359 } | 350 } |
| 360 intptr_t length = (map == NULL) ? 0 : map->count(); | 351 intptr_t length = (map == NULL) ? 0 : map->count(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 if (Dart_IsError(result)) { | 585 if (Dart_IsError(result)) { |
| 595 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 586 return ErrorExit("Error setting breakpoint at '%s': %s\n", |
| 596 breakpoint_at, | 587 breakpoint_at, |
| 597 Dart_GetError(result)); | 588 Dart_GetError(result)); |
| 598 } | 589 } |
| 599 } | 590 } |
| 600 // Lookup and invoke the top level main function. | 591 // Lookup and invoke the top level main function. |
| 601 result = Dart_InvokeStatic(library, | 592 result = Dart_InvokeStatic(library, |
| 602 Dart_NewString(""), | 593 Dart_NewString(""), |
| 603 Dart_NewString("main"), | 594 Dart_NewString("main"), |
| 604 0, | 595 0, NULL); |
| 605 NULL); | |
| 606 if (Dart_IsError(result)) { | 596 if (Dart_IsError(result)) { |
| 607 return ErrorExit("%s\n", Dart_GetError(result)); | 597 return ErrorExit("%s\n", Dart_GetError(result)); |
| 608 } | 598 } |
| 609 // Keep handling messages until the last active receive port is closed. | 599 // Keep handling messages until the last active receive port is closed. |
| 610 result = Dart_RunLoop(); | 600 result = Dart_RunLoop(); |
| 611 if (Dart_IsError(result)) { | 601 if (Dart_IsError(result)) { |
| 612 return ErrorExit("%s\n", Dart_GetError(result)); | 602 return ErrorExit("%s\n", Dart_GetError(result)); |
| 613 } | 603 } |
| 614 | 604 |
| 615 Dart_ExitScope(); | 605 Dart_ExitScope(); |
| 616 // Dump symbol information for the profiler. | 606 // Dump symbol information for the profiler. |
| 617 DumpPprofSymbolInfo(); | 607 DumpPprofSymbolInfo(); |
| 618 // Shutdown the isolate. | 608 // Shutdown the isolate. |
| 619 Dart_ShutdownIsolate(); | 609 Dart_ShutdownIsolate(); |
| 620 // Terminate event handler. | 610 // Terminate event handler. |
| 621 EventHandler::Terminate(); | 611 EventHandler::Terminate(); |
| 622 // Terminate process exit-code handler. | 612 // Terminate process exit-code handler. |
| 623 Process::TerminateExitCodeHandler(); | 613 Process::TerminateExitCodeHandler(); |
| 624 | 614 |
| 625 free(const_cast<char*>(original_script_name)); | 615 free(const_cast<char*>(original_script_name)); |
| 626 free(const_cast<char*>(original_working_directory)); | 616 free(const_cast<char*>(original_working_directory)); |
| 627 free(const_cast<char*>(original_script_url)); | 617 free(const_cast<char*>(original_script_url)); |
| 628 | 618 |
| 629 return 0; | 619 return 0; |
| 630 } | 620 } |
| OLD | NEW |