| 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 return CObject::NewOSError(); | 767 return CObject::NewOSError(); |
| 768 } | 768 } |
| 769 } else { | 769 } else { |
| 770 return CObject::FileClosedError(); | 770 return CObject::FileClosedError(); |
| 771 } | 771 } |
| 772 } | 772 } |
| 773 return CObject::IllegalArgumentError(); | 773 return CObject::IllegalArgumentError(); |
| 774 } | 774 } |
| 775 | 775 |
| 776 | 776 |
| 777 static void FinalizeExternalByteArray(void* peer) { |
| 778 delete[] reinterpret_cast<uint8_t*>(peer); |
| 779 } |
| 780 |
| 781 |
| 777 static CObject* FileReadListRequest(const CObjectArray& request) { | 782 static CObject* FileReadListRequest(const CObjectArray& request) { |
| 778 if (request.Length() == 3 && | 783 if (request.Length() == 3 && |
| 779 request[1]->IsIntptr() && | 784 request[1]->IsIntptr() && |
| 780 request[2]->IsInt32OrInt64()) { | 785 request[2]->IsInt32OrInt64()) { |
| 781 File* file = CObjectToFilePointer(request[1]); | 786 File* file = CObjectToFilePointer(request[1]); |
| 782 ASSERT(file != NULL); | 787 ASSERT(file != NULL); |
| 783 if (!file->IsClosed()) { | 788 if (!file->IsClosed()) { |
| 784 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 789 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 785 CObjectUint8Array* byte_array = | 790 uint8_t* buffer = new uint8_t[length]; |
| 786 new CObjectUint8Array(CObject::NewUint8Array(length)); | 791 int bytes_read = file->Read(buffer, length); |
| 787 void* buffer = reinterpret_cast<void*>(byte_array->Buffer()); | |
| 788 int bytes_read = file->Read(buffer, byte_array->Length()); | |
| 789 if (bytes_read >= 0) { | 792 if (bytes_read >= 0) { |
| 793 void* peer = reinterpret_cast<void*>(buffer); |
| 794 CObject* external_array = |
| 795 new CObjectExternalUint8Array( |
| 796 CObject::NewExternalUint8Array(length, |
| 797 buffer, |
| 798 peer, |
| 799 FinalizeExternalByteArray)); |
| 790 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 800 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 791 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 801 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
| 792 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); | 802 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); |
| 793 result->SetAt(2, byte_array); | 803 result->SetAt(2, external_array); |
| 794 return result; | 804 return result; |
| 795 } else { | 805 } else { |
| 796 return CObject::NewOSError(); | 806 return CObject::NewOSError(); |
| 797 } | 807 } |
| 798 } else { | 808 } else { |
| 799 return CObject::FileClosedError(); | 809 return CObject::FileClosedError(); |
| 800 } | 810 } |
| 801 } | 811 } |
| 802 return CObject::IllegalArgumentError(); | 812 return CObject::IllegalArgumentError(); |
| 803 } | 813 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 Dart_EnterScope(); | 985 Dart_EnterScope(); |
| 976 Dart_SetReturnValue(args, Dart_Null()); | 986 Dart_SetReturnValue(args, Dart_Null()); |
| 977 Dart_Port service_port = File::GetServicePort(); | 987 Dart_Port service_port = File::GetServicePort(); |
| 978 if (service_port != kIllegalPort) { | 988 if (service_port != kIllegalPort) { |
| 979 // Return a send port for the service port. | 989 // Return a send port for the service port. |
| 980 Dart_Handle send_port = Dart_NewSendPort(service_port); | 990 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 981 Dart_SetReturnValue(args, send_port); | 991 Dart_SetReturnValue(args, send_port); |
| 982 } | 992 } |
| 983 Dart_ExitScope(); | 993 Dart_ExitScope(); |
| 984 } | 994 } |
| OLD | NEW |