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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_tools_api.h" | 8 #include "include/dart_tools_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 | 10 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 ASSERT(td_len == len); | 298 ASSERT(td_len == len); |
299 ASSERT(td_data != NULL); | 299 ASSERT(td_data != NULL); |
300 memmove(td_data, buffer, td_len); | 300 memmove(td_data, buffer, td_len); |
301 result = Dart_TypedDataReleaseData(array); | 301 result = Dart_TypedDataReleaseData(array); |
302 RETURN_IF_ERROR(result); | 302 RETURN_IF_ERROR(result); |
303 } | 303 } |
304 return array; | 304 return array; |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 Dart_Handle DartUtils::SetWorkingDirectory(Dart_Handle builtin_lib) { | 308 Dart_Handle DartUtils::SetWorkingDirectory() { |
309 IsolateData* isolate_data = | |
zra
2016/02/04 04:12:41
This pattern is repeated a lot. Maybe something li
siva
2016/02/04 16:59:00
Done.
| |
310 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
311 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
309 Dart_Handle directory = NewString(original_working_directory); | 312 Dart_Handle directory = NewString(original_working_directory); |
zra
2016/02/04 04:12:41
RETURN_IF_ERROR(directory)
Sometimes we check the
siva
2016/02/04 16:59:00
NewString is used in a number of places sometimes
| |
310 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); | 313 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); |
311 } | 314 } |
312 | 315 |
313 | 316 |
314 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri, | 317 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri) { |
315 Dart_Handle builtin_lib) { | 318 IsolateData* isolate_data = |
319 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
320 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
316 const int kNumArgs = 1; | 321 const int kNumArgs = 1; |
317 Dart_Handle dart_args[kNumArgs]; | 322 Dart_Handle dart_args[kNumArgs]; |
318 dart_args[0] = script_uri; | 323 dart_args[0] = script_uri; |
319 return Dart_Invoke(builtin_lib, | 324 return Dart_Invoke(builtin_lib, |
320 NewString("_resolveInWorkingDirectory"), | 325 NewString("_resolveInWorkingDirectory"), |
321 kNumArgs, | 326 kNumArgs, |
322 dart_args); | 327 dart_args); |
323 } | 328 } |
324 | 329 |
325 | 330 |
326 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri, | 331 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri) { |
327 Dart_Handle builtin_lib) { | 332 IsolateData* isolate_data = |
333 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
334 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
328 const int kNumArgs = 1; | 335 const int kNumArgs = 1; |
329 Dart_Handle dart_args[kNumArgs]; | 336 Dart_Handle dart_args[kNumArgs]; |
330 dart_args[0] = script_uri; | 337 dart_args[0] = script_uri; |
331 return Dart_Invoke(builtin_lib, | 338 return Dart_Invoke(builtin_lib, |
332 NewString("_filePathFromUri"), | 339 NewString("_filePathFromUri"), |
333 kNumArgs, | 340 kNumArgs, |
334 dart_args); | 341 dart_args); |
335 } | 342 } |
336 | 343 |
337 | 344 |
338 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri, | 345 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri) { |
339 Dart_Handle builtin_lib) { | 346 IsolateData* isolate_data = |
347 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
348 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
340 const int kNumArgs = 1; | 349 const int kNumArgs = 1; |
341 Dart_Handle dart_args[kNumArgs]; | 350 Dart_Handle dart_args[kNumArgs]; |
342 dart_args[0] = extension_uri; | 351 dart_args[0] = extension_uri; |
343 return Dart_Invoke(builtin_lib, | 352 return Dart_Invoke(builtin_lib, |
344 NewString("_extensionPathFromUri"), | 353 NewString("_extensionPathFromUri"), |
345 kNumArgs, | 354 kNumArgs, |
346 dart_args); | 355 dart_args); |
347 } | 356 } |
348 | 357 |
349 | 358 |
350 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, | 359 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, Dart_Handle url) { |
351 Dart_Handle url, | 360 IsolateData* isolate_data = |
352 Dart_Handle builtin_lib) { | 361 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
362 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
353 const int kNumArgs = 2; | 363 const int kNumArgs = 2; |
354 Dart_Handle dart_args[kNumArgs]; | 364 Dart_Handle dart_args[kNumArgs]; |
355 dart_args[0] = library_url; | 365 dart_args[0] = library_url; |
356 dart_args[1] = url; | 366 dart_args[1] = url; |
357 return Dart_Invoke( | 367 return Dart_Invoke( |
358 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); | 368 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); |
359 } | 369 } |
360 | 370 |
361 | 371 |
362 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, | 372 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, |
363 Dart_Handle url, | 373 Dart_Handle url, |
364 Dart_Handle library_url, | 374 Dart_Handle library_url) { |
365 Dart_Handle builtin_lib) { | 375 IsolateData* isolate_data = |
376 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
377 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
366 const int kNumArgs = 3; | 378 const int kNumArgs = 3; |
367 Dart_Handle dart_args[kNumArgs]; | 379 Dart_Handle dart_args[kNumArgs]; |
368 dart_args[0] = tag; | 380 dart_args[0] = tag; |
369 dart_args[1] = url; | 381 dart_args[1] = url; |
370 dart_args[2] = library_url; | 382 dart_args[2] = library_url; |
371 return Dart_Invoke(builtin_lib, | 383 return Dart_Invoke(builtin_lib, |
372 DartUtils::NewString("_loadDataAsync"), | 384 DartUtils::NewString("_loadDataAsync"), |
373 kNumArgs, | 385 kNumArgs, |
374 dart_args); | 386 dart_args); |
375 } | 387 } |
(...skipping 24 matching lines...) Expand all Loading... | |
400 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 412 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
401 | 413 |
402 // Handle URI canonicalization requests. | 414 // Handle URI canonicalization requests. |
403 if (tag == Dart_kCanonicalizeUrl) { | 415 if (tag == Dart_kCanonicalizeUrl) { |
404 // If this is a Dart Scheme URL or 'part' of a io library | 416 // If this is a Dart Scheme URL or 'part' of a io library |
405 // then it is not modified as it will be handled internally. | 417 // then it is not modified as it will be handled internally. |
406 if (is_dart_scheme_url || is_io_library) { | 418 if (is_dart_scheme_url || is_io_library) { |
407 return url; | 419 return url; |
408 } | 420 } |
409 // Resolve the url within the context of the library's URL. | 421 // Resolve the url within the context of the library's URL. |
410 Dart_Handle builtin_lib = | 422 return ResolveUri(library_url, url); |
411 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
412 RETURN_IF_ERROR(builtin_lib); | |
413 return ResolveUri(library_url, url, builtin_lib); | |
414 } | 423 } |
415 | 424 |
416 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | 425 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). |
417 if (is_dart_scheme_url) { | 426 if (is_dart_scheme_url) { |
418 if (tag == Dart_kImportTag) { | 427 if (tag == Dart_kImportTag) { |
419 // Handle imports of other built-in libraries present in the SDK. | 428 // Handle imports of other built-in libraries present in the SDK. |
420 if (DartUtils::IsDartIOLibURL(url_string)) { | 429 if (DartUtils::IsDartIOLibURL(url_string)) { |
421 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | 430 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); |
422 } | 431 } |
423 return NewError("The built-in library '%s' is not available" | 432 return NewError("The built-in library '%s' is not available" |
(...skipping 16 matching lines...) Expand all Loading... | |
440 return Dart_LoadSource( | 449 return Dart_LoadSource( |
441 library, | 450 library, |
442 part_uri_obj, | 451 part_uri_obj, |
443 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | 452 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); |
444 } else { | 453 } else { |
445 ASSERT(tag == Dart_kImportTag); | 454 ASSERT(tag == Dart_kImportTag); |
446 return NewError("Unable to import '%s' ", url_string); | 455 return NewError("Unable to import '%s' ", url_string); |
447 } | 456 } |
448 } | 457 } |
449 | 458 |
450 Dart_Handle builtin_lib = | |
451 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
452 RETURN_IF_ERROR(builtin_lib); | |
453 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 459 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
454 // Load a native code shared library to use in a native extension | 460 // Load a native code shared library to use in a native extension |
455 if (tag != Dart_kImportTag) { | 461 if (tag != Dart_kImportTag) { |
456 return NewError("Dart extensions must use import: '%s'", url_string); | 462 return NewError("Dart extensions must use import: '%s'", url_string); |
457 } | 463 } |
458 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); | 464 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); |
459 if (Dart_IsError(path_parts)) { | 465 if (Dart_IsError(path_parts)) { |
460 return path_parts; | 466 return path_parts; |
461 } | 467 } |
462 const char* extension_directory = NULL; | 468 const char* extension_directory = NULL; |
463 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); | 469 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); |
464 const char* extension_filename = NULL; | 470 const char* extension_filename = NULL; |
465 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_filename); | 471 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_filename); |
466 const char* extension_name = NULL; | 472 const char* extension_name = NULL; |
467 Dart_StringToCString(Dart_ListGetAt(path_parts, 2), &extension_name); | 473 Dart_StringToCString(Dart_ListGetAt(path_parts, 2), &extension_name); |
468 | 474 |
469 return Extensions::LoadExtension(extension_directory, | 475 return Extensions::LoadExtension(extension_directory, |
470 extension_filename, | 476 extension_filename, |
471 extension_name, | 477 extension_name, |
472 library); | 478 library); |
473 } | 479 } |
474 | 480 |
475 // Handle 'import' or 'part' requests for all other URIs. Call dart code to | 481 // Handle 'import' or 'part' requests for all other URIs. Call dart code to |
476 // read the source code asynchronously. | 482 // read the source code asynchronously. |
477 return LoadDataAsync_Invoke(Dart_NewInteger(tag), | 483 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); |
478 url, | |
479 library_url, | |
480 builtin_lib); | |
481 } | 484 } |
482 | 485 |
483 | 486 |
484 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, | 487 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, |
485 intptr_t* buffer_len, | 488 intptr_t* buffer_len, |
486 bool* is_snapshot) { | 489 bool* is_snapshot) { |
487 intptr_t len = sizeof(magic_number); | 490 intptr_t len = sizeof(magic_number); |
488 if (*buffer_len <= len) { | 491 if (*buffer_len <= len) { |
489 *is_snapshot = false; | 492 *is_snapshot = false; |
490 return text_buffer; | 493 return text_buffer; |
(...skipping 11 matching lines...) Expand all Loading... | |
502 } | 505 } |
503 | 506 |
504 | 507 |
505 void DartUtils::WriteMagicNumber(File* file) { | 508 void DartUtils::WriteMagicNumber(File* file) { |
506 // Write a magic number and version information into the snapshot file. | 509 // Write a magic number and version information into the snapshot file. |
507 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); | 510 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); |
508 ASSERT(bytes_written); | 511 ASSERT(bytes_written); |
509 } | 512 } |
510 | 513 |
511 | 514 |
512 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 515 Dart_Handle DartUtils::LoadScript(const char* script_uri) { |
513 Dart_Handle builtin_lib) { | |
514 Dart_Handle uri = Dart_NewStringFromCString(script_uri); | 516 Dart_Handle uri = Dart_NewStringFromCString(script_uri); |
515 IsolateData* isolate_data = | 517 IsolateData* isolate_data = |
516 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 518 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
517 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); | 519 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); |
518 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); | 520 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null()); |
519 } | 521 } |
520 | 522 |
521 | 523 |
522 // Callback function, gets called from asynchronous script and library | 524 // Callback function, gets called from asynchronous script and library |
523 // reading code when there is an i/o error. | 525 // reading code when there is an i/o error. |
524 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { | 526 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { |
525 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); | 527 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); |
526 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); | 528 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); |
527 Dart_Handle error = Dart_GetNativeArgument(args, 2); | 529 Dart_Handle error = Dart_GetNativeArgument(args, 2); |
528 | 530 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 } else { | 651 } else { |
650 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); | 652 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); |
651 Dart_PropagateError(err); | 653 Dart_PropagateError(err); |
652 } | 654 } |
653 } | 655 } |
654 | 656 |
655 | 657 |
656 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 658 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
657 Dart_Handle internal_lib, | 659 Dart_Handle internal_lib, |
658 bool is_service_isolate, | 660 bool is_service_isolate, |
659 bool trace_loading, | 661 bool trace_loading) { |
660 const char* package_root, | |
661 const char* packages_config) { | |
662 // Setup the internal library's 'internalPrint' function. | 662 // Setup the internal library's 'internalPrint' function. |
663 Dart_Handle print = Dart_Invoke( | 663 Dart_Handle print = Dart_Invoke( |
664 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 664 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
665 RETURN_IF_ERROR(print); | 665 RETURN_IF_ERROR(print); |
666 Dart_Handle result = | 666 Dart_Handle result = |
667 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 667 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
668 RETURN_IF_ERROR(result); | 668 RETURN_IF_ERROR(result); |
669 | 669 |
670 if (!is_service_isolate) { | 670 if (!is_service_isolate) { |
671 if (IsWindowsHost()) { | 671 if (IsWindowsHost()) { |
672 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 672 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
673 RETURN_IF_ERROR(result); | 673 RETURN_IF_ERROR(result); |
674 } | 674 } |
675 if (trace_loading) { | 675 if (trace_loading) { |
676 result = Dart_SetField(builtin_lib, | 676 result = Dart_SetField(builtin_lib, |
677 NewString("_traceLoading"), Dart_True()); | 677 NewString("_traceLoading"), Dart_True()); |
678 RETURN_IF_ERROR(result); | 678 RETURN_IF_ERROR(result); |
679 } | 679 } |
680 // Set current working directory. | 680 // Set current working directory. |
681 result = SetWorkingDirectory(builtin_lib); | 681 result = SetWorkingDirectory(); |
682 RETURN_IF_ERROR(result); | |
683 // Wait for the service isolate to initialize the load port. | |
684 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); | |
685 if (load_port == ILLEGAL_PORT) { | |
686 return Dart_NewUnhandledExceptionError( | |
687 NewDartUnsupportedError("Service did not return load port.")); | |
688 } | |
689 result = Builtin::SetLoadPort(load_port); | |
690 RETURN_IF_ERROR(result); | |
691 } | |
692 | |
693 // Set up package root if specified. | |
694 if (package_root != NULL) { | |
695 ASSERT(packages_config == NULL); | |
696 result = NewString(package_root); | |
697 RETURN_IF_ERROR(result); | |
698 const int kNumArgs = 1; | |
699 Dart_Handle dart_args[kNumArgs]; | |
700 dart_args[0] = result; | |
701 result = Dart_Invoke(builtin_lib, | |
702 NewString("_setPackageRoot"), | |
703 kNumArgs, | |
704 dart_args); | |
705 RETURN_IF_ERROR(result); | |
706 } else if (packages_config != NULL) { | |
707 result = NewString(packages_config); | |
708 RETURN_IF_ERROR(result); | |
709 const int kNumArgs = 1; | |
710 Dart_Handle dart_args[kNumArgs]; | |
711 dart_args[0] = result; | |
712 result = Dart_Invoke(builtin_lib, | |
713 NewString("_loadPackagesMap"), | |
714 kNumArgs, | |
715 dart_args); | |
716 RETURN_IF_ERROR(result); | 682 RETURN_IF_ERROR(result); |
717 } | 683 } |
718 return Dart_True(); | 684 return Dart_True(); |
719 } | 685 } |
720 | 686 |
721 | 687 |
722 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 688 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
723 Dart_Handle builtin_lib, | 689 Dart_Handle builtin_lib, |
724 bool is_service_isolate) { | 690 bool is_service_isolate) { |
725 if (!is_service_isolate) { | 691 if (!is_service_isolate) { |
(...skipping 26 matching lines...) Expand all Loading... | |
752 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { | 718 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { |
753 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); | 719 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); |
754 } | 720 } |
755 | 721 |
756 | 722 |
757 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 723 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
758 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); | 724 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); |
759 } | 725 } |
760 | 726 |
761 | 727 |
762 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 728 Dart_Handle DartUtils::SetupServiceLoadPort() { |
763 const char* packages_config, | 729 // Wait for the service isolate to initialize the load port. |
764 bool is_service_isolate, | 730 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); |
765 bool trace_loading, | 731 if (load_port == ILLEGAL_PORT) { |
766 Dart_Handle builtin_lib) { | 732 return Dart_NewUnhandledExceptionError( |
733 NewDartUnsupportedError("Service did not return load port.")); | |
734 } | |
735 return Builtin::SetLoadPort(load_port); | |
736 } | |
737 | |
738 | |
739 Dart_Handle DartUtils::SetupPackageRoot(const char* package_root, | |
740 const char* packages_config) { | |
741 // Set up package root if specified. | |
742 if (package_root != NULL) { | |
743 ASSERT(packages_config == NULL); | |
744 Dart_Handle result = NewString(package_root); | |
745 RETURN_IF_ERROR(result); | |
746 IsolateData* isolate_data = | |
747 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
748 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
749 const int kNumArgs = 1; | |
750 Dart_Handle dart_args[kNumArgs]; | |
751 dart_args[0] = result; | |
752 result = Dart_Invoke(builtin_lib, | |
753 NewString("_setPackageRoot"), | |
754 kNumArgs, | |
755 dart_args); | |
756 RETURN_IF_ERROR(result); | |
757 } else if (packages_config != NULL) { | |
758 Dart_Handle result = NewString(packages_config); | |
759 RETURN_IF_ERROR(result); | |
760 IsolateData* isolate_data = | |
761 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
762 Dart_Handle builtin_lib = isolate_data->builtin_lib(); | |
763 const int kNumArgs = 1; | |
764 Dart_Handle dart_args[kNumArgs]; | |
765 dart_args[0] = result; | |
766 result = Dart_Invoke(builtin_lib, | |
767 NewString("_loadPackagesMap"), | |
768 kNumArgs, | |
769 dart_args); | |
770 RETURN_IF_ERROR(result); | |
771 } | |
772 return Dart_True(); | |
773 } | |
774 | |
775 | |
776 Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate, | |
777 bool trace_loading) { | |
767 // First ensure all required libraries are available. | 778 // First ensure all required libraries are available. |
768 Dart_Handle url = NewString(kCoreLibURL); | 779 Dart_Handle url = NewString(kCoreLibURL); |
769 RETURN_IF_ERROR(url); | 780 RETURN_IF_ERROR(url); |
770 Dart_Handle core_lib = Dart_LookupLibrary(url); | 781 Dart_Handle core_lib = Dart_LookupLibrary(url); |
771 RETURN_IF_ERROR(core_lib); | 782 RETURN_IF_ERROR(core_lib); |
772 url = NewString(kAsyncLibURL); | 783 url = NewString(kAsyncLibURL); |
773 RETURN_IF_ERROR(url); | 784 RETURN_IF_ERROR(url); |
774 Dart_Handle async_lib = Dart_LookupLibrary(url); | 785 Dart_Handle async_lib = Dart_LookupLibrary(url); |
775 RETURN_IF_ERROR(async_lib); | 786 RETURN_IF_ERROR(async_lib); |
776 url = NewString(kIsolateLibURL); | 787 url = NewString(kIsolateLibURL); |
777 RETURN_IF_ERROR(url); | 788 RETURN_IF_ERROR(url); |
778 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 789 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
779 RETURN_IF_ERROR(isolate_lib); | 790 RETURN_IF_ERROR(isolate_lib); |
780 url = NewString(kInternalLibURL); | 791 url = NewString(kInternalLibURL); |
781 RETURN_IF_ERROR(url); | 792 RETURN_IF_ERROR(url); |
782 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 793 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
783 RETURN_IF_ERROR(internal_lib); | 794 RETURN_IF_ERROR(internal_lib); |
795 Dart_Handle builtin_lib = | |
796 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
797 RETURN_IF_ERROR(builtin_lib); | |
784 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 798 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
785 RETURN_IF_ERROR(io_lib); | 799 RETURN_IF_ERROR(io_lib); |
786 | 800 |
801 // Setup the builtin library in a persistent handle attached the isolate | |
802 // specific data as we seem to lookup and use builtin lib a lot. | |
803 IsolateData* isolate_data = | |
804 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
805 ASSERT(isolate_data != NULL); | |
806 isolate_data->set_builtin_lib(builtin_lib); | |
807 | |
787 // We need to ensure that all the scripts loaded so far are finalized | 808 // We need to ensure that all the scripts loaded so far are finalized |
788 // as we are about to invoke some Dart code below to setup closures. | 809 // as we are about to invoke some Dart code below to setup closures. |
789 Dart_Handle result = Dart_FinalizeLoading(false); | 810 Dart_Handle result = Dart_FinalizeLoading(false); |
790 RETURN_IF_ERROR(result); | 811 RETURN_IF_ERROR(result); |
791 | 812 |
792 result = PrepareBuiltinLibrary(builtin_lib, | 813 result = PrepareBuiltinLibrary(builtin_lib, |
793 internal_lib, | 814 internal_lib, |
794 is_service_isolate, | 815 is_service_isolate, |
795 trace_loading, | 816 trace_loading); |
796 package_root, | |
797 packages_config); | |
798 RETURN_IF_ERROR(result); | 817 RETURN_IF_ERROR(result); |
799 | 818 |
800 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); | 819 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); |
801 RETURN_IF_ERROR(PrepareCoreLibrary( | 820 RETURN_IF_ERROR(PrepareCoreLibrary( |
802 core_lib, builtin_lib, is_service_isolate)); | 821 core_lib, builtin_lib, is_service_isolate)); |
803 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); | 822 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); |
804 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); | 823 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); |
805 return result; | 824 return result; |
806 } | 825 } |
807 | 826 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 new CObjectString(CObject::NewString(os_error->message())); | 1281 new CObjectString(CObject::NewString(os_error->message())); |
1263 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1282 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1264 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1283 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1265 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1284 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1266 result->SetAt(2, error_message); | 1285 result->SetAt(2, error_message); |
1267 return result; | 1286 return result; |
1268 } | 1287 } |
1269 | 1288 |
1270 } // namespace bin | 1289 } // namespace bin |
1271 } // namespace dart | 1290 } // namespace dart |
OLD | NEW |