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

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

Issue 15832003: Change File.directory to not do any IO (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file_android.cc » ('j') | 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) 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/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 499 Dart_SetReturnValue(args, Dart_NewBoolean(result));
500 } else { 500 } else {
501 Dart_Handle err = DartUtils::NewDartOSError(); 501 Dart_Handle err = DartUtils::NewDartOSError();
502 if (Dart_IsError(err)) Dart_PropagateError(err); 502 if (Dart_IsError(err)) Dart_PropagateError(err);
503 Dart_SetReturnValue(args, err); 503 Dart_SetReturnValue(args, err);
504 } 504 }
505 Dart_ExitScope(); 505 Dart_ExitScope();
506 } 506 }
507 507
508 508
509 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) {
510 Dart_EnterScope();
511 const char* str =
512 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
513 char* str_copy = strdup(str);
514 char* path = File::GetContainingDirectory(str_copy);
515 free(str_copy);
516 if (path != NULL) {
517 Dart_SetReturnValue(args, DartUtils::NewString(path));
518 free(path);
519 } else {
520 Dart_Handle err = DartUtils::NewDartOSError();
521 if (Dart_IsError(err)) Dart_PropagateError(err);
522 Dart_SetReturnValue(args, err);
523 }
524 Dart_ExitScope();
525 }
526
527
528 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { 509 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) {
529 Dart_EnterScope(); 510 Dart_EnterScope();
530 const char* str = 511 const char* str =
531 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 512 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
532 char* path = File::GetCanonicalPath(str); 513 char* path = File::GetCanonicalPath(str);
533 if (path != NULL) { 514 if (path != NULL) {
534 Dart_SetReturnValue(args, DartUtils::NewString(path)); 515 Dart_SetReturnValue(args, DartUtils::NewString(path));
535 free(path); 516 free(path);
536 } else { 517 } else {
537 Dart_Handle err = DartUtils::NewDartOSError(); 518 Dart_Handle err = DartUtils::NewDartOSError();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 free(result); 709 free(result);
729 return path; 710 return path;
730 } else { 711 } else {
731 return CObject::NewOSError(); 712 return CObject::NewOSError();
732 } 713 }
733 } 714 }
734 return CObject::IllegalArgumentError(); 715 return CObject::IllegalArgumentError();
735 } 716 }
736 717
737 718
738 static CObject* FileDirectoryRequest(const CObjectArray& request) {
739 if (request.Length() == 2 && request[1]->IsString()) {
740 CObjectString filename(request[1]);
741 char* str_copy = strdup(filename.CString());
742 char* path = File::GetContainingDirectory(str_copy);
743 free(str_copy);
744 if (path != NULL) {
745 CObject* result = new CObjectString(CObject::NewString(path));
746 free(path);
747 return result;
748 } else {
749 return CObject::NewOSError();
750 }
751 }
752 return CObject::Null();
753 }
754
755
756 static CObject* FileCloseRequest(const CObjectArray& request) { 719 static CObject* FileCloseRequest(const CObjectArray& request) {
757 intptr_t return_value = -1; 720 intptr_t return_value = -1;
758 if (request.Length() == 2 && request[1]->IsIntptr()) { 721 if (request.Length() == 2 && request[1]->IsIntptr()) {
759 File* file = CObjectToFilePointer(request[1]); 722 File* file = CObjectToFilePointer(request[1]);
760 ASSERT(file != NULL); 723 ASSERT(file != NULL);
761 delete file; 724 delete file;
762 return_value = 0; 725 return_value = 0;
763 } 726 }
764 return new CObjectIntptr(CObject::NewIntptr(return_value)); 727 return new CObjectIntptr(CObject::NewIntptr(return_value));
765 } 728 }
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 break; 1154 break;
1192 case File::kOpenRequest: 1155 case File::kOpenRequest:
1193 response = FileOpenRequest(request); 1156 response = FileOpenRequest(request);
1194 break; 1157 break;
1195 case File::kDeleteRequest: 1158 case File::kDeleteRequest:
1196 response = FileDeleteRequest(request); 1159 response = FileDeleteRequest(request);
1197 break; 1160 break;
1198 case File::kFullPathRequest: 1161 case File::kFullPathRequest:
1199 response = FileFullPathRequest(request); 1162 response = FileFullPathRequest(request);
1200 break; 1163 break;
1201 case File::kDirectoryRequest:
1202 response = FileDirectoryRequest(request);
1203 break;
1204 case File::kCloseRequest: 1164 case File::kCloseRequest:
1205 response = FileCloseRequest(request); 1165 response = FileCloseRequest(request);
1206 break; 1166 break;
1207 case File::kPositionRequest: 1167 case File::kPositionRequest:
1208 response = FilePositionRequest(request); 1168 response = FilePositionRequest(request);
1209 break; 1169 break;
1210 case File::kSetPositionRequest: 1170 case File::kSetPositionRequest:
1211 response = FileSetPositionRequest(request); 1171 response = FileSetPositionRequest(request);
1212 break; 1172 break;
1213 case File::kTruncateRequest: 1173 case File::kTruncateRequest:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 if (service_port != ILLEGAL_PORT) { 1240 if (service_port != ILLEGAL_PORT) {
1281 // Return a send port for the service port. 1241 // Return a send port for the service port.
1282 Dart_Handle send_port = Dart_NewSendPort(service_port); 1242 Dart_Handle send_port = Dart_NewSendPort(service_port);
1283 Dart_SetReturnValue(args, send_port); 1243 Dart_SetReturnValue(args, send_port);
1284 } 1244 }
1285 Dart_ExitScope(); 1245 Dart_ExitScope();
1286 } 1246 }
1287 1247
1288 } // namespace bin 1248 } // namespace bin
1289 } // namespace dart 1249 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698