Chromium Code Reviews| Index: runtime/bin/file.cc |
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc |
| index 1318fe80e95e0af5170ccbcc81ad8e90197bf7fa..e59955e099835a21e587b6a9b31a76184f7e1b7f 100644 |
| --- a/runtime/bin/file.cc |
| +++ b/runtime/bin/file.cc |
| @@ -79,9 +79,7 @@ void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) { |
| Dart_NewInteger(reinterpret_cast<intptr_t>(file))); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -100,15 +98,12 @@ void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { |
| void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { |
| Dart_EnterScope(); |
| - intptr_t return_value = -1; |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - delete file; |
| - return_value = 0; |
| - } |
| - Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| + ASSERT(file != NULL); |
| + delete file; |
| + Dart_SetReturnValue(args, Dart_NewInteger(0)); |
| Dart_ExitScope(); |
| } |
| @@ -118,20 +113,17 @@ void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - uint8_t buffer; |
| - int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| - if (bytes_read == 1) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(buffer)); |
| - } else if (bytes_read == 0) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(-1)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + uint8_t buffer; |
| + int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| + if (bytes_read == 1) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(buffer)); |
| + } else if (bytes_read == 0) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(-1)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -139,22 +131,31 @@ void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { |
| void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { |
| Dart_EnterScope(); |
| - intptr_t value = |
| + intptr_t file_ptr = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| - File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - int64_t value = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| + File* file = reinterpret_cast<File*>(file_ptr); |
| + ASSERT(file != NULL); |
|
Søren Gjesse
2012/05/16 11:54:11
How about adding a function to do this
int64_t va
Mads Ager (google)
2012/05/16 12:45:19
Maybe we should just change GetIntegerValue to do
|
| + Dart_Handle value_handle = Dart_GetNativeArgument(args, 1); |
| + bool valid_argument = Dart_IsInteger(value_handle); |
| + if (valid_argument) { |
| + Dart_IntegerFitsIntoInt64(value_handle, &valid_argument); |
| + } |
| + if (valid_argument) { |
| + int64_t value = DartUtils::GetIntegerValue(value_handle); |
| uint8_t buffer = static_cast<uint8_t>(value & 0xff); |
| int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| if (bytes_written >= 0) { |
| Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| + } else { |
| + OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| + Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -165,20 +166,17 @@ void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - const char* str = |
| - DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| - int bytes_written = file->Write(reinterpret_cast<const void*>(str), |
| - strlen(str)); |
| - if (bytes_written >= 0) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + const char* str = |
| + DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| + int bytes_written = file->Write(reinterpret_cast<const void*>(str), |
| + strlen(str)); |
| + if (bytes_written >= 0) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -189,38 +187,33 @@ void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| - ASSERT(Dart_IsList(buffer_obj)); |
| - int64_t offset = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| - int64_t length = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| - intptr_t array_len = 0; |
| - Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| + ASSERT(file != NULL); |
| + Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| + ASSERT(Dart_IsList(buffer_obj)); |
| + int64_t offset = |
| + DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| + int64_t length = |
| + DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| + intptr_t array_len = 0; |
| + Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| + if (Dart_IsError(result)) Dart_PropagateError(result); |
| + ASSERT((offset + length) <= array_len); |
| + uint8_t* buffer = new uint8_t[length]; |
| + int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| + if (bytes_read >= 0) { |
| + result = |
|
Søren Gjesse
2012/05/16 11:54:11
Fits one line?
Mads Ager (google)
2012/05/16 12:45:19
Done.
|
| + Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| if (Dart_IsError(result)) { |
| + delete[] buffer; |
| Dart_PropagateError(result); |
| } |
| - ASSERT((offset + length) <= array_len); |
| - uint8_t* buffer = new uint8_t[length]; |
| - int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| - if (bytes_read >= 0) { |
| - result = |
| - Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| - if (Dart_IsError(result)) { |
| - delete[] buffer; |
| - Dart_PropagateError(result); |
| - } |
| - Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| - delete[] buffer; |
| + Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| + delete[] buffer; |
| Dart_ExitScope(); |
| } |
| @@ -230,37 +223,32 @@ void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| - ASSERT(Dart_IsList(buffer_obj)); |
| - int64_t offset = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| - int64_t length = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| - intptr_t buffer_len = 0; |
| - Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| - if (Dart_IsError(result)) { |
| - Dart_PropagateError(result); |
| - } |
| - ASSERT((offset + length) <= buffer_len); |
| - uint8_t* buffer = new uint8_t[length]; |
| - result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| - if (Dart_IsError(result)) { |
| - delete[] buffer; |
| - Dart_PropagateError(result); |
| - } |
| - int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); |
| - if (bytes_written >= 0) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| + ASSERT(Dart_IsList(buffer_obj)); |
| + int64_t offset = |
| + DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
|
Søren Gjesse
2012/05/16 11:54:11
Shouldn't we check more here? DartUtils::GetIntege
Mads Ager (google)
2012/05/16 12:45:19
Oh, yes, here and many other places. I just haven'
|
| + int64_t length = |
| + DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| + intptr_t buffer_len = 0; |
| + Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| + if (Dart_IsError(result)) Dart_PropagateError(result); |
| + ASSERT((offset + length) <= buffer_len); |
| + uint8_t* buffer = new uint8_t[length]; |
| + result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| + if (Dart_IsError(result)) { |
| delete[] buffer; |
| + Dart_PropagateError(result); |
| } |
| + int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); |
| + if (bytes_written >= 0) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| + } |
| + delete[] buffer; |
| Dart_ExitScope(); |
| } |
| @@ -270,17 +258,14 @@ void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - intptr_t return_value = file->Position(); |
| - if (return_value >= 0) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + intptr_t return_value = file->Position(); |
| + if (return_value >= 0) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -291,18 +276,26 @@ void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - int64_t position = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| + ASSERT(file != NULL); |
| + Dart_Handle pos_handle = Dart_GetNativeArgument(args, 1); |
| + bool valid_argument = false; |
| + if (Dart_IsInteger(pos_handle)) { |
| + Dart_IntegerFitsIntoInt64(pos_handle, &valid_argument); |
| + } |
| + if (valid_argument) { |
| + int64_t position = DartUtils::GetIntegerValue(pos_handle); |
| if (file->SetPosition(position)) { |
| Dart_SetReturnValue(args, Dart_True()); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| + } else { |
| + OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| + Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -313,18 +306,15 @@ void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - int64_t length = |
| - DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| - if (file->Truncate(length)) { |
| - Dart_SetReturnValue(args, Dart_True()); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + int64_t length = |
| + DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| + if (file->Truncate(length)) { |
| + Dart_SetReturnValue(args, Dart_True()); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -335,17 +325,14 @@ void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - intptr_t return_value = file->Length(); |
| - if (return_value >= 0) { |
| - Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + intptr_t return_value = file->Length(); |
| + if (return_value >= 0) { |
| + Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -360,9 +347,7 @@ void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) { |
| Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -374,16 +359,13 @@ void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { |
| intptr_t value = |
| DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| File* file = reinterpret_cast<File*>(value); |
| - if (file != NULL) { |
| - if (file->Flush()) { |
| - Dart_SetReturnValue(args, Dart_True()); |
| - } else { |
| - Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| - Dart_SetReturnValue(args, err); |
| - } |
| + ASSERT(file != NULL); |
| + if (file->Flush()) { |
| + Dart_SetReturnValue(args, Dart_True()); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| } |
| @@ -398,9 +380,7 @@ void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
| Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -416,9 +396,7 @@ void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { |
| Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -437,9 +415,7 @@ void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { |
| free(path); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -456,9 +432,7 @@ void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { |
| free(path); |
| } else { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| - if (Dart_IsError(err)) { |
| - Dart_PropagateError(err); |
| - } |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| } |
| Dart_ExitScope(); |
| @@ -600,10 +574,9 @@ static CObject* FileCloseRequest(const CObjectArray& request) { |
| intptr_t return_value = -1; |
| if (request.Length() == 2 && request[1]->IsIntptr()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL) { |
| - delete file; |
| - return_value = 0; |
| - } |
| + ASSERT(file != NULL); |
| + delete file; |
| + return_value = 0; |
| } |
| return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| } |
| @@ -612,7 +585,8 @@ static CObject* FileCloseRequest(const CObjectArray& request) { |
| static CObject* FilePositionRequest(const CObjectArray& request) { |
| if (request.Length() == 2 && request[1]->IsIntptr()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| intptr_t return_value = file->Position(); |
| if (return_value >= 0) { |
| return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| @@ -632,7 +606,8 @@ static CObject* FileSetPositionRequest(const CObjectArray& request) { |
| request[1]->IsIntptr() && |
| request[2]->IsInt32OrInt64()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| int64_t position = CObjectInt32OrInt64ToInt64(request[2]); |
| if (file->SetPosition(position)) { |
| return CObject::True(); |
| @@ -652,7 +627,8 @@ static CObject* FileTruncateRequest(const CObjectArray& request) { |
| request[1]->IsIntptr() && |
| request[2]->IsInt32OrInt64()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| if (file->Truncate(length)) { |
| return CObject::True(); |
| @@ -670,7 +646,8 @@ static CObject* FileTruncateRequest(const CObjectArray& request) { |
| static CObject* FileLengthRequest(const CObjectArray& request) { |
| if (request.Length() == 2 && request[1]->IsIntptr()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| intptr_t return_value = file->Length(); |
| if (return_value >= 0) { |
| return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| @@ -700,10 +677,10 @@ static CObject* FileLengthFromNameRequest(const CObjectArray& request) { |
| static CObject* FileFlushRequest(const CObjectArray& request) { |
| - intptr_t return_value = -1; |
| if (request.Length() == 2 && request[1]->IsIntptr()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| if (file->Flush()) { |
| return CObject::True(); |
| } else { |
| @@ -714,14 +691,14 @@ static CObject* FileFlushRequest(const CObjectArray& request) { |
| } |
| } |
| return CObject::IllegalArgumentError(); |
| - return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| } |
| static CObject* FileReadByteRequest(const CObjectArray& request) { |
| if (request.Length() == 2 && request[1]->IsIntptr()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| uint8_t buffer; |
| int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| if (bytes_read > 0) { |
| @@ -744,7 +721,8 @@ static CObject* FileWriteByteRequest(const CObjectArray& request) { |
| request[1]->IsIntptr() && |
| request[2]->IsInt32OrInt64()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| int64_t byte = CObjectInt32OrInt64ToInt64(request[2]); |
| uint8_t buffer = static_cast<uint8_t>(byte & 0xff); |
| int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| @@ -766,7 +744,8 @@ static CObject* FileReadListRequest(const CObjectArray& request) { |
| request[1]->IsIntptr() && |
| request[2]->IsInt32OrInt64()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| CObjectUint8Array* byte_array = |
| new CObjectUint8Array(CObject::NewUint8Array(length)); |
| @@ -796,7 +775,8 @@ static CObject* FileWriteListRequest(const CObjectArray& request) { |
| request[3]->IsInt32OrInt64() && |
| request[4]->IsInt32OrInt64()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); |
| int64_t length = CObjectInt32OrInt64ToInt64(request[4]); |
| uint8_t* buffer_start; |
| @@ -841,7 +821,8 @@ static CObject* FileWriteStringRequest(const CObjectArray& request) { |
| request[1]->IsIntptr() && |
| request[2]->IsString()) { |
| File* file = CObjectToFilePointer(request[1]); |
| - if (file != NULL && !file->IsClosed()) { |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| CObjectString str(request[2]); |
| const void* buffer = reinterpret_cast<const void*>(str.CString()); |
| int64_t bytes_written = file->Write(buffer, str.Length()); |