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

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

Issue 11345025: Use the encoding parameter for writeString on RandomAccessFile objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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_patch.dart » ('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) 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } else { 151 } else {
152 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 152 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
153 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 153 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
154 if (Dart_IsError(err)) Dart_PropagateError(err); 154 if (Dart_IsError(err)) Dart_PropagateError(err);
155 Dart_SetReturnValue(args, err); 155 Dart_SetReturnValue(args, err);
156 } 156 }
157 Dart_ExitScope(); 157 Dart_ExitScope();
158 } 158 }
159 159
160 160
161 void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) {
162 Dart_EnterScope();
163 intptr_t value =
164 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
165 File* file = reinterpret_cast<File*>(value);
166 ASSERT(file != NULL);
167 const char* str =
168 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
169 int bytes_written = file->Write(reinterpret_cast<const void*>(str),
170 strlen(str));
171 if (bytes_written >= 0) {
172 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written));
173 } else {
174 Dart_Handle err = DartUtils::NewDartOSError();
175 if (Dart_IsError(err)) Dart_PropagateError(err);
176 Dart_SetReturnValue(args, err);
177 }
178 Dart_ExitScope();
179 }
180
181
182 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { 161 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) {
183 Dart_EnterScope(); 162 Dart_EnterScope();
184 intptr_t value = 163 intptr_t value =
185 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 164 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
186 File* file = reinterpret_cast<File*>(value); 165 File* file = reinterpret_cast<File*>(value);
187 ASSERT(file != NULL); 166 ASSERT(file != NULL);
188 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 167 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
189 ASSERT(Dart_IsList(buffer_obj)); 168 ASSERT(Dart_IsList(buffer_obj));
190 // Offset and length arguments are checked in Dart code to be 169 // Offset and length arguments are checked in Dart code to be
191 // integers and have the property that (offset + length) <= 170 // integers and have the property that (offset + length) <=
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 return CObject::NewOSError(); 833 return CObject::NewOSError();
855 } 834 }
856 } else { 835 } else {
857 return CObject::FileClosedError(); 836 return CObject::FileClosedError();
858 } 837 }
859 } 838 }
860 return CObject::IllegalArgumentError(); 839 return CObject::IllegalArgumentError();
861 } 840 }
862 841
863 842
864 static CObject* FileWriteStringRequest(const CObjectArray& request) {
865 if (request.Length() == 3 &&
866 request[1]->IsIntptr() &&
867 request[2]->IsString()) {
868 File* file = CObjectToFilePointer(request[1]);
869 ASSERT(file != NULL);
870 if (!file->IsClosed()) {
871 CObjectString str(request[2]);
872 const void* buffer = reinterpret_cast<const void*>(str.CString());
873 int64_t bytes_written = file->Write(buffer, str.Length());
874 return new CObjectInt64(CObject::NewInt64(bytes_written));
875 } else {
876 return CObject::FileClosedError();
877 }
878 }
879 return CObject::IllegalArgumentError();
880 }
881
882
883 void FileService(Dart_Port dest_port_id, 843 void FileService(Dart_Port dest_port_id,
884 Dart_Port reply_port_id, 844 Dart_Port reply_port_id,
885 Dart_CObject* message) { 845 Dart_CObject* message) {
886 CObject* response = CObject::False(); 846 CObject* response = CObject::False();
887 CObjectArray request(message); 847 CObjectArray request(message);
888 if (message->type == Dart_CObject::kArray) { 848 if (message->type == Dart_CObject::kArray) {
889 if (request.Length() > 1 && request[0]->IsInt32()) { 849 if (request.Length() > 1 && request[0]->IsInt32()) {
890 CObjectInt32 requestType(request[0]); 850 CObjectInt32 requestType(request[0]);
891 switch (requestType.Value()) { 851 switch (requestType.Value()) {
892 case File::kExistsRequest: 852 case File::kExistsRequest:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 break; 896 break;
937 case File::kWriteByteRequest: 897 case File::kWriteByteRequest:
938 response = FileWriteByteRequest(request); 898 response = FileWriteByteRequest(request);
939 break; 899 break;
940 case File::kReadListRequest: 900 case File::kReadListRequest:
941 response = FileReadListRequest(request); 901 response = FileReadListRequest(request);
942 break; 902 break;
943 case File::kWriteListRequest: 903 case File::kWriteListRequest:
944 response = FileWriteListRequest(request); 904 response = FileWriteListRequest(request);
945 break; 905 break;
946 case File::kWriteStringRequest:
947 response = FileWriteStringRequest(request);
948 break;
949 default: 906 default:
950 UNREACHABLE(); 907 UNREACHABLE();
951 } 908 }
952 } 909 }
953 } 910 }
954 911
955 Dart_PostCObject(reply_port_id, response->AsApiCObject()); 912 Dart_PostCObject(reply_port_id, response->AsApiCObject());
956 } 913 }
957 914
958 915
(...skipping 26 matching lines...) Expand all
985 Dart_EnterScope(); 942 Dart_EnterScope();
986 Dart_SetReturnValue(args, Dart_Null()); 943 Dart_SetReturnValue(args, Dart_Null());
987 Dart_Port service_port = File::GetServicePort(); 944 Dart_Port service_port = File::GetServicePort();
988 if (service_port != ILLEGAL_PORT) { 945 if (service_port != ILLEGAL_PORT) {
989 // Return a send port for the service port. 946 // Return a send port for the service port.
990 Dart_Handle send_port = Dart_NewSendPort(service_port); 947 Dart_Handle send_port = Dart_NewSendPort(service_port);
991 Dart_SetReturnValue(args, send_port); 948 Dart_SetReturnValue(args, send_port);
992 } 949 }
993 Dart_ExitScope(); 950 Dart_ExitScope();
994 } 951 }
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698