| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "bin/io_natives.h" |
| 6 |
| 7 #include <stdlib.h> |
| 8 #include <string.h> |
| 9 |
| 10 #include "bin/builtin.h" |
| 11 #include "bin/dartutils.h" |
| 12 #include "include/dart_api.h" |
| 13 #include "platform/assert.h" |
| 14 |
| 15 |
| 16 // Lists the native functions implementing advanced dart:io classes. |
| 17 // Some classes, like File and Directory, list their implementations in |
| 18 // builtin_natives.cc instead. |
| 19 #define IO_NATIVE_LIST(V) \ |
| 20 V(Common_IsBuiltinList, 1) \ |
| 21 V(Crypto_GetRandomBytes, 1) \ |
| 22 V(EventHandler_Start, 1) \ |
| 23 V(EventHandler_SendData, 4) \ |
| 24 V(Process_Start, 10) \ |
| 25 V(Process_Kill, 3) \ |
| 26 V(ServerSocket_CreateBindListen, 4) \ |
| 27 V(ServerSocket_Accept, 2) \ |
| 28 V(Socket_CreateConnect, 3) \ |
| 29 V(Socket_Available, 1) \ |
| 30 V(Socket_Read, 2) \ |
| 31 V(Socket_ReadList, 4) \ |
| 32 V(Socket_WriteList, 4) \ |
| 33 V(Socket_GetPort, 1) \ |
| 34 V(Socket_GetRemotePeer, 1) \ |
| 35 V(Socket_GetError, 1) \ |
| 36 V(Socket_GetStdioHandle, 2) \ |
| 37 V(Socket_NewServicePort, 0) |
| 38 |
| 39 |
| 40 IO_NATIVE_LIST(DECLARE_FUNCTION); |
| 41 |
| 42 static struct NativeEntries { |
| 43 const char* name_; |
| 44 Dart_NativeFunction function_; |
| 45 int argument_count_; |
| 46 } IOEntries[] = { |
| 47 IO_NATIVE_LIST(REGISTER_FUNCTION) |
| 48 }; |
| 49 |
| 50 |
| 51 Dart_NativeFunction IONativeLookup(Dart_Handle name, |
| 52 int argument_count) { |
| 53 const char* function_name = NULL; |
| 54 Dart_Handle result = Dart_StringToCString(name, &function_name); |
| 55 DART_CHECK_VALID(result); |
| 56 ASSERT(function_name != NULL); |
| 57 int num_entries = sizeof(IOEntries) / sizeof(struct NativeEntries); |
| 58 for (int i = 0; i < num_entries; i++) { |
| 59 struct NativeEntries* entry = &(IOEntries[i]); |
| 60 if (!strcmp(function_name, entry->name_) && |
| 61 (entry->argument_count_ == argument_count)) { |
| 62 return reinterpret_cast<Dart_NativeFunction>(entry->function_); |
| 63 } |
| 64 } |
| 65 return NULL; |
| 66 } |
| OLD | NEW |