| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "dart/runtime/include/dart_api.h" | 9 #include "dart/runtime/include/dart_api.h" |
| 10 #include "mojo/dart/embedder/builtin.h" | 10 #include "mojo/dart/embedder/builtin.h" |
| 11 #include "mojo/dart/embedder/common.h" | 11 #include "mojo/dart/embedder/common.h" |
| 12 #include "mojo/dart/embedder/io/filter.h" | 12 #include "mojo/dart/embedder/io/filter.h" |
| 13 #include "mojo/dart/embedder/io/internet_address.h" | 13 #include "mojo/dart/embedder/io/internet_address.h" |
| 14 #include "mojo/dart/embedder/mojo_dart_state.h" | 14 #include "mojo/dart/embedder/mojo_dart_state.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace dart { | 18 namespace dart { |
| 19 | 19 |
| 20 #define MOJO_IO_NATIVE_LIST(V) \ | 20 #define MOJO_IO_NATIVE_LIST(V) \ |
| 21 V(Filter_CreateZLibDeflate, 8) \ | 21 V(Filter_CreateZLibDeflate, 8) \ |
| 22 V(Filter_CreateZLibInflate, 4) \ | 22 V(Filter_CreateZLibInflate, 4) \ |
| 23 V(Filter_End, 1) \ | |
| 24 V(Filter_Process, 4) \ | 23 V(Filter_Process, 4) \ |
| 25 V(Filter_Processed, 3) \ | 24 V(Filter_Processed, 3) \ |
| 26 V(InternetAddress_Parse, 1) \ | 25 V(InternetAddress_Parse, 1) \ |
| 27 V(InternetAddress_Reverse, 1) \ | 26 V(InternetAddress_Reverse, 1) \ |
| 28 V(Platform_NumberOfProcessors, 0) \ | 27 V(Platform_NumberOfProcessors, 0) \ |
| 29 V(Platform_OperatingSystem, 0) \ | 28 V(Platform_OperatingSystem, 0) \ |
| 30 V(Platform_PathSeparator, 0) \ | 29 V(Platform_PathSeparator, 0) \ |
| 31 V(Platform_LocalHostname, 0) \ | 30 V(Platform_LocalHostname, 0) \ |
| 32 V(Platform_ExecutableName, 0) \ | 31 V(Platform_ExecutableName, 0) \ |
| 33 V(Platform_Environment, 0) \ | 32 V(Platform_Environment, 0) \ |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 static void Finalizer(void* isolate_callback_data, | 107 static void Finalizer(void* isolate_callback_data, |
| 109 Dart_WeakPersistentHandle handle, | 108 Dart_WeakPersistentHandle handle, |
| 110 void* buffer) { | 109 void* buffer) { |
| 111 Free(buffer); | 110 Free(buffer); |
| 112 } | 111 } |
| 113 | 112 |
| 114 private: | 113 private: |
| 115 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); | 114 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); |
| 116 }; | 115 }; |
| 117 | 116 |
| 118 static Filter* GetFilter(Dart_Handle filter_obj) { | 117 static Dart_Handle GetFilter(Dart_Handle filter_obj, Filter** filter) { |
| 119 Filter* filter; | 118 CHECK(filter != NULL); |
| 120 Dart_Handle result = Filter::GetFilterPointerNativeField(filter_obj, &filter); | 119 Filter* result; |
| 121 if (Dart_IsError(result)) { | 120 Dart_Handle err = Filter::GetFilterNativeField(filter_obj, &result); |
| 122 Dart_PropagateError(result); | 121 if (Dart_IsError(err)) { |
| 122 return err; |
| 123 } | 123 } |
| 124 if (filter == NULL) { | 124 if (result == NULL) { |
| 125 Dart_ThrowException(DartEmbedder::NewInternalError("Filter destroyed")); | 125 return Dart_NewApiError("Filter was destroyed"); |
| 126 } | 126 } |
| 127 return filter; | 127 |
| 128 *filter = result; |
| 129 return Dart_Null(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 static void EndFilter(Dart_Handle filter_obj, Filter* filter) { | 132 static Dart_Handle CopyDictionary(Dart_Handle dictionary_obj, |
| 131 Filter::SetFilterPointerNativeField(filter_obj, NULL); | 133 uint8_t** dictionary) { |
| 132 delete filter; | 134 CHECK(dictionary != NULL); |
| 133 } | |
| 134 | |
| 135 static uint8_t* copyDictionary(Dart_Handle dictionary_obj) { | |
| 136 uint8_t* src = NULL; | 135 uint8_t* src = NULL; |
| 137 intptr_t size; | 136 intptr_t size; |
| 138 Dart_TypedData_Type type; | 137 Dart_TypedData_Type type; |
| 139 | 138 |
| 140 if (Dart_IsError(Dart_ListLength(dictionary_obj, &size))) { | 139 Dart_Handle err = Dart_ListLength(dictionary_obj, &size); |
| 141 Dart_ThrowException(DartEmbedder::NewInternalError( | 140 if (Dart_IsError(err)) { |
| 142 "Failed to get the zlib dictionary length")); | 141 return err; |
| 143 } | 142 } |
| 144 | 143 |
| 145 uint8_t* dictionary = new uint8_t[size]; | 144 uint8_t* result = new uint8_t[size]; |
| 146 | 145 if (result == NULL) { |
| 147 if (dictionary == NULL) { | 146 return Dart_NewApiError("Could not allocate new dictionary"); |
| 148 Dart_ThrowException(DartEmbedder::NewInternalError( | |
| 149 "Failed to allocate buffer for the zlib dictionary")); | |
| 150 } | 147 } |
| 151 | 148 |
| 152 Dart_Handle result = Dart_TypedDataAcquireData( | 149 err = Dart_TypedDataAcquireData( |
| 153 dictionary_obj, &type, reinterpret_cast<void**>(&src), &size); | 150 dictionary_obj, &type, reinterpret_cast<void**>(&src), &size); |
| 154 if (!Dart_IsError(result)) { | 151 if (!Dart_IsError(err)) { |
| 155 memmove(dictionary, src, size); | 152 memmove(result, src, size); |
| 156 Dart_TypedDataReleaseData(dictionary_obj); | 153 Dart_TypedDataReleaseData(dictionary_obj); |
| 157 } else { | 154 } else { |
| 158 if (Dart_IsError(Dart_ListGetAsBytes(dictionary_obj, 0, dictionary, | 155 err = Dart_ListGetAsBytes(dictionary_obj, 0, result, size); |
| 159 size))) { | 156 if (Dart_IsError(err)) { |
| 160 Dart_ThrowException(DartEmbedder::NewInternalError( | 157 delete[] result; |
| 161 "Failed to get the zlib dictionary")); | 158 return err; |
| 162 } | 159 } |
| 163 } | 160 } |
| 164 | 161 |
| 165 return dictionary; | 162 *dictionary = result; |
| 163 return Dart_Null(); |
| 166 } | 164 } |
| 167 | 165 |
| 168 void Filter_CreateZLibInflate(Dart_NativeArguments args) { | 166 void Filter_CreateZLibInflate(Dart_NativeArguments args) { |
| 169 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 167 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 170 Dart_Handle window_bits_obj = Dart_GetNativeArgument(args, 1); | 168 int64_t window_bits = DartEmbedder::GetIntegerArgument(args, 1); |
| 171 int64_t window_bits = DartEmbedder::GetIntegerValue(window_bits_obj); | |
| 172 Dart_Handle dict_obj = Dart_GetNativeArgument(args, 2); | 169 Dart_Handle dict_obj = Dart_GetNativeArgument(args, 2); |
| 170 bool raw = DartEmbedder::GetBooleanArgument(args, 3); |
| 171 |
| 172 Dart_Handle err; |
| 173 uint8_t* dictionary = NULL; | 173 uint8_t* dictionary = NULL; |
| 174 intptr_t dictionary_length = 0; | 174 intptr_t dictionary_length = 0; |
| 175 if (!Dart_IsNull(dict_obj)) { | 175 if (!Dart_IsNull(dict_obj)) { |
| 176 dictionary = copyDictionary(dict_obj); | 176 err = CopyDictionary(dict_obj, &dictionary); |
| 177 if (dictionary != NULL) { | 177 if (Dart_IsError(err)) { |
| 178 dictionary_length = 0; | 178 Dart_PropagateError(err); |
| 179 Dart_ListLength(dict_obj, &dictionary_length); | 179 } |
| 180 CHECK(dictionary != NULL); |
| 181 dictionary_length = 0; |
| 182 err = Dart_ListLength(dict_obj, &dictionary_length); |
| 183 if (Dart_IsError(err)) { |
| 184 delete[] dictionary; |
| 185 Dart_PropagateError(err); |
| 180 } | 186 } |
| 181 } | 187 } |
| 182 Dart_Handle raw_obj = Dart_GetNativeArgument(args, 3); | 188 |
| 183 bool raw; | 189 ZLibInflateFilter* filter = new ZLibInflateFilter( |
| 184 if (Dart_IsError(Dart_BooleanValue(raw_obj, &raw))) { | 190 static_cast<int32_t>(window_bits), dictionary, dictionary_length, raw); |
| 185 Dart_ThrowException(DartEmbedder::NewInternalError( | 191 if (filter == NULL) { |
| 186 "Failed to get 'raw' parameter")); | 192 delete[] dictionary; |
| 193 Dart_PropagateError(Dart_NewApiError( |
| 194 "Could not allocate ZLibInflateFilter")); |
| 187 } | 195 } |
| 188 Filter* filter = new ZLibInflateFilter(static_cast<int32_t>(window_bits), | |
| 189 dictionary, dictionary_length, raw); | |
| 190 if (!filter->Init()) { | 196 if (!filter->Init()) { |
| 191 delete filter; | 197 delete filter; |
| 192 Dart_ThrowException(DartEmbedder::NewInternalError( | 198 Dart_ThrowException(DartEmbedder::NewInternalError( |
| 193 "Failed to create ZLibInflateFilter")); | 199 "Failed to create ZLibInflateFilter")); |
| 194 } | 200 } |
| 195 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter); | 201 err = Filter::SetFilterAndCreateFinalizer( |
| 196 if (Dart_IsError(result)) { | 202 filter_obj, filter, sizeof(*filter) + dictionary_length); |
| 203 if (Dart_IsError(err)) { |
| 197 delete filter; | 204 delete filter; |
| 198 Dart_PropagateError(result); | 205 Dart_PropagateError(err); |
| 199 } | 206 } |
| 200 } | 207 } |
| 201 | 208 |
| 202 void Filter_CreateZLibDeflate(Dart_NativeArguments args) { | 209 void Filter_CreateZLibDeflate(Dart_NativeArguments args) { |
| 203 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 210 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 204 Dart_Handle gzip_obj = Dart_GetNativeArgument(args, 1); | 211 bool gzip = DartEmbedder::GetBooleanArgument(args, 1); |
| 205 bool gzip = DartEmbedder::GetBooleanValue(gzip_obj); | |
| 206 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2); | 212 Dart_Handle level_obj = Dart_GetNativeArgument(args, 2); |
| 207 int64_t level = DartEmbedder::GetInt64ValueCheckRange( | 213 int64_t level = DartEmbedder::GetInt64ValueCheckRange( |
| 208 level_obj, | 214 level_obj, |
| 209 std::numeric_limits<int32_t>::min(), | 215 std::numeric_limits<int32_t>::min(), |
| 210 std::numeric_limits<int32_t>::max()); | 216 std::numeric_limits<int32_t>::max()); |
| 211 Dart_Handle window_bits_obj = Dart_GetNativeArgument(args, 3); | 217 int64_t window_bits = DartEmbedder::GetIntegerArgument(args, 3); |
| 212 int64_t window_bits = DartEmbedder::GetIntegerValue(window_bits_obj); | 218 int64_t mem_level = DartEmbedder::GetIntegerArgument(args, 4); |
| 213 Dart_Handle mLevel_obj = Dart_GetNativeArgument(args, 4); | 219 int64_t strategy = DartEmbedder::GetIntegerArgument(args, 5); |
| 214 int64_t mem_level = DartEmbedder::GetIntegerValue(mLevel_obj); | |
| 215 Dart_Handle strategy_obj = Dart_GetNativeArgument(args, 5); | |
| 216 int64_t strategy = DartEmbedder::GetIntegerValue(strategy_obj); | |
| 217 Dart_Handle dict_obj = Dart_GetNativeArgument(args, 6); | 220 Dart_Handle dict_obj = Dart_GetNativeArgument(args, 6); |
| 221 bool raw = DartEmbedder::GetBooleanArgument(args, 7); |
| 222 |
| 223 Dart_Handle err; |
| 218 uint8_t* dictionary = NULL; | 224 uint8_t* dictionary = NULL; |
| 219 intptr_t dictionary_length = 0; | 225 intptr_t dictionary_length = 0; |
| 220 if (!Dart_IsNull(dict_obj)) { | 226 if (!Dart_IsNull(dict_obj)) { |
| 221 dictionary = copyDictionary(dict_obj); | 227 err = CopyDictionary(dict_obj, &dictionary); |
| 222 if (dictionary != NULL) { | 228 if (Dart_IsError(err)) { |
| 223 dictionary_length = 0; | 229 Dart_PropagateError(err); |
| 224 Dart_ListLength(dict_obj, &dictionary_length); | 230 } |
| 231 CHECK(dictionary != NULL); |
| 232 dictionary_length = 0; |
| 233 err = Dart_ListLength(dict_obj, &dictionary_length); |
| 234 if (Dart_IsError(err)) { |
| 235 delete[] dictionary; |
| 236 Dart_PropagateError(err); |
| 225 } | 237 } |
| 226 } | 238 } |
| 227 Dart_Handle raw_obj = Dart_GetNativeArgument(args, 7); | 239 |
| 228 bool raw = DartEmbedder::GetBooleanValue(raw_obj); | 240 ZLibDeflateFilter* filter = new ZLibDeflateFilter( |
| 229 Filter* filter = new ZLibDeflateFilter(gzip, static_cast<int32_t>(level), | 241 gzip, |
| 230 static_cast<int32_t>(window_bits), | 242 static_cast<int32_t>(level), |
| 231 static_cast<int32_t>(mem_level), | 243 static_cast<int32_t>(window_bits), |
| 232 static_cast<int32_t>(strategy), | 244 static_cast<int32_t>(mem_level), |
| 233 dictionary, dictionary_length, raw); | 245 static_cast<int32_t>(strategy), |
| 246 dictionary, dictionary_length, raw); |
| 247 if (filter == NULL) { |
| 248 delete[] dictionary; |
| 249 Dart_PropagateError(Dart_NewApiError( |
| 250 "Could not allocate ZLibDeflateFilter")); |
| 251 } |
| 234 if (!filter->Init()) { | 252 if (!filter->Init()) { |
| 235 delete filter; | 253 delete filter; |
| 236 Dart_ThrowException(DartEmbedder::NewInternalError( | 254 Dart_ThrowException(DartEmbedder::NewInternalError( |
| 237 "Failed to create ZLibDeflateFilter")); | 255 "Failed to create ZLibDeflateFilter")); |
| 238 } | 256 } |
| 239 Dart_Handle result = Filter::SetFilterPointerNativeField(filter_obj, filter); | 257 Dart_Handle result = Filter::SetFilterAndCreateFinalizer( |
| 258 filter_obj, filter, sizeof(*filter) + dictionary_length); |
| 240 if (Dart_IsError(result)) { | 259 if (Dart_IsError(result)) { |
| 241 delete filter; | 260 delete filter; |
| 242 Dart_PropagateError(result); | 261 Dart_PropagateError(result); |
| 243 } | 262 } |
| 244 } | 263 } |
| 245 | 264 |
| 246 void Filter_Process(Dart_NativeArguments args) { | 265 void Filter_Process(Dart_NativeArguments args) { |
| 247 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 266 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 248 Filter* filter = GetFilter(filter_obj); | |
| 249 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); | 267 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); |
| 250 intptr_t start = | 268 intptr_t start = DartEmbedder::GetIntptrArgument(args, 2); |
| 251 DartEmbedder::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 269 intptr_t end = DartEmbedder::GetIntptrArgument(args, 3); |
| 252 intptr_t end = DartEmbedder::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | |
| 253 intptr_t chunk_length = end - start; | 270 intptr_t chunk_length = end - start; |
| 254 intptr_t length; | 271 intptr_t length; |
| 255 Dart_TypedData_Type type; | 272 Dart_TypedData_Type type; |
| 256 uint8_t* buffer = NULL; | 273 uint8_t* buffer = NULL; |
| 274 |
| 275 Filter* filter = NULL; |
| 276 Dart_Handle err = GetFilter(filter_obj, &filter); |
| 277 if (Dart_IsError(err)) { |
| 278 Dart_PropagateError(err); |
| 279 } |
| 280 |
| 257 Dart_Handle result = Dart_TypedDataAcquireData( | 281 Dart_Handle result = Dart_TypedDataAcquireData( |
| 258 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); | 282 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); |
| 259 | |
| 260 if (!Dart_IsError(result)) { | 283 if (!Dart_IsError(result)) { |
| 261 DCHECK(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); | 284 CHECK(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); |
| 262 if (type != Dart_TypedData_kUint8 && type != Dart_TypedData_kInt8) { | 285 if (type != Dart_TypedData_kUint8 && type != Dart_TypedData_kInt8) { |
| 263 Dart_TypedDataReleaseData(data_obj); | 286 Dart_TypedDataReleaseData(data_obj); |
| 264 Dart_ThrowException(DartEmbedder::NewInternalError( | 287 Dart_ThrowException(DartEmbedder::NewInternalError( |
| 265 "Invalid argument passed to Filter_Process")); | 288 "Invalid argument passed to Filter_Process")); |
| 266 } | 289 } |
| 267 uint8_t* zlib_buffer = new uint8_t[chunk_length]; | 290 uint8_t* zlib_buffer = new uint8_t[chunk_length]; |
| 268 if (zlib_buffer == NULL) { | 291 if (zlib_buffer == NULL) { |
| 269 Dart_TypedDataReleaseData(data_obj); | 292 Dart_TypedDataReleaseData(data_obj); |
| 270 Dart_ThrowException(DartEmbedder::NewInternalError( | 293 Dart_PropagateError(Dart_NewApiError("Could not allocate zlib buffer")); |
| 271 "Failed to allocate buffer for zlib")); | |
| 272 } | 294 } |
| 295 |
| 273 memmove(zlib_buffer, buffer + start, chunk_length); | 296 memmove(zlib_buffer, buffer + start, chunk_length); |
| 274 Dart_TypedDataReleaseData(data_obj); | 297 Dart_TypedDataReleaseData(data_obj); |
| 275 buffer = zlib_buffer; | 298 buffer = zlib_buffer; |
| 276 } else { | 299 } else { |
| 277 if (Dart_IsError(Dart_ListLength(data_obj, &length))) { | 300 err = Dart_ListLength(data_obj, &length); |
| 278 Dart_ThrowException(DartEmbedder::NewInternalError( | 301 if (Dart_IsError(err)) { |
| 279 "Failed to get list length")); | 302 Dart_PropagateError(err); |
| 280 } | 303 } |
| 281 buffer = new uint8_t[chunk_length]; | 304 buffer = new uint8_t[chunk_length]; |
| 282 if (Dart_IsError(Dart_ListGetAsBytes( | 305 if (buffer == NULL) { |
| 283 data_obj, start, buffer, chunk_length))) { | 306 Dart_PropagateError(Dart_NewApiError("Could not allocate buffer")); |
| 307 } |
| 308 err = Dart_ListGetAsBytes(data_obj, start, buffer, chunk_length); |
| 309 if (Dart_IsError(err)) { |
| 284 delete[] buffer; | 310 delete[] buffer; |
| 285 Dart_ThrowException(DartEmbedder::NewInternalError( | 311 Dart_PropagateError(err); |
| 286 "Failed to get list bytes")); | |
| 287 } | 312 } |
| 288 } | 313 } |
| 289 // Process will take ownership of buffer, if successful. | 314 // Process will take ownership of buffer, if successful. |
| 290 if (!filter->Process(buffer, chunk_length)) { | 315 if (!filter->Process(buffer, chunk_length)) { |
| 291 delete[] buffer; | 316 delete[] buffer; |
| 292 EndFilter(filter_obj, filter); | |
| 293 Dart_ThrowException(DartEmbedder::NewInternalError( | 317 Dart_ThrowException(DartEmbedder::NewInternalError( |
| 294 "Call to Process while still processing data")); | 318 "Call to Process while still processing data")); |
| 295 } | 319 } |
| 296 } | 320 } |
| 297 | 321 |
| 298 void Filter_Processed(Dart_NativeArguments args) { | 322 void Filter_Processed(Dart_NativeArguments args) { |
| 299 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 323 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 300 Filter* filter = GetFilter(filter_obj); | 324 bool flush = DartEmbedder::GetBooleanArgument(args, 1); |
| 301 Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1); | 325 bool end = DartEmbedder::GetBooleanArgument(args, 2); |
| 302 bool flush; | 326 |
| 303 if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) { | 327 Filter* filter = NULL; |
| 304 Dart_ThrowException(DartEmbedder::NewInternalError( | 328 Dart_Handle err = GetFilter(filter_obj, &filter); |
| 305 "Failed to get 'flush' parameter")); | 329 if (Dart_IsError(err)) { |
| 330 Dart_PropagateError(err); |
| 306 } | 331 } |
| 307 Dart_Handle end_obj = Dart_GetNativeArgument(args, 2); | 332 |
| 308 bool end; | |
| 309 if (Dart_IsError(Dart_BooleanValue(end_obj, &end))) { | |
| 310 Dart_ThrowException(DartEmbedder::NewInternalError( | |
| 311 "Failed to get 'end' parameter")); | |
| 312 } | |
| 313 intptr_t read = filter->Processed(filter->processed_buffer(), | 333 intptr_t read = filter->Processed(filter->processed_buffer(), |
| 314 filter->processed_buffer_size(), | 334 filter->processed_buffer_size(), |
| 315 flush, | 335 flush, |
| 316 end); | 336 end); |
| 317 if (read < 0) { | 337 if (read < 0) { |
| 318 // Error, end filter. | |
| 319 EndFilter(filter_obj, filter); | |
| 320 Dart_ThrowException(DartEmbedder::NewInternalError( | 338 Dart_ThrowException(DartEmbedder::NewInternalError( |
| 321 "Filter error, bad data")); | 339 "Filter error, bad data")); |
| 322 } else if (read == 0) { | 340 } else if (read == 0) { |
| 323 Dart_SetReturnValue(args, Dart_Null()); | 341 Dart_SetReturnValue(args, Dart_Null()); |
| 324 } else { | 342 } else { |
| 325 uint8_t* io_buffer; | 343 uint8_t* io_buffer; |
| 326 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer); | 344 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer); |
| 327 memmove(io_buffer, filter->processed_buffer(), read); | 345 memmove(io_buffer, filter->processed_buffer(), read); |
| 328 Dart_SetReturnValue(args, result); | 346 Dart_SetReturnValue(args, result); |
| 329 } | 347 } |
| 330 } | 348 } |
| 331 | 349 |
| 332 void Filter_End(Dart_NativeArguments args) { | |
| 333 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | |
| 334 Filter* filter = GetFilter(filter_obj); | |
| 335 EndFilter(filter_obj, filter); | |
| 336 } | |
| 337 | |
| 338 void InternetAddress_Parse(Dart_NativeArguments arguments) { | 350 void InternetAddress_Parse(Dart_NativeArguments arguments) { |
| 339 const char* address = DartEmbedder::GetStringArgument(arguments, 0); | 351 const char* address = DartEmbedder::GetStringArgument(arguments, 0); |
| 340 CHECK(address != nullptr); | 352 CHECK(address != nullptr); |
| 341 RawAddr raw; | 353 RawAddr raw; |
| 342 int type = strchr(address, ':') == nullptr ? InternetAddress::TYPE_IPV4 | 354 int type = strchr(address, ':') == nullptr ? InternetAddress::TYPE_IPV4 |
| 343 : InternetAddress::TYPE_IPV6; | 355 : InternetAddress::TYPE_IPV6; |
| 344 intptr_t length = (type == InternetAddress::TYPE_IPV4) ? | 356 intptr_t length = (type == InternetAddress::TYPE_IPV4) ? |
| 345 IPV4_RAW_ADDR_LENGTH : IPV6_RAW_ADDR_LENGTH; | 357 IPV4_RAW_ADDR_LENGTH : IPV6_RAW_ADDR_LENGTH; |
| 346 if (InternetAddress::Parse(type, address, &raw)) { | 358 if (InternetAddress::Parse(type, address, &raw)) { |
| 347 Dart_SetReturnValue(arguments, | 359 Dart_SetReturnValue(arguments, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 void Process_Pid(Dart_NativeArguments arguments) { | 452 void Process_Pid(Dart_NativeArguments arguments) { |
| 441 // TODO(rudominer) After sandboxing is implemented getpid() will not return | 453 // TODO(rudominer) After sandboxing is implemented getpid() will not return |
| 442 // the real pid. Most likely it will return the value 1. We need to decide | 454 // the real pid. Most likely it will return the value 1. We need to decide |
| 443 // what behavior we want Dart's pid getter to have when sandboxed. | 455 // what behavior we want Dart's pid getter to have when sandboxed. |
| 444 pid_t pid = getpid(); | 456 pid_t pid = getpid(); |
| 445 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(pid)); | 457 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(pid)); |
| 446 } | 458 } |
| 447 | 459 |
| 448 } // namespace dart | 460 } // namespace dart |
| 449 } // namespace mojo | 461 } // namespace mojo |
| OLD | NEW |