| 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/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 912 |
| 913 static CObject* FileReadRequest(const CObjectArray& request) { | 913 static CObject* FileReadRequest(const CObjectArray& request) { |
| 914 if (request.Length() == 3 && | 914 if (request.Length() == 3 && |
| 915 request[1]->IsIntptr() && | 915 request[1]->IsIntptr() && |
| 916 request[2]->IsInt32OrInt64()) { | 916 request[2]->IsInt32OrInt64()) { |
| 917 File* file = CObjectToFilePointer(request[1]); | 917 File* file = CObjectToFilePointer(request[1]); |
| 918 ASSERT(file != NULL); | 918 ASSERT(file != NULL); |
| 919 if (!file->IsClosed()) { | 919 if (!file->IsClosed()) { |
| 920 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 920 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 921 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); | 921 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); |
| 922 ASSERT(io_buffer != NULL); |
| 922 uint8_t* data = io_buffer->value.as_external_typed_data.data; | 923 uint8_t* data = io_buffer->value.as_external_typed_data.data; |
| 923 int64_t bytes_read = file->Read(data, length); | 924 int64_t bytes_read = file->Read(data, length); |
| 924 if (bytes_read >= 0) { | 925 if (bytes_read >= 0) { |
| 925 CObjectExternalUint8Array* external_array = | 926 CObjectExternalUint8Array* external_array = |
| 926 new CObjectExternalUint8Array(io_buffer); | 927 new CObjectExternalUint8Array(io_buffer); |
| 927 external_array->SetLength(bytes_read); | 928 external_array->SetLength(bytes_read); |
| 928 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); | 929 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); |
| 929 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 930 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
| 930 result->SetAt(1, external_array); | 931 result->SetAt(1, external_array); |
| 931 return result; | 932 return result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 943 | 944 |
| 944 static CObject* FileReadIntoRequest(const CObjectArray& request) { | 945 static CObject* FileReadIntoRequest(const CObjectArray& request) { |
| 945 if (request.Length() == 3 && | 946 if (request.Length() == 3 && |
| 946 request[1]->IsIntptr() && | 947 request[1]->IsIntptr() && |
| 947 request[2]->IsInt32OrInt64()) { | 948 request[2]->IsInt32OrInt64()) { |
| 948 File* file = CObjectToFilePointer(request[1]); | 949 File* file = CObjectToFilePointer(request[1]); |
| 949 ASSERT(file != NULL); | 950 ASSERT(file != NULL); |
| 950 if (!file->IsClosed()) { | 951 if (!file->IsClosed()) { |
| 951 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 952 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 952 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); | 953 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); |
| 954 ASSERT(io_buffer != NULL); |
| 953 uint8_t* data = io_buffer->value.as_external_typed_data.data; | 955 uint8_t* data = io_buffer->value.as_external_typed_data.data; |
| 954 int64_t bytes_read = file->Read(data, length); | 956 int64_t bytes_read = file->Read(data, length); |
| 955 if (bytes_read >= 0) { | 957 if (bytes_read >= 0) { |
| 956 CObjectExternalUint8Array* external_array = | 958 CObjectExternalUint8Array* external_array = |
| 957 new CObjectExternalUint8Array(io_buffer); | 959 new CObjectExternalUint8Array(io_buffer); |
| 958 external_array->SetLength(bytes_read); | 960 external_array->SetLength(bytes_read); |
| 959 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 961 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 960 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 962 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
| 961 result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read))); | 963 result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read))); |
| 962 result->SetAt(2, external_array); | 964 result->SetAt(2, external_array); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 Dart_Port service_port = File::GetServicePort(); | 1274 Dart_Port service_port = File::GetServicePort(); |
| 1273 if (service_port != ILLEGAL_PORT) { | 1275 if (service_port != ILLEGAL_PORT) { |
| 1274 // Return a send port for the service port. | 1276 // Return a send port for the service port. |
| 1275 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1277 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 1276 Dart_SetReturnValue(args, send_port); | 1278 Dart_SetReturnValue(args, send_port); |
| 1277 } | 1279 } |
| 1278 } | 1280 } |
| 1279 | 1281 |
| 1280 } // namespace bin | 1282 } // namespace bin |
| 1281 } // namespace dart | 1283 } // namespace dart |
| OLD | NEW |