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

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

Issue 584023004: Service isolate rework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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) 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_native_api.h" 8 #include "include/dart_native_api.h"
9 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
11 #include "platform/globals.h" 11 #include "platform/globals.h"
12 12
13 #include "bin/crypto.h" 13 #include "bin/crypto.h"
14 #include "bin/directory.h" 14 #include "bin/directory.h"
15 #include "bin/extensions.h" 15 #include "bin/extensions.h"
16 #include "bin/file.h" 16 #include "bin/file.h"
17 #include "bin/io_buffer.h" 17 #include "bin/io_buffer.h"
18 #include "bin/platform.h"
18 #include "bin/socket.h" 19 #include "bin/socket.h"
19 #include "bin/utils.h" 20 #include "bin/utils.h"
20 21
21 namespace dart { 22 namespace dart {
22 namespace bin { 23 namespace bin {
23 24
24 const char* DartUtils::original_working_directory = NULL; 25 const char* DartUtils::original_working_directory = NULL;
25 const char* DartUtils::kDartScheme = "dart:"; 26 const char* DartUtils::kDartScheme = "dart:";
26 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; 27 const char* DartUtils::kDartExtensionScheme = "dart-ext:";
27 const char* DartUtils::kAsyncLibURL = "dart:async"; 28 const char* DartUtils::kAsyncLibURL = "dart:async";
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 void DartUtils::WriteMagicNumber(File* file) { 471 void DartUtils::WriteMagicNumber(File* file) {
471 // Write a magic number and version information into the snapshot file. 472 // Write a magic number and version information into the snapshot file.
472 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); 473 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number));
473 ASSERT(bytes_written); 474 ASSERT(bytes_written);
474 } 475 }
475 476
476 477
477 Dart_Handle DartUtils::LoadScript(const char* script_uri, 478 Dart_Handle DartUtils::LoadScript(const char* script_uri,
478 Dart_Handle builtin_lib) { 479 Dart_Handle builtin_lib) {
479 Dart_Handle uri = Dart_NewStringFromCString(script_uri); 480 Dart_Handle uri = Dart_NewStringFromCString(script_uri);
481
482 Dart_Port load_port = Dart_ServiceWaitForLoadPort();
483 Builtin::SetLoadPort(load_port);
siva 2015/01/27 19:12:46 Maybe return an error if load_port remains ILLEGAL
Cutch 2015/01/27 19:30:59 Done.
484
480 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); 485 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib);
481 } 486 }
482 487
483 488
484 // Callback function, gets called from asynchronous script and library 489 // Callback function, gets called from asynchronous script and library
485 // reading code when there is an i/o error. 490 // reading code when there is an i/o error.
486 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { 491 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) {
487 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); 492 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0);
488 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); 493 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1);
489 Dart_Handle error = Dart_GetNativeArgument(args, 2); 494 Dart_Handle error = Dart_GetNativeArgument(args, 2);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 Dart_Handle res = Dart_FinalizeLoading(true); 588 Dart_Handle res = Dart_FinalizeLoading(true);
584 if (Dart_IsError(res)) { 589 if (Dart_IsError(res)) {
585 // TODO(hausner): If compilation/loading errors are supposed to 590 // TODO(hausner): If compilation/loading errors are supposed to
586 // be observable by the program, we need to mark the bad library 591 // be observable by the program, we need to mark the bad library
587 // with the error instead of propagating it. 592 // with the error instead of propagating it.
588 Dart_PropagateError(res); 593 Dart_PropagateError(res);
589 } 594 }
590 } 595 }
591 596
592 597
598 void FUNCTION_NAME(Builtin_NativeLibraryExtension)(Dart_NativeArguments args) {
599 const char* suffix = Platform::LibraryExtension();
600 ASSERT(suffix != NULL);
601 Dart_Handle res = Dart_NewStringFromCString(suffix);
602 if (Dart_IsError(res)) {
603 Dart_PropagateError(res);
604 }
605 Dart_SetReturnValue(args, res);
606 }
siva 2015/01/27 19:12:46 it was not clear to me why these Builtin_Native fu
Cutch 2015/01/27 19:30:59 Acknowledged.
607
608
609 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib,
610 const char* package_root) {
611 Dart_Handle url = NewString(kInternalLibURL);
612 DART_CHECK_VALID(url);
613 Dart_Handle internal_lib = Dart_LookupLibrary(url);
614 DART_CHECK_VALID(internal_lib);
615
616 // Setup the internal library's 'internalPrint' function.
617 Dart_Handle print = Dart_Invoke(
618 builtin_lib, NewString("_getPrintClosure"), 0, NULL);
619 DART_CHECK_VALID(print);
620 Dart_Handle result =
621 Dart_SetField(internal_lib, NewString("_printClosure"), print);
622 DART_CHECK_VALID(result);
623
624 if (IsWindowsHost()) {
625 // Set running on Windows flag.
626 result = Dart_Invoke(builtin_lib, NewString("_setWindows"), 0, NULL);
627 DART_CHECK_VALID(result);
628 }
629
630 // Set current working directory.
631 result = SetWorkingDirectory(builtin_lib);
632 DART_CHECK_VALID(result);
633
634 // Set up package root if specified.
635 if (package_root != NULL) {
636 result = NewString(package_root);
637 DART_CHECK_VALID(result);
638 const int kNumArgs = 1;
639 Dart_Handle dart_args[kNumArgs];
640 dart_args[0] = result;
641 result = Dart_Invoke(builtin_lib,
642 NewString("_setPackageRoot"),
643 kNumArgs,
644 dart_args);
645 DART_CHECK_VALID(result);
646 }
647 }
648
649
650 void DartUtils::PrepareCoreLibrary(Dart_Handle builtin_lib) {
651 Dart_Handle url = NewString(kCoreLibURL);
652 DART_CHECK_VALID(url);
653 Dart_Handle core_lib = Dart_LookupLibrary(url);
654 DART_CHECK_VALID(core_lib);
655
656 // Setup the 'Uri.base' getter in dart:core.
657 Dart_Handle uri_base = Dart_Invoke(
658 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL);
659 DART_CHECK_VALID(uri_base);
660 Dart_Handle result = Dart_SetField(core_lib,
661 NewString("_uriBaseClosure"),
662 uri_base);
663 DART_CHECK_VALID(result);
664 }
665
666
667 void DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib,
668 Dart_Handle io_lib) {
669 Dart_Handle url = NewString(kIsolateLibURL);
670 DART_CHECK_VALID(url);
671 Dart_Handle isolate_lib = Dart_LookupLibrary(url);
672 DART_CHECK_VALID(isolate_lib);
673
674 // Setup the 'timer' factory in dart:async.
675 Dart_Handle timer_closure =
676 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL);
677 DART_CHECK_VALID(timer_closure);
678 Dart_Handle args[1];
679 args[0] = timer_closure;
680 DART_CHECK_VALID(Dart_Invoke(
681 async_lib, NewString("_setTimerFactoryClosure"), 1, args));
682
683 // Setup the 'scheduleImmediate' closure in dart:async.
684 Dart_Handle schedule_immediate_closure =
685 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"),
686 0, NULL);
687 args[0] = schedule_immediate_closure;
688 DART_CHECK_VALID(Dart_Invoke(
689 async_lib, NewString("_setScheduleImmediateClosure"), 1, args));
690 }
691
692
593 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, 693 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root,
594 Dart_Handle builtin_lib) { 694 Dart_Handle builtin_lib) {
595 // First ensure all required libraries are available. 695 // First ensure all required libraries are available.
596 Dart_Handle url = NewString(kAsyncLibURL); 696 Dart_Handle url = NewString(kAsyncLibURL);
597 DART_CHECK_VALID(url); 697 DART_CHECK_VALID(url);
598 Dart_Handle async_lib = Dart_LookupLibrary(url); 698 Dart_Handle async_lib = Dart_LookupLibrary(url);
599 DART_CHECK_VALID(async_lib); 699 DART_CHECK_VALID(async_lib);
600 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); 700 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
601 701
602 // We need to ensure that all the scripts loaded so far are finalized 702 // We need to ensure that all the scripts loaded so far are finalized
603 // as we are about to invoke some Dart code below to setup closures. 703 // as we are about to invoke some Dart code below to setup closures.
604 Dart_Handle result = Dart_FinalizeLoading(false); 704 Dart_Handle result = Dart_FinalizeLoading(false);
605 DART_CHECK_VALID(result); 705 DART_CHECK_VALID(result);
606 706
607 // Setup the internal library's 'internalPrint' function. 707 PrepareBuiltinLibrary(builtin_lib, package_root);
608 Dart_Handle print = Dart_Invoke( 708 PrepareAsyncLibrary(async_lib, io_lib);
609 builtin_lib, NewString("_getPrintClosure"), 0, NULL); 709 PrepareCoreLibrary(builtin_lib);
610 url = NewString(kInternalLibURL);
611 DART_CHECK_VALID(url);
612 Dart_Handle internal_lib = Dart_LookupLibrary(url);
613 DART_CHECK_VALID(internal_lib);
614 result = Dart_SetField(internal_lib,
615 NewString("_printClosure"),
616 print);
617 DART_CHECK_VALID(result);
618 710
619 // Setup the 'timer' factory. 711 return result;
620 Dart_Handle timer_closure = 712 }
621 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL);
622 Dart_Handle args[1];
623 args[0] = timer_closure;
624 DART_CHECK_VALID(Dart_Invoke(
625 async_lib, NewString("_setTimerFactoryClosure"), 1, args));
626 713
627 // Setup the 'scheduleImmediate' closure.
628 url = NewString(kIsolateLibURL);
629 DART_CHECK_VALID(url);
630 Dart_Handle isolate_lib = Dart_LookupLibrary(url);
631 DART_CHECK_VALID(isolate_lib);
632 Dart_Handle schedule_immediate_closure =
633 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"),
634 0, NULL);
635 args[0] = schedule_immediate_closure;
636 DART_CHECK_VALID(Dart_Invoke(
637 async_lib, NewString("_setScheduleImmediateClosure"), 1, args));
638 714
639 // Setup the corelib 'Uri.base' getter. 715 void DartUtils::SetupIOLibrary(const char* script_uri) {
640 url = NewString(kCoreLibURL); 716 Dart_Handle io_lib_url = NewString(kIOLibURL);
641 DART_CHECK_VALID(url); 717 DART_CHECK_VALID(io_lib_url);
642 Dart_Handle corelib = Dart_LookupLibrary(url); 718 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
643 DART_CHECK_VALID(corelib); 719 DART_CHECK_VALID(io_lib);
644 Dart_Handle uri_base = Dart_Invoke( 720 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform");
645 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); 721 DART_CHECK_VALID(platform_type);
646 DART_CHECK_VALID(uri_base); 722 Dart_Handle script_name = NewString("_nativeScript");
647 result = Dart_SetField(corelib, 723 DART_CHECK_VALID(script_name);
648 NewString("_uriBaseClosure"), 724 Dart_Handle dart_script = NewString(script_uri);
649 uri_base); 725 DART_CHECK_VALID(dart_script);
650 DART_CHECK_VALID(result); 726 Dart_Handle set_script_name =
651 727 Dart_SetField(platform_type, script_name, dart_script);
652 if (IsWindowsHost()) { 728 DART_CHECK_VALID(set_script_name);
653 // Set running on Windows flag.
654 result = Dart_Invoke(builtin_lib, NewString("_setWindows"), 0, NULL);
655 if (Dart_IsError(result)) {
656 return result;
657 }
658 }
659
660 // Set current working directory.
661 result = SetWorkingDirectory(builtin_lib);
662 if (Dart_IsError(result)) {
663 return result;
664 }
665
666 // Set up package root if specified.
667 if (package_root != NULL) {
668 result = NewString(package_root);
669 if (!Dart_IsError(result)) {
670 const int kNumArgs = 1;
671 Dart_Handle dart_args[kNumArgs];
672 dart_args[0] = result;
673 return Dart_Invoke(builtin_lib,
674 NewString("_setPackageRoot"),
675 kNumArgs,
676 dart_args);
677 }
678 }
679 return result;
680 } 729 }
681 730
682 731
683 bool DartUtils::PostNull(Dart_Port port_id) { 732 bool DartUtils::PostNull(Dart_Port port_id) {
684 // Post a message with just the null object. 733 // Post a message with just the null object.
685 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); 734 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject());
686 } 735 }
687 736
688 737
689 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { 738 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 new CObjectString(CObject::NewString(os_error->message())); 1160 new CObjectString(CObject::NewString(os_error->message()));
1112 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1161 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1113 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1162 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1114 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1163 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1115 result->SetAt(2, error_message); 1164 result->SetAt(2, error_message);
1116 return result; 1165 return result;
1117 } 1166 }
1118 1167
1119 } // namespace bin 1168 } // namespace bin
1120 } // namespace dart 1169 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/gen_snapshot.cc » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698