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

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

Issue 983713002: Remove 'dart:io' import in builtin.dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« runtime/bin/builtin.dart ('K') | « runtime/bin/builtin_natives.cc ('k') | no next file » | 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) 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"
(...skipping 29 matching lines...) Expand all
40 40
41 static bool IsWindowsHost() { 41 static bool IsWindowsHost() {
42 #if defined(TARGET_OS_WINDOWS) 42 #if defined(TARGET_OS_WINDOWS)
43 return true; 43 return true;
44 #else // defined(TARGET_OS_WINDOWS) 44 #else // defined(TARGET_OS_WINDOWS)
45 return false; 45 return false;
46 #endif // defined(TARGET_OS_WINDOWS) 46 #endif // defined(TARGET_OS_WINDOWS)
47 } 47 }
48 48
49 49
50 // Experimental flag that offloads all script loading I/O onto
51 // the service isolate. Disabled for now.
52 #define LOAD_VIA_SERVICE_ISOLATE
53
54 const char* DartUtils::MapLibraryUrl(CommandLineOptions* url_mapping, 50 const char* DartUtils::MapLibraryUrl(CommandLineOptions* url_mapping,
55 const char* url_string) { 51 const char* url_string) {
56 ASSERT(url_mapping != NULL); 52 ASSERT(url_mapping != NULL);
57 // We need to check if the passed in url is found in the url_mapping array, 53 // We need to check if the passed in url is found in the url_mapping array,
58 // in that case use the mapped entry. 54 // in that case use the mapped entry.
59 intptr_t len = strlen(url_string); 55 intptr_t len = strlen(url_string);
60 for (intptr_t idx = 0; idx < url_mapping->count(); idx++) { 56 for (intptr_t idx = 0; idx < url_mapping->count(); idx++) {
61 const char* url_name = url_mapping->GetArgument(idx); 57 const char* url_name = url_mapping->GetArgument(idx);
62 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) { 58 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) {
63 const char* url_mapped_name = url_name + len + 1; 59 const char* url_mapped_name = url_name + len + 1;
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // Write a magic number and version information into the snapshot file. 472 // Write a magic number and version information into the snapshot file.
477 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); 473 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number));
478 ASSERT(bytes_written); 474 ASSERT(bytes_written);
479 } 475 }
480 476
481 477
482 Dart_Handle DartUtils::LoadScript(const char* script_uri, 478 Dart_Handle DartUtils::LoadScript(const char* script_uri,
483 Dart_Handle builtin_lib) { 479 Dart_Handle builtin_lib) {
484 Dart_Handle uri = Dart_NewStringFromCString(script_uri); 480 Dart_Handle uri = Dart_NewStringFromCString(script_uri);
485 481
486 #if defined(LOAD_VIA_SERVICE_ISOLATE)
487 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); 482 Dart_Port load_port = Dart_ServiceWaitForLoadPort();
488 if (load_port == ILLEGAL_PORT) { 483 if (load_port == ILLEGAL_PORT) {
489 return NewDartUnsupportedError("Service did not return load port."); 484 return NewDartUnsupportedError("Service did not return load port.");
490 } 485 }
491 Builtin::SetLoadPort(load_port); 486 Builtin::SetLoadPort(load_port);
492 #endif
493 487
494 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); 488 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib);
495 } 489 }
496 490
497 491
498 // Callback function, gets called from asynchronous script and library 492 // Callback function, gets called from asynchronous script and library
499 // reading code when there is an i/o error. 493 // reading code when there is an i/o error.
500 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { 494 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) {
501 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); 495 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0);
502 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); 496 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 const char* suffix = Platform::LibraryExtension(); 602 const char* suffix = Platform::LibraryExtension();
609 ASSERT(suffix != NULL); 603 ASSERT(suffix != NULL);
610 Dart_Handle res = Dart_NewStringFromCString(suffix); 604 Dart_Handle res = Dart_NewStringFromCString(suffix);
611 if (Dart_IsError(res)) { 605 if (Dart_IsError(res)) {
612 Dart_PropagateError(res); 606 Dart_PropagateError(res);
613 } 607 }
614 Dart_SetReturnValue(args, res); 608 Dart_SetReturnValue(args, res);
615 } 609 }
616 610
617 611
612 void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) {
613 char* current = Directory::Current();
614 if (current != NULL) {
615 Dart_SetReturnValue(args, DartUtils::NewString(current));
616 free(current);
617 } else {
618 Dart_Handle err = DartUtils::NewError("Failed to get current directory.");
619 Dart_PropagateError(err);
620 }
621 }
622
623
618 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, 624 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib,
619 Dart_Handle internal_lib, 625 Dart_Handle internal_lib,
620 bool is_service_isolate, 626 bool is_service_isolate,
621 const char* package_root) { 627 const char* package_root) {
622 // Setup the internal library's 'internalPrint' function. 628 // Setup the internal library's 'internalPrint' function.
623 Dart_Handle print = Dart_Invoke( 629 Dart_Handle print = Dart_Invoke(
624 builtin_lib, NewString("_getPrintClosure"), 0, NULL); 630 builtin_lib, NewString("_getPrintClosure"), 0, NULL);
625 DART_CHECK_VALID(print); 631 DART_CHECK_VALID(print);
626 Dart_Handle result = 632 Dart_Handle result =
627 Dart_SetField(internal_lib, NewString("_printClosure"), print); 633 Dart_SetField(internal_lib, NewString("_printClosure"), print);
628 DART_CHECK_VALID(result); 634 DART_CHECK_VALID(result);
629 635
630 if (!is_service_isolate) { 636 if (!is_service_isolate) {
631 result = 637 result =
632 Dart_SetField(builtin_lib, NewString("_isWindows"), 638 Dart_SetField(builtin_lib, NewString("_isWindows"),
633 IsWindowsHost() ? Dart_True() : Dart_False()); 639 IsWindowsHost() ? Dart_True() : Dart_False());
634 DART_CHECK_VALID(result); 640 DART_CHECK_VALID(result);
635 } 641 }
636 642
637 #if defined(LOAD_VIA_SERVICE_ISOLATE)
638 result = Dart_SetField(builtin_lib, NewString("_load_via_service_isolate"),
639 Dart_True());
640 DART_CHECK_VALID(result);
641 #endif
642
643 if (!is_service_isolate) { 643 if (!is_service_isolate) {
644 // Set current working directory. 644 // Set current working directory.
645 result = SetWorkingDirectory(builtin_lib); 645 result = SetWorkingDirectory(builtin_lib);
646 DART_CHECK_VALID(result); 646 DART_CHECK_VALID(result);
647 } 647 }
648 648
649 // Set up package root if specified. 649 // Set up package root if specified.
650 if (package_root != NULL) { 650 if (package_root != NULL) {
651 result = NewString(package_root); 651 result = NewString(package_root);
652 DART_CHECK_VALID(result); 652 DART_CHECK_VALID(result);
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 new CObjectString(CObject::NewString(os_error->message())); 1195 new CObjectString(CObject::NewString(os_error->message()));
1196 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1196 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1197 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1197 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1198 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1198 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1199 result->SetAt(2, error_message); 1199 result->SetAt(2, error_message);
1200 return result; 1200 return result;
1201 } 1201 }
1202 1202
1203 } // namespace bin 1203 } // namespace bin
1204 } // namespace dart 1204 } // namespace dart
OLDNEW
« runtime/bin/builtin.dart ('K') | « runtime/bin/builtin_natives.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698