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

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

Issue 12315129: Make File.readSync return only the bytes read (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « no previous file | sdk/lib/io/file_impl.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) 2013, the Dart project authors. Please see the AUTHORS file
Ivan Posva 2013/02/27 18:18:56 No need to update.
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"
11 #include "bin/utils.h" 11 #include "bin/utils.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (DartUtils::GetInt64Value(length_object, &length)) { 173 if (DartUtils::GetInt64Value(length_object, &length)) {
174 uint8_t* buffer = NULL; 174 uint8_t* buffer = NULL;
175 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer); 175 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer);
176 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); 176 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
177 if (bytes_read < 0) { 177 if (bytes_read < 0) {
178 Dart_Handle err = DartUtils::NewDartOSError(); 178 Dart_Handle err = DartUtils::NewDartOSError();
179 if (Dart_IsError(err)) Dart_PropagateError(err); 179 if (Dart_IsError(err)) Dart_PropagateError(err);
180 Dart_SetReturnValue(args, err); 180 Dart_SetReturnValue(args, err);
181 } else { 181 } else {
182 if (bytes_read < length) { 182 if (bytes_read < length) {
183 // TODO(ager): cache the 'length' string if this becomes a bottle neck. 183 const int kNumArgs = 3;
184 Dart_SetField(external_array, 184 Dart_Handle dart_args[kNumArgs];
Mads Ager (google) 2013/02/27 15:02:36 I should have been beaten with a stick for doing t
185 DartUtils::NewString("length"), 185 dart_args[0] = external_array;
186 Dart_NewInteger(bytes_read)); 186 dart_args[1] = Dart_NewInteger(0);
187 dart_args[2] = Dart_NewInteger(bytes_read);
188 // TODO(sgjesse): Cache the _makeUint8ListView function somewhere.
189 Dart_Handle io_lib =
190 Dart_LookupLibrary(DartUtils::NewString("dart:io"));
191 if (Dart_IsError(io_lib)) Dart_PropagateError(io_lib);
192 Dart_Handle array_view =
193 Dart_Invoke(io_lib,
194 DartUtils::NewString("_makeUint8ListView"),
195 kNumArgs,
196 dart_args);
197 if (Dart_IsError(array_view)) Dart_PropagateError(array_view);
198 Dart_SetReturnValue(args, array_view);
199 } else {
200 Dart_SetReturnValue(args, external_array);
187 } 201 }
188 Dart_SetReturnValue(args, external_array);
189 } 202 }
190 } else { 203 } else {
191 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 204 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
192 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 205 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
193 if (Dart_IsError(err)) Dart_PropagateError(err); 206 if (Dart_IsError(err)) Dart_PropagateError(err);
194 Dart_SetReturnValue(args, err); 207 Dart_SetReturnValue(args, err);
195 } 208 }
196 Dart_ExitScope(); 209 Dart_ExitScope();
197 } 210 }
198 211
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 Dart_EnterScope(); 989 Dart_EnterScope();
977 Dart_SetReturnValue(args, Dart_Null()); 990 Dart_SetReturnValue(args, Dart_Null());
978 Dart_Port service_port = File::GetServicePort(); 991 Dart_Port service_port = File::GetServicePort();
979 if (service_port != ILLEGAL_PORT) { 992 if (service_port != ILLEGAL_PORT) {
980 // Return a send port for the service port. 993 // Return a send port for the service port.
981 Dart_Handle send_port = Dart_NewSendPort(service_port); 994 Dart_Handle send_port = Dart_NewSendPort(service_port);
982 Dart_SetReturnValue(args, send_port); 995 Dart_SetReturnValue(args, send_port);
983 } 996 }
984 Dart_ExitScope(); 997 Dart_ExitScope();
985 } 998 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698