| 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/builtin.h" | 5 #include "bin/builtin.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| 11 #include "include/dart_api.h" | 11 #include "include/dart_api.h" |
| 12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
| 13 | 13 |
| 14 | 14 |
| 15 // List all native functions implemented in standalone dart that is used | 15 // Lists the native functions implementing basic functionality in |
| 16 // to inject additional functionality e.g: Logger, file I/O, socket I/O etc. | 16 // standalone dart, such as printing, file I/O, and platform information. |
| 17 // Advanced I/O classes like sockets and process management are implemented |
| 18 // using functions listed in io_natives.cc. |
| 17 #define BUILTIN_NATIVE_LIST(V) \ | 19 #define BUILTIN_NATIVE_LIST(V) \ |
| 18 V(Common_IsBuiltinList, 1) \ | |
| 19 V(Crypto_GetRandomBytes, 1) \ | |
| 20 V(Directory_Exists, 1) \ | 20 V(Directory_Exists, 1) \ |
| 21 V(Directory_Create, 1) \ | 21 V(Directory_Create, 1) \ |
| 22 V(Directory_Current, 0) \ | 22 V(Directory_Current, 0) \ |
| 23 V(Directory_CreateTemp, 1) \ | 23 V(Directory_CreateTemp, 1) \ |
| 24 V(Directory_Delete, 2) \ | 24 V(Directory_Delete, 2) \ |
| 25 V(Directory_Rename, 2) \ | 25 V(Directory_Rename, 2) \ |
| 26 V(Directory_NewServicePort, 0) \ | 26 V(Directory_NewServicePort, 0) \ |
| 27 V(EventHandler_Start, 1) \ | |
| 28 V(EventHandler_SendData, 4) \ | |
| 29 V(Exit, 1) \ | 27 V(Exit, 1) \ |
| 30 V(File_Open, 2) \ | 28 V(File_Open, 2) \ |
| 31 V(File_Exists, 1) \ | 29 V(File_Exists, 1) \ |
| 32 V(File_Close, 1) \ | 30 V(File_Close, 1) \ |
| 33 V(File_ReadByte, 1) \ | 31 V(File_ReadByte, 1) \ |
| 34 V(File_WriteByte, 2) \ | 32 V(File_WriteByte, 2) \ |
| 35 V(File_ReadList, 4) \ | 33 V(File_ReadList, 4) \ |
| 36 V(File_WriteList, 4) \ | 34 V(File_WriteList, 4) \ |
| 37 V(File_Position, 1) \ | 35 V(File_Position, 1) \ |
| 38 V(File_SetPosition, 2) \ | 36 V(File_SetPosition, 2) \ |
| 39 V(File_Truncate, 2) \ | 37 V(File_Truncate, 2) \ |
| 40 V(File_Length, 1) \ | 38 V(File_Length, 1) \ |
| 41 V(File_LengthFromName, 1) \ | 39 V(File_LengthFromName, 1) \ |
| 42 V(File_LastModified, 1) \ | 40 V(File_LastModified, 1) \ |
| 43 V(File_Flush, 1) \ | 41 V(File_Flush, 1) \ |
| 44 V(File_Create, 1) \ | 42 V(File_Create, 1) \ |
| 45 V(File_Delete, 1) \ | 43 V(File_Delete, 1) \ |
| 46 V(File_Directory, 1) \ | 44 V(File_Directory, 1) \ |
| 47 V(File_FullPath, 1) \ | 45 V(File_FullPath, 1) \ |
| 48 V(File_OpenStdio, 1) \ | 46 V(File_OpenStdio, 1) \ |
| 49 V(File_GetStdioHandleType, 1) \ | 47 V(File_GetStdioHandleType, 1) \ |
| 50 V(File_NewServicePort, 0) \ | 48 V(File_NewServicePort, 0) \ |
| 51 V(Logger_PrintString, 1) \ | 49 V(Logger_PrintString, 1) \ |
| 52 V(Platform_NumberOfProcessors, 0) \ | 50 V(Platform_NumberOfProcessors, 0) \ |
| 53 V(Platform_OperatingSystem, 0) \ | 51 V(Platform_OperatingSystem, 0) \ |
| 54 V(Platform_PathSeparator, 0) \ | 52 V(Platform_PathSeparator, 0) \ |
| 55 V(Platform_LocalHostname, 0) \ | 53 V(Platform_LocalHostname, 0) \ |
| 56 V(Platform_Environment, 0) \ | 54 V(Platform_Environment, 0) |
| 57 V(Process_Start, 10) \ | |
| 58 V(Process_Kill, 3) \ | |
| 59 V(ServerSocket_CreateBindListen, 4) \ | |
| 60 V(ServerSocket_Accept, 2) \ | |
| 61 V(Socket_CreateConnect, 3) \ | |
| 62 V(Socket_Available, 1) \ | |
| 63 V(Socket_Read, 2) \ | |
| 64 V(Socket_ReadList, 4) \ | |
| 65 V(Socket_WriteList, 4) \ | |
| 66 V(Socket_GetPort, 1) \ | |
| 67 V(Socket_GetRemotePeer, 1) \ | |
| 68 V(Socket_GetError, 1) \ | |
| 69 V(Socket_GetStdioHandle, 2) \ | |
| 70 V(Socket_NewServicePort, 0) | |
| 71 | 55 |
| 72 | 56 |
| 73 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); | 57 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); |
| 74 | 58 |
| 75 static struct NativeEntries { | 59 static struct NativeEntries { |
| 76 const char* name_; | 60 const char* name_; |
| 77 Dart_NativeFunction function_; | 61 Dart_NativeFunction function_; |
| 78 int argument_count_; | 62 int argument_count_; |
| 79 } BuiltinEntries[] = { | 63 } BuiltinEntries[] = { |
| 80 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) | 64 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) |
| 81 }; | 65 }; |
| 82 | 66 |
| 83 | 67 |
| 84 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, | 68 Dart_NativeFunction Builtin::BuiltinNativeLookup(Dart_Handle name, |
| 85 int argument_count) { | 69 int argument_count) { |
| 86 const char* function_name = NULL; | 70 const char* function_name = NULL; |
| 87 Dart_Handle result = Dart_StringToCString(name, &function_name); | 71 Dart_Handle result = Dart_StringToCString(name, &function_name); |
| 88 DART_CHECK_VALID(result); | 72 DART_CHECK_VALID(result); |
| 89 ASSERT(function_name != NULL); | 73 ASSERT(function_name != NULL); |
| 90 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); | 74 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); |
| 91 for (int i = 0; i < num_entries; i++) { | 75 for (int i = 0; i < num_entries; i++) { |
| 92 struct NativeEntries* entry = &(BuiltinEntries[i]); | 76 struct NativeEntries* entry = &(BuiltinEntries[i]); |
| 93 if (!strcmp(function_name, entry->name_) && | 77 if (!strcmp(function_name, entry->name_) && |
| 94 (entry->argument_count_ == argument_count)) { | 78 (entry->argument_count_ == argument_count)) { |
| 95 return reinterpret_cast<Dart_NativeFunction>(entry->function_); | 79 return reinterpret_cast<Dart_NativeFunction>(entry->function_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 112 |
| 129 | 113 |
| 130 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { | 114 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { |
| 131 Dart_EnterScope(); | 115 Dart_EnterScope(); |
| 132 int64_t status = 0; | 116 int64_t status = 0; |
| 133 // Ignore result if passing invalid argument and just exit 0. | 117 // Ignore result if passing invalid argument and just exit 0. |
| 134 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 118 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 135 Dart_ExitScope(); | 119 Dart_ExitScope(); |
| 136 exit(status); | 120 exit(status); |
| 137 } | 121 } |
| OLD | NEW |