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

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

Issue 10443008: Implement File.lastModified. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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/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/thread.h" 9 #include "bin/thread.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 350 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
351 } else { 351 } else {
352 Dart_Handle err = DartUtils::NewDartOSError(); 352 Dart_Handle err = DartUtils::NewDartOSError();
353 if (Dart_IsError(err)) Dart_PropagateError(err); 353 if (Dart_IsError(err)) Dart_PropagateError(err);
354 Dart_SetReturnValue(args, err); 354 Dart_SetReturnValue(args, err);
355 } 355 }
356 Dart_ExitScope(); 356 Dart_ExitScope();
357 } 357 }
358 358
359 359
360 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) {
361 Dart_EnterScope();
362 const char* name =
363 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
364 intptr_t return_value = File::LastModified(name);
365 if (return_value >= 0) {
366 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
367 } else {
368 Dart_Handle err = DartUtils::NewDartOSError();
369 if (Dart_IsError(err)) Dart_PropagateError(err);
370 Dart_SetReturnValue(args, err);
371 }
372 Dart_ExitScope();
373 }
374
375
360 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { 376 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) {
361 Dart_EnterScope(); 377 Dart_EnterScope();
362 intptr_t value = 378 intptr_t value =
363 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 379 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
364 File* file = reinterpret_cast<File*>(value); 380 File* file = reinterpret_cast<File*>(value);
365 ASSERT(file != NULL); 381 ASSERT(file != NULL);
366 if (file->Flush()) { 382 if (file->Flush()) {
367 Dart_SetReturnValue(args, Dart_True()); 383 Dart_SetReturnValue(args, Dart_True());
368 } else { 384 } else {
369 Dart_Handle err = DartUtils::NewDartOSError(); 385 Dart_Handle err = DartUtils::NewDartOSError();
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 if (return_value >= 0) { 688 if (return_value >= 0) {
673 return new CObjectIntptr(CObject::NewIntptr(return_value)); 689 return new CObjectIntptr(CObject::NewIntptr(return_value));
674 } else { 690 } else {
675 return CObject::NewOSError(); 691 return CObject::NewOSError();
676 } 692 }
677 } 693 }
678 return CObject::IllegalArgumentError(); 694 return CObject::IllegalArgumentError();
679 } 695 }
680 696
681 697
698 static CObject* FileLastModifiedRequest(const CObjectArray& request) {
699 if (request.Length() == 2 && request[1]->IsString()) {
700 CObjectString filename(request[1]);
701 intptr_t return_value = File::LastModified(filename.CString());
702 if (return_value >= 0) {
703 return new CObjectIntptr(CObject::NewIntptr(return_value));
704 } else {
705 return CObject::NewOSError();
706 }
707 }
708 return CObject::IllegalArgumentError();
709 }
710
711
682 static CObject* FileFlushRequest(const CObjectArray& request) { 712 static CObject* FileFlushRequest(const CObjectArray& request) {
683 if (request.Length() == 2 && request[1]->IsIntptr()) { 713 if (request.Length() == 2 && request[1]->IsIntptr()) {
684 File* file = CObjectToFilePointer(request[1]); 714 File* file = CObjectToFilePointer(request[1]);
685 ASSERT(file != NULL); 715 ASSERT(file != NULL);
686 if (!file->IsClosed()) { 716 if (!file->IsClosed()) {
687 if (file->Flush()) { 717 if (file->Flush()) {
688 return CObject::True(); 718 return CObject::True();
689 } else { 719 } else {
690 return CObject::NewOSError(); 720 return CObject::NewOSError();
691 } 721 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 break; 906 break;
877 case File::kTruncateRequest: 907 case File::kTruncateRequest:
878 response = FileTruncateRequest(request); 908 response = FileTruncateRequest(request);
879 break; 909 break;
880 case File::kLengthRequest: 910 case File::kLengthRequest:
881 response = FileLengthRequest(request); 911 response = FileLengthRequest(request);
882 break; 912 break;
883 case File::kLengthFromNameRequest: 913 case File::kLengthFromNameRequest:
884 response = FileLengthFromNameRequest(request); 914 response = FileLengthFromNameRequest(request);
885 break; 915 break;
916 case File::kLastModifiedRequest:
917 response = FileLastModifiedRequest(request);
918 break;
886 case File::kFlushRequest: 919 case File::kFlushRequest:
887 response = FileFlushRequest(request); 920 response = FileFlushRequest(request);
888 break; 921 break;
889 case File::kReadByteRequest: 922 case File::kReadByteRequest:
890 response = FileReadByteRequest(request); 923 response = FileReadByteRequest(request);
891 break; 924 break;
892 case File::kWriteByteRequest: 925 case File::kWriteByteRequest:
893 response = FileWriteByteRequest(request); 926 response = FileWriteByteRequest(request);
894 break; 927 break;
895 case File::kReadListRequest: 928 case File::kReadListRequest:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 Dart_EnterScope(); 973 Dart_EnterScope();
941 Dart_SetReturnValue(args, Dart_Null()); 974 Dart_SetReturnValue(args, Dart_Null());
942 Dart_Port service_port = File::GetServicePort(); 975 Dart_Port service_port = File::GetServicePort();
943 if (service_port != kIllegalPort) { 976 if (service_port != kIllegalPort) {
944 // Return a send port for the service port. 977 // Return a send port for the service port.
945 Dart_Handle send_port = Dart_NewSendPort(service_port); 978 Dart_Handle send_port = Dart_NewSendPort(service_port);
946 Dart_SetReturnValue(args, send_port); 979 Dart_SetReturnValue(args, send_port);
947 } 980 }
948 Dart_ExitScope(); 981 Dart_ExitScope();
949 } 982 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698