OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/io_buffer.h" | 9 #include "bin/io_buffer.h" |
10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 if (file->Flush()) { | 384 if (file->Flush()) { |
385 Dart_SetReturnValue(args, Dart_True()); | 385 Dart_SetReturnValue(args, Dart_True()); |
386 } else { | 386 } else { |
387 Dart_Handle err = DartUtils::NewDartOSError(); | 387 Dart_Handle err = DartUtils::NewDartOSError(); |
388 if (Dart_IsError(err)) Dart_PropagateError(err); | 388 if (Dart_IsError(err)) Dart_PropagateError(err); |
389 Dart_SetReturnValue(args, err); | 389 Dart_SetReturnValue(args, err); |
390 } | 390 } |
391 } | 391 } |
392 | 392 |
393 | 393 |
394 void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) { | |
395 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); | |
396 ASSERT(file != NULL); | |
397 int64_t lock; | |
Lasse Reichstein Nielsen
2015/01/08 11:59:22
Is this the type on all platforms? There is no loc
Søren Gjesse
2015/01/09 13:06:19
The int64_t type is used to get the Dart int argum
| |
398 // Lock type arguments are checked in Dart code to be legal. | |
Lasse Reichstein Nielsen
2015/01/08 11:59:21
legal -> valid.
It's not a law.
Don't trust Dart
Søren Gjesse
2015/01/09 13:06:19
I an also checking here. It they are not integers
| |
399 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &lock)) { | |
400 int64_t start; | |
401 int64_t end; | |
402 if (lock >= File::kLockMin && | |
403 lock <= File::kLockMax && | |
404 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &start) && | |
405 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 3), &end)) { | |
406 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { | |
407 Dart_SetReturnValue(args, Dart_True()); | |
408 } else { | |
409 Dart_Handle err = DartUtils::NewDartOSError(); | |
410 if (Dart_IsError(err)) Dart_PropagateError(err); | |
411 Dart_SetReturnValue(args, err); | |
412 } | |
413 return; | |
414 } | |
415 } | |
416 | |
417 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | |
418 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | |
419 if (Dart_IsError(err)) Dart_PropagateError(err); | |
420 Dart_SetReturnValue(args, err); | |
421 } | |
422 | |
423 | |
394 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { | 424 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
395 const char* str = | 425 const char* str = |
396 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 426 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
397 bool result = File::Create(str); | 427 bool result = File::Create(str); |
398 if (result) { | 428 if (result) { |
399 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 429 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
400 } else { | 430 } else { |
401 Dart_Handle err = DartUtils::NewDartOSError(); | 431 Dart_Handle err = DartUtils::NewDartOSError(); |
402 if (Dart_IsError(err)) Dart_PropagateError(err); | 432 if (Dart_IsError(err)) Dart_PropagateError(err); |
403 Dart_SetReturnValue(args, err); | 433 Dart_SetReturnValue(args, err); |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1189 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); | 1219 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); |
1190 } | 1220 } |
1191 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1221 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
1192 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1222 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
1193 wrapper->SetAt(1, result); | 1223 wrapper->SetAt(1, result); |
1194 return wrapper; | 1224 return wrapper; |
1195 } | 1225 } |
1196 return CObject::IllegalArgumentError(); | 1226 return CObject::IllegalArgumentError(); |
1197 } | 1227 } |
1198 | 1228 |
1229 | |
1230 CObject* File::LockRequest(const CObjectArray& request) { | |
1231 if (request.Length() == 4 && | |
1232 request[0]->IsIntptr() && | |
1233 request[1]->IsInt32OrInt64() && | |
1234 request[2]->IsInt32OrInt64() && | |
1235 request[3]->IsInt32OrInt64()) { | |
1236 File* file = CObjectToFilePointer(request[0]); | |
1237 ASSERT(file != NULL); | |
1238 if (!file->IsClosed()) { | |
1239 int64_t lock = CObjectInt32OrInt64ToInt64(request[1]); | |
1240 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); | |
1241 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); | |
1242 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { | |
1243 return CObject::True(); | |
1244 } else { | |
1245 return CObject::NewOSError(); | |
1246 } | |
1247 } else { | |
1248 return CObject::FileClosedError(); | |
1249 } | |
1250 } | |
1251 return CObject::IllegalArgumentError(); | |
1252 } | |
1253 | |
1199 } // namespace bin | 1254 } // namespace bin |
1200 } // namespace dart | 1255 } // namespace dart |
OLD | NEW |