| OLD | NEW |
| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 | 179 |
| 180 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { | 180 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { |
| 181 Dart_EnterScope(); | 181 Dart_EnterScope(); |
| 182 intptr_t value = | 182 intptr_t value = |
| 183 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 183 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 184 File* file = reinterpret_cast<File*>(value); | 184 File* file = reinterpret_cast<File*>(value); |
| 185 ASSERT(file != NULL); | 185 ASSERT(file != NULL); |
| 186 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 186 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 187 ASSERT(Dart_IsList(buffer_obj)); | 187 ASSERT(Dart_IsList(buffer_obj)); |
| 188 // Offset and length arguments are checked in Dart code to be |
| 189 // integers and have the property that (offset + length) <= |
| 190 // list.length. Therefore, it is safe to extract their value as |
| 191 // 64-bit integers. |
| 188 int64_t offset = | 192 int64_t offset = |
| 189 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 193 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 190 int64_t length = | 194 int64_t length = |
| 191 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 195 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 192 intptr_t array_len = 0; | 196 intptr_t array_len = 0; |
| 193 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 197 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 194 if (Dart_IsError(result)) Dart_PropagateError(result); | 198 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 195 ASSERT((offset + length) <= array_len); | 199 ASSERT((offset + length) <= array_len); |
| 196 uint8_t* buffer = new uint8_t[length]; | 200 uint8_t* buffer = new uint8_t[length]; |
| 197 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | 201 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 213 | 217 |
| 214 | 218 |
| 215 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { | 219 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| 216 Dart_EnterScope(); | 220 Dart_EnterScope(); |
| 217 intptr_t value = | 221 intptr_t value = |
| 218 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 222 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 219 File* file = reinterpret_cast<File*>(value); | 223 File* file = reinterpret_cast<File*>(value); |
| 220 ASSERT(file != NULL); | 224 ASSERT(file != NULL); |
| 221 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 225 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 222 ASSERT(Dart_IsList(buffer_obj)); | 226 ASSERT(Dart_IsList(buffer_obj)); |
| 227 // Offset and length arguments are checked in Dart code to be |
| 228 // integers and have the property that (offset + length) <= |
| 229 // list.length. Therefore, it is safe to extract their value as |
| 230 // 64-bit integers. |
| 223 int64_t offset = | 231 int64_t offset = |
| 224 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 232 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 225 int64_t length = | 233 int64_t length = |
| 226 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 234 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 227 intptr_t buffer_len = 0; | 235 intptr_t buffer_len = 0; |
| 228 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 236 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 229 if (Dart_IsError(result)) Dart_PropagateError(result); | 237 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 230 ASSERT((offset + length) <= buffer_len); | 238 ASSERT((offset + length) <= buffer_len); |
| 231 uint8_t* buffer = new uint8_t[length]; | 239 uint8_t* buffer = new uint8_t[length]; |
| 232 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); | 240 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 Dart_ExitScope(); | 297 Dart_ExitScope(); |
| 290 } | 298 } |
| 291 | 299 |
| 292 | 300 |
| 293 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { | 301 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { |
| 294 Dart_EnterScope(); | 302 Dart_EnterScope(); |
| 295 intptr_t value = | 303 intptr_t value = |
| 296 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 304 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 297 File* file = reinterpret_cast<File*>(value); | 305 File* file = reinterpret_cast<File*>(value); |
| 298 ASSERT(file != NULL); | 306 ASSERT(file != NULL); |
| 299 int64_t length = | 307 int64_t length = 0; |
| 300 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 308 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { |
| 301 if (file->Truncate(length)) { | 309 if (file->Truncate(length)) { |
| 302 Dart_SetReturnValue(args, Dart_True()); | 310 Dart_SetReturnValue(args, Dart_True()); |
| 311 } else { |
| 312 Dart_Handle err = DartUtils::NewDartOSError(); |
| 313 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 314 Dart_SetReturnValue(args, err); |
| 315 } |
| 303 } else { | 316 } else { |
| 304 Dart_Handle err = DartUtils::NewDartOSError(); | 317 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 318 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| 305 if (Dart_IsError(err)) Dart_PropagateError(err); | 319 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 306 Dart_SetReturnValue(args, err); | 320 Dart_SetReturnValue(args, err); |
| 307 } | 321 } |
| 308 Dart_ExitScope(); | 322 Dart_ExitScope(); |
| 309 } | 323 } |
| 310 | 324 |
| 311 | 325 |
| 312 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { | 326 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { |
| 313 Dart_EnterScope(); | 327 Dart_EnterScope(); |
| 314 intptr_t value = | 328 intptr_t value = |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 Dart_EnterScope(); | 940 Dart_EnterScope(); |
| 927 Dart_SetReturnValue(args, Dart_Null()); | 941 Dart_SetReturnValue(args, Dart_Null()); |
| 928 Dart_Port service_port = File::GetServicePort(); | 942 Dart_Port service_port = File::GetServicePort(); |
| 929 if (service_port != kIllegalPort) { | 943 if (service_port != kIllegalPort) { |
| 930 // Return a send port for the service port. | 944 // Return a send port for the service port. |
| 931 Dart_Handle send_port = Dart_NewSendPort(service_port); | 945 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 932 Dart_SetReturnValue(args, send_port); | 946 Dart_SetReturnValue(args, send_port); |
| 933 } | 947 } |
| 934 Dart_ExitScope(); | 948 Dart_ExitScope(); |
| 935 } | 949 } |
| OLD | NEW |