| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 | 135 |
| 136 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { | 136 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { |
| 137 Dart_EnterScope(); | 137 Dart_EnterScope(); |
| 138 intptr_t return_value = -1; | 138 intptr_t return_value = -1; |
| 139 intptr_t value = | 139 intptr_t value = |
| 140 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 140 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 141 File* file = reinterpret_cast<File*>(value); | 141 File* file = reinterpret_cast<File*>(value); |
| 142 if (file != NULL) { | 142 if (file != NULL) { |
| 143 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 143 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 144 ASSERT(Dart_IsArray(buffer_obj)); | 144 ASSERT(Dart_IsList(buffer_obj)); |
| 145 int64_t offset = | 145 int64_t offset = |
| 146 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 146 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 147 int64_t length = | 147 int64_t length = |
| 148 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 148 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 149 intptr_t array_len = 0; | 149 intptr_t array_len = 0; |
| 150 Dart_Handle result = Dart_GetLength(buffer_obj, &array_len); | 150 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 151 ASSERT(Dart_IsValid(result)); | 151 ASSERT(Dart_IsValid(result)); |
| 152 ASSERT((offset + length) <= array_len); | 152 ASSERT((offset + length) <= array_len); |
| 153 uint8_t* buffer = new uint8_t[length]; | 153 uint8_t* buffer = new uint8_t[length]; |
| 154 int total_bytes_read = | 154 int total_bytes_read = |
| 155 file->Read(reinterpret_cast<void*>(buffer), length); | 155 file->Read(reinterpret_cast<void*>(buffer), length); |
| 156 /* | 156 /* |
| 157 * Reading 0 indicates end of file. | 157 * Reading 0 indicates end of file. |
| 158 */ | 158 */ |
| 159 if (total_bytes_read >= 0) { | 159 if (total_bytes_read >= 0) { |
| 160 result = | 160 result = |
| 161 Dart_ArraySet(buffer_obj, offset, buffer, total_bytes_read); | 161 Dart_ListSetAsBytes(buffer_obj, offset, buffer, total_bytes_read); |
| 162 ASSERT(Dart_IsValid(result)); | 162 ASSERT(Dart_IsValid(result)); |
| 163 return_value = total_bytes_read; | 163 return_value = total_bytes_read; |
| 164 } | 164 } |
| 165 delete[] buffer; | 165 delete[] buffer; |
| 166 } | 166 } |
| 167 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 167 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 168 Dart_ExitScope(); | 168 Dart_ExitScope(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { | 172 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| 173 Dart_EnterScope(); | 173 Dart_EnterScope(); |
| 174 intptr_t return_value = -1; | 174 intptr_t return_value = -1; |
| 175 intptr_t value = | 175 intptr_t value = |
| 176 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 176 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 177 File* file = reinterpret_cast<File*>(value); | 177 File* file = reinterpret_cast<File*>(value); |
| 178 if (file != NULL) { | 178 if (file != NULL) { |
| 179 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 179 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 180 ASSERT(Dart_IsArray(buffer_obj)); | 180 ASSERT(Dart_IsList(buffer_obj)); |
| 181 int64_t offset = | 181 int64_t offset = |
| 182 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 182 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 183 int64_t length = | 183 int64_t length = |
| 184 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 184 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 185 intptr_t buffer_len = 0; | 185 intptr_t buffer_len = 0; |
| 186 Dart_Handle result = Dart_GetLength(buffer_obj, &buffer_len); | 186 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 187 ASSERT(Dart_IsValid(result)); | 187 ASSERT(Dart_IsValid(result)); |
| 188 ASSERT((offset + length) <= buffer_len); | 188 ASSERT((offset + length) <= buffer_len); |
| 189 uint8_t* buffer = new uint8_t[length]; | 189 uint8_t* buffer = new uint8_t[length]; |
| 190 result = Dart_ArrayGet(buffer_obj, offset, buffer, length); | 190 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| 191 ASSERT(Dart_IsValid(result)); | 191 ASSERT(Dart_IsValid(result)); |
| 192 int total_bytes_written = | 192 int total_bytes_written = |
| 193 file->Write(reinterpret_cast<void*>(buffer), length); | 193 file->Write(reinterpret_cast<void*>(buffer), length); |
| 194 if (total_bytes_written >= 0) { | 194 if (total_bytes_written >= 0) { |
| 195 return_value = total_bytes_written; | 195 return_value = total_bytes_written; |
| 196 } | 196 } |
| 197 delete[] buffer; | 197 delete[] buffer; |
| 198 } | 198 } |
| 199 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 199 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 200 Dart_ExitScope(); | 200 Dart_ExitScope(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 Dart_EnterScope(); | 258 Dart_EnterScope(); |
| 259 const char* str = | 259 const char* str = |
| 260 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 260 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 261 char* path = File::GetCanonicalPath(str); | 261 char* path = File::GetCanonicalPath(str); |
| 262 if (path != NULL) { | 262 if (path != NULL) { |
| 263 Dart_SetReturnValue(args, Dart_NewString(path)); | 263 Dart_SetReturnValue(args, Dart_NewString(path)); |
| 264 free(path); | 264 free(path); |
| 265 } | 265 } |
| 266 Dart_ExitScope(); | 266 Dart_ExitScope(); |
| 267 } | 267 } |
| OLD | NEW |