| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // reading. This is to prevent the opening of directories as | 72 // reading. This is to prevent the opening of directories as |
| 73 // files. Directories can be opened for reading using the posix | 73 // files. Directories can be opened for reading using the posix |
| 74 // 'open' call. | 74 // 'open' call. |
| 75 File* file = NULL; | 75 File* file = NULL; |
| 76 file = File::Open(filename, file_mode); | 76 file = File::Open(filename, file_mode); |
| 77 if (file != NULL) { | 77 if (file != NULL) { |
| 78 Dart_SetReturnValue(args, | 78 Dart_SetReturnValue(args, |
| 79 Dart_NewInteger(reinterpret_cast<intptr_t>(file))); | 79 Dart_NewInteger(reinterpret_cast<intptr_t>(file))); |
| 80 } else { | 80 } else { |
| 81 Dart_Handle err = DartUtils::NewDartOSError(); | 81 Dart_Handle err = DartUtils::NewDartOSError(); |
| 82 if (Dart_IsError(err)) Dart_PropagateError(err); | 82 if (Dart_IsError(err)) { |
| 83 Dart_PropagateError(err); |
| 84 } |
| 83 Dart_SetReturnValue(args, err); | 85 Dart_SetReturnValue(args, err); |
| 84 } | 86 } |
| 85 Dart_ExitScope(); | 87 Dart_ExitScope(); |
| 86 } | 88 } |
| 87 | 89 |
| 88 | 90 |
| 89 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { | 91 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { |
| 90 Dart_EnterScope(); | 92 Dart_EnterScope(); |
| 91 const char* filename = | 93 const char* filename = |
| 92 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 94 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 93 bool exists = File::Exists(filename); | 95 bool exists = File::Exists(filename); |
| 94 Dart_SetReturnValue(args, Dart_NewBoolean(exists)); | 96 Dart_SetReturnValue(args, Dart_NewBoolean(exists)); |
| 95 Dart_ExitScope(); | 97 Dart_ExitScope(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 | 100 |
| 99 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { | 101 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { |
| 100 Dart_EnterScope(); | 102 Dart_EnterScope(); |
| 103 intptr_t return_value = -1; |
| 101 intptr_t value = | 104 intptr_t value = |
| 102 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 105 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 103 File* file = reinterpret_cast<File*>(value); | 106 File* file = reinterpret_cast<File*>(value); |
| 104 ASSERT(file != NULL); | 107 if (file != NULL) { |
| 105 delete file; | 108 delete file; |
| 106 Dart_SetReturnValue(args, Dart_NewInteger(0)); | 109 return_value = 0; |
| 110 } |
| 111 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 107 Dart_ExitScope(); | 112 Dart_ExitScope(); |
| 108 } | 113 } |
| 109 | 114 |
| 110 | 115 |
| 111 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { | 116 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { |
| 112 Dart_EnterScope(); | 117 Dart_EnterScope(); |
| 113 intptr_t value = | 118 intptr_t value = |
| 114 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 119 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 115 File* file = reinterpret_cast<File*>(value); | 120 File* file = reinterpret_cast<File*>(value); |
| 116 ASSERT(file != NULL); | 121 if (file != NULL) { |
| 117 uint8_t buffer; | 122 uint8_t buffer; |
| 118 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 123 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| 119 if (bytes_read == 1) { | 124 if (bytes_read == 1) { |
| 120 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); | 125 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); |
| 121 } else if (bytes_read == 0) { | 126 } else if (bytes_read == 0) { |
| 122 Dart_SetReturnValue(args, Dart_NewInteger(-1)); | 127 Dart_SetReturnValue(args, Dart_NewInteger(-1)); |
| 123 } else { | 128 } else { |
| 124 Dart_Handle err = DartUtils::NewDartOSError(); | 129 Dart_Handle err = DartUtils::NewDartOSError(); |
| 125 if (Dart_IsError(err)) Dart_PropagateError(err); | 130 if (Dart_IsError(err)) { |
| 126 Dart_SetReturnValue(args, err); | 131 Dart_PropagateError(err); |
| 132 } |
| 133 Dart_SetReturnValue(args, err); |
| 134 } |
| 127 } | 135 } |
| 128 Dart_ExitScope(); | 136 Dart_ExitScope(); |
| 129 } | 137 } |
| 130 | 138 |
| 131 | 139 |
| 132 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { | 140 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { |
| 133 Dart_EnterScope(); | 141 Dart_EnterScope(); |
| 134 intptr_t file_ptr = | 142 intptr_t value = |
| 135 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 143 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 136 File* file = reinterpret_cast<File*>(file_ptr); | 144 File* file = reinterpret_cast<File*>(value); |
| 137 ASSERT(file != NULL); | 145 if (file != NULL) { |
| 138 int64_t value = 0; | 146 int64_t value = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 139 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &value)) { | |
| 140 uint8_t buffer = static_cast<uint8_t>(value & 0xff); | 147 uint8_t buffer = static_cast<uint8_t>(value & 0xff); |
| 141 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 148 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| 142 if (bytes_written >= 0) { | 149 if (bytes_written >= 0) { |
| 143 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 150 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 144 } else { | 151 } else { |
| 145 Dart_Handle err = DartUtils::NewDartOSError(); | 152 Dart_Handle err = DartUtils::NewDartOSError(); |
| 146 if (Dart_IsError(err)) Dart_PropagateError(err); | 153 if (Dart_IsError(err)) { |
| 154 Dart_PropagateError(err); |
| 155 } |
| 147 Dart_SetReturnValue(args, err); | 156 Dart_SetReturnValue(args, err); |
| 148 } | 157 } |
| 149 } else { | |
| 150 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | |
| 151 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | |
| 152 if (Dart_IsError(err)) Dart_PropagateError(err); | |
| 153 Dart_SetReturnValue(args, err); | |
| 154 } | 158 } |
| 155 Dart_ExitScope(); | 159 Dart_ExitScope(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 | 162 |
| 159 void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) { | 163 void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) { |
| 160 Dart_EnterScope(); | 164 Dart_EnterScope(); |
| 161 intptr_t value = | 165 intptr_t value = |
| 162 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 166 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 163 File* file = reinterpret_cast<File*>(value); | 167 File* file = reinterpret_cast<File*>(value); |
| 164 ASSERT(file != NULL); | 168 if (file != NULL) { |
| 165 const char* str = | 169 const char* str = |
| 166 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 170 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 167 int bytes_written = file->Write(reinterpret_cast<const void*>(str), | 171 int bytes_written = file->Write(reinterpret_cast<const void*>(str), |
| 168 strlen(str)); | 172 strlen(str)); |
| 169 if (bytes_written >= 0) { | 173 if (bytes_written >= 0) { |
| 170 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 174 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 171 } else { | 175 } else { |
| 172 Dart_Handle err = DartUtils::NewDartOSError(); | 176 Dart_Handle err = DartUtils::NewDartOSError(); |
| 173 if (Dart_IsError(err)) Dart_PropagateError(err); | 177 if (Dart_IsError(err)) { |
| 174 Dart_SetReturnValue(args, err); | 178 Dart_PropagateError(err); |
| 179 } |
| 180 Dart_SetReturnValue(args, err); |
| 181 } |
| 175 } | 182 } |
| 176 Dart_ExitScope(); | 183 Dart_ExitScope(); |
| 177 } | 184 } |
| 178 | 185 |
| 179 | 186 |
| 180 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { | 187 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { |
| 181 Dart_EnterScope(); | 188 Dart_EnterScope(); |
| 182 intptr_t value = | 189 intptr_t value = |
| 183 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 190 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 184 File* file = reinterpret_cast<File*>(value); | 191 File* file = reinterpret_cast<File*>(value); |
| 185 ASSERT(file != NULL); | 192 if (file != NULL) { |
| 186 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 193 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 187 ASSERT(Dart_IsList(buffer_obj)); | 194 ASSERT(Dart_IsList(buffer_obj)); |
| 188 int64_t offset = | 195 int64_t offset = |
| 189 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 196 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 190 int64_t length = | 197 int64_t length = |
| 191 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 198 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 192 intptr_t array_len = 0; | 199 intptr_t array_len = 0; |
| 193 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 200 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 194 if (Dart_IsError(result)) Dart_PropagateError(result); | |
| 195 ASSERT((offset + length) <= array_len); | |
| 196 uint8_t* buffer = new uint8_t[length]; | |
| 197 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | |
| 198 if (bytes_read >= 0) { | |
| 199 result = Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); | |
| 200 if (Dart_IsError(result)) { | 201 if (Dart_IsError(result)) { |
| 201 delete[] buffer; | |
| 202 Dart_PropagateError(result); | 202 Dart_PropagateError(result); |
| 203 } | 203 } |
| 204 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | 204 ASSERT((offset + length) <= array_len); |
| 205 } else { | 205 uint8_t* buffer = new uint8_t[length]; |
| 206 Dart_Handle err = DartUtils::NewDartOSError(); | 206 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| 207 if (Dart_IsError(err)) Dart_PropagateError(err); | 207 if (bytes_read >= 0) { |
| 208 Dart_SetReturnValue(args, err); | 208 result = |
| 209 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| 210 if (Dart_IsError(result)) { |
| 211 delete[] buffer; |
| 212 Dart_PropagateError(result); |
| 213 } |
| 214 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| 215 } else { |
| 216 Dart_Handle err = DartUtils::NewDartOSError(); |
| 217 if (Dart_IsError(err)) { |
| 218 Dart_PropagateError(err); |
| 219 } |
| 220 Dart_SetReturnValue(args, err); |
| 221 } |
| 222 delete[] buffer; |
| 209 } | 223 } |
| 210 delete[] buffer; | |
| 211 Dart_ExitScope(); | 224 Dart_ExitScope(); |
| 212 } | 225 } |
| 213 | 226 |
| 214 | 227 |
| 215 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { | 228 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| 216 Dart_EnterScope(); | 229 Dart_EnterScope(); |
| 217 intptr_t value = | 230 intptr_t value = |
| 218 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 231 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 219 File* file = reinterpret_cast<File*>(value); | 232 File* file = reinterpret_cast<File*>(value); |
| 220 ASSERT(file != NULL); | 233 if (file != NULL) { |
| 221 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 234 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 222 ASSERT(Dart_IsList(buffer_obj)); | 235 ASSERT(Dart_IsList(buffer_obj)); |
| 223 int64_t offset = | 236 int64_t offset = |
| 224 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 237 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 225 int64_t length = | 238 int64_t length = |
| 226 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 239 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 227 intptr_t buffer_len = 0; | 240 intptr_t buffer_len = 0; |
| 228 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 241 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 229 if (Dart_IsError(result)) Dart_PropagateError(result); | 242 if (Dart_IsError(result)) { |
| 230 ASSERT((offset + length) <= buffer_len); | 243 Dart_PropagateError(result); |
| 231 uint8_t* buffer = new uint8_t[length]; | 244 } |
| 232 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); | 245 ASSERT((offset + length) <= buffer_len); |
| 233 if (Dart_IsError(result)) { | 246 uint8_t* buffer = new uint8_t[length]; |
| 247 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| 248 if (Dart_IsError(result)) { |
| 249 delete[] buffer; |
| 250 Dart_PropagateError(result); |
| 251 } |
| 252 int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); |
| 253 if (bytes_written >= 0) { |
| 254 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 255 } else { |
| 256 Dart_Handle err = DartUtils::NewDartOSError(); |
| 257 if (Dart_IsError(err)) { |
| 258 Dart_PropagateError(err); |
| 259 } |
| 260 Dart_SetReturnValue(args, err); |
| 261 } |
| 234 delete[] buffer; | 262 delete[] buffer; |
| 235 Dart_PropagateError(result); | |
| 236 } | 263 } |
| 237 int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); | |
| 238 if (bytes_written >= 0) { | |
| 239 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | |
| 240 } else { | |
| 241 Dart_Handle err = DartUtils::NewDartOSError(); | |
| 242 if (Dart_IsError(err)) Dart_PropagateError(err); | |
| 243 Dart_SetReturnValue(args, err); | |
| 244 } | |
| 245 delete[] buffer; | |
| 246 Dart_ExitScope(); | 264 Dart_ExitScope(); |
| 247 } | 265 } |
| 248 | 266 |
| 249 | 267 |
| 250 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { | 268 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { |
| 251 Dart_EnterScope(); | 269 Dart_EnterScope(); |
| 252 intptr_t value = | 270 intptr_t value = |
| 253 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 271 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 254 File* file = reinterpret_cast<File*>(value); | 272 File* file = reinterpret_cast<File*>(value); |
| 255 ASSERT(file != NULL); | 273 if (file != NULL) { |
| 256 intptr_t return_value = file->Position(); | 274 intptr_t return_value = file->Position(); |
| 257 if (return_value >= 0) { | 275 if (return_value >= 0) { |
| 258 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 276 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 259 } else { | 277 } else { |
| 260 Dart_Handle err = DartUtils::NewDartOSError(); | 278 Dart_Handle err = DartUtils::NewDartOSError(); |
| 261 if (Dart_IsError(err)) Dart_PropagateError(err); | 279 if (Dart_IsError(err)) { |
| 262 Dart_SetReturnValue(args, err); | 280 Dart_PropagateError(err); |
| 281 } |
| 282 Dart_SetReturnValue(args, err); |
| 283 } |
| 263 } | 284 } |
| 264 Dart_ExitScope(); | 285 Dart_ExitScope(); |
| 265 } | 286 } |
| 266 | 287 |
| 267 | 288 |
| 268 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { | 289 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { |
| 269 Dart_EnterScope(); | 290 Dart_EnterScope(); |
| 270 intptr_t value = | 291 intptr_t value = |
| 271 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 292 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 272 File* file = reinterpret_cast<File*>(value); | 293 File* file = reinterpret_cast<File*>(value); |
| 273 ASSERT(file != NULL); | 294 if (file != NULL) { |
| 274 int64_t position = 0; | 295 int64_t position = |
| 275 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &position)) { | 296 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 276 if (file->SetPosition(position)) { | 297 if (file->SetPosition(position)) { |
| 277 Dart_SetReturnValue(args, Dart_True()); | 298 Dart_SetReturnValue(args, Dart_True()); |
| 278 } else { | 299 } else { |
| 279 Dart_Handle err = DartUtils::NewDartOSError(); | 300 Dart_Handle err = DartUtils::NewDartOSError(); |
| 280 if (Dart_IsError(err)) Dart_PropagateError(err); | 301 if (Dart_IsError(err)) { |
| 302 Dart_PropagateError(err); |
| 303 } |
| 281 Dart_SetReturnValue(args, err); | 304 Dart_SetReturnValue(args, err); |
| 282 } | 305 } |
| 283 } else { | |
| 284 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | |
| 285 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | |
| 286 if (Dart_IsError(err)) Dart_PropagateError(err); | |
| 287 Dart_SetReturnValue(args, err); | |
| 288 } | 306 } |
| 289 Dart_ExitScope(); | 307 Dart_ExitScope(); |
| 290 } | 308 } |
| 291 | 309 |
| 292 | 310 |
| 293 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { | 311 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { |
| 294 Dart_EnterScope(); | 312 Dart_EnterScope(); |
| 295 intptr_t value = | 313 intptr_t value = |
| 296 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 314 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 297 File* file = reinterpret_cast<File*>(value); | 315 File* file = reinterpret_cast<File*>(value); |
| 298 ASSERT(file != NULL); | 316 if (file != NULL) { |
| 299 int64_t length = | 317 int64_t length = |
| 300 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 318 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 301 if (file->Truncate(length)) { | 319 if (file->Truncate(length)) { |
| 302 Dart_SetReturnValue(args, Dart_True()); | 320 Dart_SetReturnValue(args, Dart_True()); |
| 303 } else { | 321 } else { |
| 304 Dart_Handle err = DartUtils::NewDartOSError(); | 322 Dart_Handle err = DartUtils::NewDartOSError(); |
| 305 if (Dart_IsError(err)) Dart_PropagateError(err); | 323 if (Dart_IsError(err)) { |
| 306 Dart_SetReturnValue(args, err); | 324 Dart_PropagateError(err); |
| 325 } |
| 326 Dart_SetReturnValue(args, err); |
| 327 } |
| 307 } | 328 } |
| 308 Dart_ExitScope(); | 329 Dart_ExitScope(); |
| 309 } | 330 } |
| 310 | 331 |
| 311 | 332 |
| 312 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { | 333 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { |
| 313 Dart_EnterScope(); | 334 Dart_EnterScope(); |
| 314 intptr_t value = | 335 intptr_t value = |
| 315 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 336 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 316 File* file = reinterpret_cast<File*>(value); | 337 File* file = reinterpret_cast<File*>(value); |
| 317 ASSERT(file != NULL); | 338 if (file != NULL) { |
| 318 intptr_t return_value = file->Length(); | 339 intptr_t return_value = file->Length(); |
| 319 if (return_value >= 0) { | 340 if (return_value >= 0) { |
| 320 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 341 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 321 } else { | 342 } else { |
| 322 Dart_Handle err = DartUtils::NewDartOSError(); | 343 Dart_Handle err = DartUtils::NewDartOSError(); |
| 323 if (Dart_IsError(err)) Dart_PropagateError(err); | 344 if (Dart_IsError(err)) { |
| 324 Dart_SetReturnValue(args, err); | 345 Dart_PropagateError(err); |
| 346 } |
| 347 Dart_SetReturnValue(args, err); |
| 348 } |
| 325 } | 349 } |
| 326 Dart_ExitScope(); | 350 Dart_ExitScope(); |
| 327 } | 351 } |
| 328 | 352 |
| 329 | 353 |
| 330 void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) { | 354 void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) { |
| 331 Dart_EnterScope(); | 355 Dart_EnterScope(); |
| 332 const char* name = | 356 const char* name = |
| 333 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 357 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 334 intptr_t return_value = File::LengthFromName(name); | 358 intptr_t return_value = File::LengthFromName(name); |
| 335 if (return_value >= 0) { | 359 if (return_value >= 0) { |
| 336 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 360 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 337 } else { | 361 } else { |
| 338 Dart_Handle err = DartUtils::NewDartOSError(); | 362 Dart_Handle err = DartUtils::NewDartOSError(); |
| 339 if (Dart_IsError(err)) Dart_PropagateError(err); | 363 if (Dart_IsError(err)) { |
| 364 Dart_PropagateError(err); |
| 365 } |
| 340 Dart_SetReturnValue(args, err); | 366 Dart_SetReturnValue(args, err); |
| 341 } | 367 } |
| 342 Dart_ExitScope(); | 368 Dart_ExitScope(); |
| 343 } | 369 } |
| 344 | 370 |
| 345 | 371 |
| 346 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { | 372 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { |
| 347 Dart_EnterScope(); | 373 Dart_EnterScope(); |
| 348 intptr_t value = | 374 intptr_t value = |
| 349 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 375 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 350 File* file = reinterpret_cast<File*>(value); | 376 File* file = reinterpret_cast<File*>(value); |
| 351 ASSERT(file != NULL); | 377 if (file != NULL) { |
| 352 if (file->Flush()) { | 378 if (file->Flush()) { |
| 353 Dart_SetReturnValue(args, Dart_True()); | 379 Dart_SetReturnValue(args, Dart_True()); |
| 354 } else { | 380 } else { |
| 355 Dart_Handle err = DartUtils::NewDartOSError(); | 381 Dart_Handle err = DartUtils::NewDartOSError(); |
| 356 if (Dart_IsError(err)) Dart_PropagateError(err); | 382 if (Dart_IsError(err)) { |
| 357 Dart_SetReturnValue(args, err); | 383 Dart_PropagateError(err); |
| 384 } |
| 385 Dart_SetReturnValue(args, err); |
| 386 } |
| 358 } | 387 } |
| 359 Dart_ExitScope(); | 388 Dart_ExitScope(); |
| 360 } | 389 } |
| 361 | 390 |
| 362 | 391 |
| 363 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { | 392 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
| 364 Dart_EnterScope(); | 393 Dart_EnterScope(); |
| 365 const char* str = | 394 const char* str = |
| 366 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 395 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 367 bool result = File::Create(str); | 396 bool result = File::Create(str); |
| 368 if (result) { | 397 if (result) { |
| 369 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 398 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 370 } else { | 399 } else { |
| 371 Dart_Handle err = DartUtils::NewDartOSError(); | 400 Dart_Handle err = DartUtils::NewDartOSError(); |
| 372 if (Dart_IsError(err)) Dart_PropagateError(err); | 401 if (Dart_IsError(err)) { |
| 402 Dart_PropagateError(err); |
| 403 } |
| 373 Dart_SetReturnValue(args, err); | 404 Dart_SetReturnValue(args, err); |
| 374 } | 405 } |
| 375 Dart_ExitScope(); | 406 Dart_ExitScope(); |
| 376 } | 407 } |
| 377 | 408 |
| 378 | 409 |
| 379 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { | 410 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { |
| 380 Dart_EnterScope(); | 411 Dart_EnterScope(); |
| 381 const char* str = | 412 const char* str = |
| 382 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 413 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 383 bool result = File::Delete(str); | 414 bool result = File::Delete(str); |
| 384 if (result) { | 415 if (result) { |
| 385 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 416 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 386 } else { | 417 } else { |
| 387 Dart_Handle err = DartUtils::NewDartOSError(); | 418 Dart_Handle err = DartUtils::NewDartOSError(); |
| 388 if (Dart_IsError(err)) Dart_PropagateError(err); | 419 if (Dart_IsError(err)) { |
| 420 Dart_PropagateError(err); |
| 421 } |
| 389 Dart_SetReturnValue(args, err); | 422 Dart_SetReturnValue(args, err); |
| 390 } | 423 } |
| 391 Dart_ExitScope(); | 424 Dart_ExitScope(); |
| 392 } | 425 } |
| 393 | 426 |
| 394 | 427 |
| 395 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { | 428 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { |
| 396 Dart_EnterScope(); | 429 Dart_EnterScope(); |
| 397 const char* str = | 430 const char* str = |
| 398 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 431 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 399 char* str_copy = strdup(str); | 432 char* str_copy = strdup(str); |
| 400 char* path = File::GetContainingDirectory(str_copy); | 433 char* path = File::GetContainingDirectory(str_copy); |
| 401 free(str_copy); | 434 free(str_copy); |
| 402 if (path != NULL) { | 435 if (path != NULL) { |
| 403 Dart_SetReturnValue(args, Dart_NewString(path)); | 436 Dart_SetReturnValue(args, Dart_NewString(path)); |
| 404 free(path); | 437 free(path); |
| 405 } else { | 438 } else { |
| 406 Dart_Handle err = DartUtils::NewDartOSError(); | 439 Dart_Handle err = DartUtils::NewDartOSError(); |
| 407 if (Dart_IsError(err)) Dart_PropagateError(err); | 440 if (Dart_IsError(err)) { |
| 441 Dart_PropagateError(err); |
| 442 } |
| 408 Dart_SetReturnValue(args, err); | 443 Dart_SetReturnValue(args, err); |
| 409 } | 444 } |
| 410 Dart_ExitScope(); | 445 Dart_ExitScope(); |
| 411 } | 446 } |
| 412 | 447 |
| 413 | 448 |
| 414 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { | 449 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { |
| 415 Dart_EnterScope(); | 450 Dart_EnterScope(); |
| 416 const char* str = | 451 const char* str = |
| 417 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 452 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 418 char* path = File::GetCanonicalPath(str); | 453 char* path = File::GetCanonicalPath(str); |
| 419 if (path != NULL) { | 454 if (path != NULL) { |
| 420 Dart_SetReturnValue(args, Dart_NewString(path)); | 455 Dart_SetReturnValue(args, Dart_NewString(path)); |
| 421 free(path); | 456 free(path); |
| 422 } else { | 457 } else { |
| 423 Dart_Handle err = DartUtils::NewDartOSError(); | 458 Dart_Handle err = DartUtils::NewDartOSError(); |
| 424 if (Dart_IsError(err)) Dart_PropagateError(err); | 459 if (Dart_IsError(err)) { |
| 460 Dart_PropagateError(err); |
| 461 } |
| 425 Dart_SetReturnValue(args, err); | 462 Dart_SetReturnValue(args, err); |
| 426 } | 463 } |
| 427 Dart_ExitScope(); | 464 Dart_ExitScope(); |
| 428 } | 465 } |
| 429 | 466 |
| 430 | 467 |
| 431 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { | 468 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { |
| 432 Dart_EnterScope(); | 469 Dart_EnterScope(); |
| 433 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 470 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 434 File* file = File::OpenStdio(fd); | 471 File* file = File::OpenStdio(fd); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 593 } |
| 557 } | 594 } |
| 558 return CObject::Null(); | 595 return CObject::Null(); |
| 559 } | 596 } |
| 560 | 597 |
| 561 | 598 |
| 562 static CObject* FileCloseRequest(const CObjectArray& request) { | 599 static CObject* FileCloseRequest(const CObjectArray& request) { |
| 563 intptr_t return_value = -1; | 600 intptr_t return_value = -1; |
| 564 if (request.Length() == 2 && request[1]->IsIntptr()) { | 601 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 565 File* file = CObjectToFilePointer(request[1]); | 602 File* file = CObjectToFilePointer(request[1]); |
| 566 ASSERT(file != NULL); | 603 if (file != NULL) { |
| 567 delete file; | 604 delete file; |
| 568 return_value = 0; | 605 return_value = 0; |
| 606 } |
| 569 } | 607 } |
| 570 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 608 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 571 } | 609 } |
| 572 | 610 |
| 573 | 611 |
| 574 static CObject* FilePositionRequest(const CObjectArray& request) { | 612 static CObject* FilePositionRequest(const CObjectArray& request) { |
| 575 if (request.Length() == 2 && request[1]->IsIntptr()) { | 613 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 576 File* file = CObjectToFilePointer(request[1]); | 614 File* file = CObjectToFilePointer(request[1]); |
| 577 ASSERT(file != NULL); | 615 if (file != NULL && !file->IsClosed()) { |
| 578 if (!file->IsClosed()) { | |
| 579 intptr_t return_value = file->Position(); | 616 intptr_t return_value = file->Position(); |
| 580 if (return_value >= 0) { | 617 if (return_value >= 0) { |
| 581 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 618 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 582 } else { | 619 } else { |
| 583 return CObject::NewOSError(); | 620 return CObject::NewOSError(); |
| 584 } | 621 } |
| 585 } else { | 622 } else { |
| 586 return CObject::FileClosedError(); | 623 return CObject::FileClosedError(); |
| 587 } | 624 } |
| 588 } | 625 } |
| 589 return CObject::IllegalArgumentError(); | 626 return CObject::IllegalArgumentError(); |
| 590 } | 627 } |
| 591 | 628 |
| 592 | 629 |
| 593 static CObject* FileSetPositionRequest(const CObjectArray& request) { | 630 static CObject* FileSetPositionRequest(const CObjectArray& request) { |
| 594 if (request.Length() == 3 && | 631 if (request.Length() == 3 && |
| 595 request[1]->IsIntptr() && | 632 request[1]->IsIntptr() && |
| 596 request[2]->IsInt32OrInt64()) { | 633 request[2]->IsInt32OrInt64()) { |
| 597 File* file = CObjectToFilePointer(request[1]); | 634 File* file = CObjectToFilePointer(request[1]); |
| 598 ASSERT(file != NULL); | 635 if (file != NULL && !file->IsClosed()) { |
| 599 if (!file->IsClosed()) { | |
| 600 int64_t position = CObjectInt32OrInt64ToInt64(request[2]); | 636 int64_t position = CObjectInt32OrInt64ToInt64(request[2]); |
| 601 if (file->SetPosition(position)) { | 637 if (file->SetPosition(position)) { |
| 602 return CObject::True(); | 638 return CObject::True(); |
| 603 } else { | 639 } else { |
| 604 return CObject::NewOSError(); | 640 return CObject::NewOSError(); |
| 605 } | 641 } |
| 606 } else { | 642 } else { |
| 607 return CObject::FileClosedError(); | 643 return CObject::FileClosedError(); |
| 608 } | 644 } |
| 609 } | 645 } |
| 610 return CObject::IllegalArgumentError(); | 646 return CObject::IllegalArgumentError(); |
| 611 } | 647 } |
| 612 | 648 |
| 613 | 649 |
| 614 static CObject* FileTruncateRequest(const CObjectArray& request) { | 650 static CObject* FileTruncateRequest(const CObjectArray& request) { |
| 615 if (request.Length() == 3 && | 651 if (request.Length() == 3 && |
| 616 request[1]->IsIntptr() && | 652 request[1]->IsIntptr() && |
| 617 request[2]->IsInt32OrInt64()) { | 653 request[2]->IsInt32OrInt64()) { |
| 618 File* file = CObjectToFilePointer(request[1]); | 654 File* file = CObjectToFilePointer(request[1]); |
| 619 ASSERT(file != NULL); | 655 if (file != NULL && !file->IsClosed()) { |
| 620 if (!file->IsClosed()) { | |
| 621 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 656 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 622 if (file->Truncate(length)) { | 657 if (file->Truncate(length)) { |
| 623 return CObject::True(); | 658 return CObject::True(); |
| 624 } else { | 659 } else { |
| 625 return CObject::NewOSError(); | 660 return CObject::NewOSError(); |
| 626 } | 661 } |
| 627 } else { | 662 } else { |
| 628 return CObject::FileClosedError(); | 663 return CObject::FileClosedError(); |
| 629 } | 664 } |
| 630 } | 665 } |
| 631 return CObject::IllegalArgumentError(); | 666 return CObject::IllegalArgumentError(); |
| 632 } | 667 } |
| 633 | 668 |
| 634 | 669 |
| 635 static CObject* FileLengthRequest(const CObjectArray& request) { | 670 static CObject* FileLengthRequest(const CObjectArray& request) { |
| 636 if (request.Length() == 2 && request[1]->IsIntptr()) { | 671 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 637 File* file = CObjectToFilePointer(request[1]); | 672 File* file = CObjectToFilePointer(request[1]); |
| 638 ASSERT(file != NULL); | 673 if (file != NULL && !file->IsClosed()) { |
| 639 if (!file->IsClosed()) { | |
| 640 intptr_t return_value = file->Length(); | 674 intptr_t return_value = file->Length(); |
| 641 if (return_value >= 0) { | 675 if (return_value >= 0) { |
| 642 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 676 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 643 } else { | 677 } else { |
| 644 return CObject::NewOSError(); | 678 return CObject::NewOSError(); |
| 645 } | 679 } |
| 646 } else { | 680 } else { |
| 647 return CObject::FileClosedError(); | 681 return CObject::FileClosedError(); |
| 648 } | 682 } |
| 649 } | 683 } |
| 650 return CObject::IllegalArgumentError(); | 684 return CObject::IllegalArgumentError(); |
| 651 } | 685 } |
| 652 | 686 |
| 653 | 687 |
| 654 static CObject* FileLengthFromNameRequest(const CObjectArray& request) { | 688 static CObject* FileLengthFromNameRequest(const CObjectArray& request) { |
| 655 if (request.Length() == 2 && request[1]->IsString()) { | 689 if (request.Length() == 2 && request[1]->IsString()) { |
| 656 CObjectString filename(request[1]); | 690 CObjectString filename(request[1]); |
| 657 intptr_t return_value = File::LengthFromName(filename.CString()); | 691 intptr_t return_value = File::LengthFromName(filename.CString()); |
| 658 if (return_value >= 0) { | 692 if (return_value >= 0) { |
| 659 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 693 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 660 } else { | 694 } else { |
| 661 return CObject::NewOSError(); | 695 return CObject::NewOSError(); |
| 662 } | 696 } |
| 663 } | 697 } |
| 664 return CObject::IllegalArgumentError(); | 698 return CObject::IllegalArgumentError(); |
| 665 } | 699 } |
| 666 | 700 |
| 667 | 701 |
| 668 static CObject* FileFlushRequest(const CObjectArray& request) { | 702 static CObject* FileFlushRequest(const CObjectArray& request) { |
| 703 intptr_t return_value = -1; |
| 669 if (request.Length() == 2 && request[1]->IsIntptr()) { | 704 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 670 File* file = CObjectToFilePointer(request[1]); | 705 File* file = CObjectToFilePointer(request[1]); |
| 671 ASSERT(file != NULL); | 706 if (file != NULL && !file->IsClosed()) { |
| 672 if (!file->IsClosed()) { | |
| 673 if (file->Flush()) { | 707 if (file->Flush()) { |
| 674 return CObject::True(); | 708 return CObject::True(); |
| 675 } else { | 709 } else { |
| 676 return CObject::NewOSError(); | 710 return CObject::NewOSError(); |
| 677 } | 711 } |
| 678 } else { | 712 } else { |
| 679 return CObject::FileClosedError(); | 713 return CObject::FileClosedError(); |
| 680 } | 714 } |
| 681 } | 715 } |
| 682 return CObject::IllegalArgumentError(); | 716 return CObject::IllegalArgumentError(); |
| 717 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 683 } | 718 } |
| 684 | 719 |
| 685 | 720 |
| 686 static CObject* FileReadByteRequest(const CObjectArray& request) { | 721 static CObject* FileReadByteRequest(const CObjectArray& request) { |
| 687 if (request.Length() == 2 && request[1]->IsIntptr()) { | 722 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 688 File* file = CObjectToFilePointer(request[1]); | 723 File* file = CObjectToFilePointer(request[1]); |
| 689 ASSERT(file != NULL); | 724 if (file != NULL && !file->IsClosed()) { |
| 690 if (!file->IsClosed()) { | |
| 691 uint8_t buffer; | 725 uint8_t buffer; |
| 692 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 726 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| 693 if (bytes_read > 0) { | 727 if (bytes_read > 0) { |
| 694 return new CObjectIntptr(CObject::NewIntptr(buffer)); | 728 return new CObjectIntptr(CObject::NewIntptr(buffer)); |
| 695 } else if (bytes_read == 0) { | 729 } else if (bytes_read == 0) { |
| 696 return new CObjectIntptr(CObject::NewIntptr(-1)); | 730 return new CObjectIntptr(CObject::NewIntptr(-1)); |
| 697 } else { | 731 } else { |
| 698 return CObject::NewOSError(); | 732 return CObject::NewOSError(); |
| 699 } | 733 } |
| 700 } else { | 734 } else { |
| 701 return CObject::FileClosedError(); | 735 return CObject::FileClosedError(); |
| 702 } | 736 } |
| 703 } | 737 } |
| 704 return CObject::IllegalArgumentError(); | 738 return CObject::IllegalArgumentError(); |
| 705 } | 739 } |
| 706 | 740 |
| 707 | 741 |
| 708 static CObject* FileWriteByteRequest(const CObjectArray& request) { | 742 static CObject* FileWriteByteRequest(const CObjectArray& request) { |
| 709 if (request.Length() == 3 && | 743 if (request.Length() == 3 && |
| 710 request[1]->IsIntptr() && | 744 request[1]->IsIntptr() && |
| 711 request[2]->IsInt32OrInt64()) { | 745 request[2]->IsInt32OrInt64()) { |
| 712 File* file = CObjectToFilePointer(request[1]); | 746 File* file = CObjectToFilePointer(request[1]); |
| 713 ASSERT(file != NULL); | 747 if (file != NULL && !file->IsClosed()) { |
| 714 if (!file->IsClosed()) { | |
| 715 int64_t byte = CObjectInt32OrInt64ToInt64(request[2]); | 748 int64_t byte = CObjectInt32OrInt64ToInt64(request[2]); |
| 716 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); | 749 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); |
| 717 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 750 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| 718 if (bytes_written > 0) { | 751 if (bytes_written > 0) { |
| 719 return new CObjectIntptr(CObject::NewIntptr(bytes_written)); | 752 return new CObjectIntptr(CObject::NewIntptr(bytes_written)); |
| 720 } else { | 753 } else { |
| 721 return CObject::NewOSError(); | 754 return CObject::NewOSError(); |
| 722 } | 755 } |
| 723 } else { | 756 } else { |
| 724 return CObject::FileClosedError(); | 757 return CObject::FileClosedError(); |
| 725 } | 758 } |
| 726 } | 759 } |
| 727 return CObject::IllegalArgumentError(); | 760 return CObject::IllegalArgumentError(); |
| 728 } | 761 } |
| 729 | 762 |
| 730 | 763 |
| 731 static CObject* FileReadListRequest(const CObjectArray& request) { | 764 static CObject* FileReadListRequest(const CObjectArray& request) { |
| 732 if (request.Length() == 3 && | 765 if (request.Length() == 3 && |
| 733 request[1]->IsIntptr() && | 766 request[1]->IsIntptr() && |
| 734 request[2]->IsInt32OrInt64()) { | 767 request[2]->IsInt32OrInt64()) { |
| 735 File* file = CObjectToFilePointer(request[1]); | 768 File* file = CObjectToFilePointer(request[1]); |
| 736 ASSERT(file != NULL); | 769 if (file != NULL && !file->IsClosed()) { |
| 737 if (!file->IsClosed()) { | |
| 738 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 770 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 739 CObjectUint8Array* byte_array = | 771 CObjectUint8Array* byte_array = |
| 740 new CObjectUint8Array(CObject::NewUint8Array(length)); | 772 new CObjectUint8Array(CObject::NewUint8Array(length)); |
| 741 void* buffer = reinterpret_cast<void*>(byte_array->Buffer()); | 773 void* buffer = reinterpret_cast<void*>(byte_array->Buffer()); |
| 742 int bytes_read = file->Read(buffer, byte_array->Length()); | 774 int bytes_read = file->Read(buffer, byte_array->Length()); |
| 743 if (bytes_read >= 0) { | 775 if (bytes_read >= 0) { |
| 744 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 776 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 745 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 777 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
| 746 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); | 778 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); |
| 747 result->SetAt(2, byte_array); | 779 result->SetAt(2, byte_array); |
| 748 return result; | 780 return result; |
| 749 } else { | 781 } else { |
| 750 return CObject::NewOSError(); | 782 return CObject::NewOSError(); |
| 751 } | 783 } |
| 752 } else { | 784 } else { |
| 753 return CObject::FileClosedError(); | 785 return CObject::FileClosedError(); |
| 754 } | 786 } |
| 755 } | 787 } |
| 756 return CObject::IllegalArgumentError(); | 788 return CObject::IllegalArgumentError(); |
| 757 } | 789 } |
| 758 | 790 |
| 759 | 791 |
| 760 static CObject* FileWriteListRequest(const CObjectArray& request) { | 792 static CObject* FileWriteListRequest(const CObjectArray& request) { |
| 761 if (request.Length() == 5 && | 793 if (request.Length() == 5 && |
| 762 request[1]->IsIntptr() && | 794 request[1]->IsIntptr() && |
| 763 (request[2]->IsUint8Array() || request[2]->IsArray()) && | 795 (request[2]->IsUint8Array() || request[2]->IsArray()) && |
| 764 request[3]->IsInt32OrInt64() && | 796 request[3]->IsInt32OrInt64() && |
| 765 request[4]->IsInt32OrInt64()) { | 797 request[4]->IsInt32OrInt64()) { |
| 766 File* file = CObjectToFilePointer(request[1]); | 798 File* file = CObjectToFilePointer(request[1]); |
| 767 ASSERT(file != NULL); | 799 if (file != NULL && !file->IsClosed()) { |
| 768 if (!file->IsClosed()) { | |
| 769 int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); | 800 int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); |
| 770 int64_t length = CObjectInt32OrInt64ToInt64(request[4]); | 801 int64_t length = CObjectInt32OrInt64ToInt64(request[4]); |
| 771 uint8_t* buffer_start; | 802 uint8_t* buffer_start; |
| 772 if (request[2]->IsUint8Array()) { | 803 if (request[2]->IsUint8Array()) { |
| 773 CObjectUint8Array byte_array(request[2]); | 804 CObjectUint8Array byte_array(request[2]); |
| 774 buffer_start = byte_array.Buffer() + offset; | 805 buffer_start = byte_array.Buffer() + offset; |
| 775 } else { | 806 } else { |
| 776 CObjectArray array(request[2]); | 807 CObjectArray array(request[2]); |
| 777 buffer_start = new uint8_t[length]; | 808 buffer_start = new uint8_t[length]; |
| 778 for (int i = 0; i < length; i++) { | 809 for (int i = 0; i < length; i++) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 803 } | 834 } |
| 804 return CObject::IllegalArgumentError(); | 835 return CObject::IllegalArgumentError(); |
| 805 } | 836 } |
| 806 | 837 |
| 807 | 838 |
| 808 static CObject* FileWriteStringRequest(const CObjectArray& request) { | 839 static CObject* FileWriteStringRequest(const CObjectArray& request) { |
| 809 if (request.Length() == 3 && | 840 if (request.Length() == 3 && |
| 810 request[1]->IsIntptr() && | 841 request[1]->IsIntptr() && |
| 811 request[2]->IsString()) { | 842 request[2]->IsString()) { |
| 812 File* file = CObjectToFilePointer(request[1]); | 843 File* file = CObjectToFilePointer(request[1]); |
| 813 ASSERT(file != NULL); | 844 if (file != NULL && !file->IsClosed()) { |
| 814 if (!file->IsClosed()) { | |
| 815 CObjectString str(request[2]); | 845 CObjectString str(request[2]); |
| 816 const void* buffer = reinterpret_cast<const void*>(str.CString()); | 846 const void* buffer = reinterpret_cast<const void*>(str.CString()); |
| 817 int64_t bytes_written = file->Write(buffer, str.Length()); | 847 int64_t bytes_written = file->Write(buffer, str.Length()); |
| 818 return new CObjectInt64(CObject::NewInt64(bytes_written)); | 848 return new CObjectInt64(CObject::NewInt64(bytes_written)); |
| 819 } else { | 849 } else { |
| 820 return CObject::FileClosedError(); | 850 return CObject::FileClosedError(); |
| 821 } | 851 } |
| 822 } | 852 } |
| 823 return CObject::IllegalArgumentError(); | 853 return CObject::IllegalArgumentError(); |
| 824 } | 854 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 Dart_EnterScope(); | 956 Dart_EnterScope(); |
| 927 Dart_SetReturnValue(args, Dart_Null()); | 957 Dart_SetReturnValue(args, Dart_Null()); |
| 928 Dart_Port service_port = File::GetServicePort(); | 958 Dart_Port service_port = File::GetServicePort(); |
| 929 if (service_port != kIllegalPort) { | 959 if (service_port != kIllegalPort) { |
| 930 // Return a send port for the service port. | 960 // Return a send port for the service port. |
| 931 Dart_Handle send_port = Dart_NewSendPort(service_port); | 961 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 932 Dart_SetReturnValue(args, send_port); | 962 Dart_SetReturnValue(args, send_port); |
| 933 } | 963 } |
| 934 Dart_ExitScope(); | 964 Dart_ExitScope(); |
| 935 } | 965 } |
| OLD | NEW |