Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #ifndef INCLUDE_DART_API_H_ | 7 #ifndef INCLUDE_DART_API_H_ |
| 8 #define INCLUDE_DART_API_H_ | 8 #define INCLUDE_DART_API_H_ |
| 9 | 9 |
| 10 /** \mainpage Dart Embedding API Reference | 10 /** \mainpage Dart Embedding API Reference |
| (...skipping 2137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2148 * native function by index. It also allows the return value of a | 2148 * native function by index. It also allows the return value of a |
| 2149 * native function to be set. | 2149 * native function to be set. |
| 2150 */ | 2150 */ |
| 2151 typedef struct _Dart_NativeArguments* Dart_NativeArguments; | 2151 typedef struct _Dart_NativeArguments* Dart_NativeArguments; |
| 2152 | 2152 |
| 2153 /** | 2153 /** |
| 2154 * Extracts current isolate data from the native arguments structure. | 2154 * Extracts current isolate data from the native arguments structure. |
| 2155 */ | 2155 */ |
| 2156 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args); | 2156 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args); |
| 2157 | 2157 |
| 2158 typedef enum { | |
| 2159 Dart_NativeArgument_kBool = 0, | |
| 2160 Dart_NativeArgument_kInt32, | |
| 2161 Dart_NativeArgument_kUint32, | |
| 2162 Dart_NativeArgument_kInt64, | |
| 2163 Dart_NativeArgument_kUint64, | |
| 2164 Dart_NativeArgument_kDouble, | |
| 2165 Dart_NativeArgument_kString, | |
| 2166 Dart_NativeArgument_kInstance, | |
| 2167 Dart_NativeArgument_kNativeFields, | |
| 2168 } Dart_NativeArgument_Type; | |
| 2169 | |
| 2170 typedef union _Dart_NativeArgument_Value { | |
| 2171 bool as_bool; | |
| 2172 int32_t as_int32; | |
| 2173 uint32_t as_uint32; | |
| 2174 int64_t as_int64; | |
| 2175 uint64_t as_uint64; | |
| 2176 double as_double; | |
| 2177 struct { | |
| 2178 Dart_Handle dart_str; | |
| 2179 void* peer; | |
| 2180 } as_string; | |
| 2181 struct { | |
| 2182 intptr_t num_fields; | |
| 2183 intptr_t* values; | |
| 2184 } as_native_fields; | |
| 2185 Dart_Handle as_instance; | |
| 2186 } Dart_NativeArgument_Value; | |
| 2187 | |
| 2188 enum { | |
| 2189 kNativeArgNumberPos = 0, | |
| 2190 kNativeArgNumberSize = 4, | |
|
Ivan Posva
2014/05/20 19:27:03
How about we make it a byte each?
siva
2014/05/21 23:56:54
Done.
| |
| 2191 kNativeArgTypePos = kNativeArgNumberPos + kNativeArgNumberSize, | |
| 2192 kNativeArgTypeSize = 4, | |
| 2193 }; | |
| 2194 | |
| 2195 #define BITMASK(size) ((1 << size) - 1) | |
| 2196 #define DART_NATIVE_ARG_DESCRIPTOR(type, position) \ | |
| 2197 (((type & BITMASK(kNativeArgTypeSize)) << kNativeArgTypePos) | \ | |
| 2198 (position & BITMASK(kNativeArgNumberSize))) | |
| 2199 | |
| 2200 /** | |
| 2201 * Gets the native arguments based on the types passed in and populates | |
| 2202 * the passed arguments buffer with appropriate native values. | |
| 2203 * | |
| 2204 * \param args the Native arguments block passed into the native call. | |
| 2205 * \param num_arguments length of argument descriptor array and argument | |
| 2206 * values array passed in. | |
| 2207 * \param arg_descriptors an array that describes the arguments that | |
| 2208 * need to be retrieved. For each argument to be retrieved the descriptor | |
| 2209 * contains the argument number (0, 1 etc.) and the argument type | |
| 2210 * described using Dart_NativeArgument_Type, e.g: | |
| 2211 * DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kBool, 1) indicates | |
| 2212 * that the first argument is to be retrieved and it should be a boolean. | |
| 2213 * \param arg_values array into which the native arguments need to be | |
| 2214 * extracted into, the array is allocated by the caller (it could be | |
| 2215 * stack allocated to avoid the malloc/free performance overhead). | |
| 2216 * | |
| 2217 * \return Success if all the arguments could be extracted correctly, | |
| 2218 * returns an error handle if there were any errors while extracting the | |
| 2219 * arguments (mismatched number of arguments, incorrect types, etc.). | |
| 2220 */ | |
| 2221 DART_EXPORT Dart_Handle Dart_GetNativeArguments( | |
| 2222 Dart_NativeArguments args, | |
| 2223 int num_arguments, | |
| 2224 const uint8_t* arg_descriptors, | |
| 2225 Dart_NativeArgument_Value* arg_values); | |
| 2226 | |
| 2227 | |
| 2158 /** | 2228 /** |
| 2159 * Gets the native argument at some index. | 2229 * Gets the native argument at some index. |
| 2160 */ | 2230 */ |
| 2161 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 2231 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 2162 int index); | 2232 int index); |
| 2163 /* TODO(turnidge): Specify the behavior of an out-of-bounds access. */ | 2233 /* TODO(turnidge): Specify the behavior of an out-of-bounds access. */ |
| 2164 | 2234 |
| 2165 /** | 2235 /** |
| 2166 * Gets the number of native arguments. | 2236 * Gets the number of native arguments. |
| 2167 */ | 2237 */ |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2639 * NOTE: If multiple callbacks with the same name are registered, only the | 2709 * NOTE: If multiple callbacks with the same name are registered, only the |
| 2640 * last callback registered will be remembered. | 2710 * last callback registered will be remembered. |
| 2641 */ | 2711 */ |
| 2642 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 2712 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 2643 const char* name, | 2713 const char* name, |
| 2644 Dart_ServiceRequestCallback callback, | 2714 Dart_ServiceRequestCallback callback, |
| 2645 void* user_data); | 2715 void* user_data); |
| 2646 | 2716 |
| 2647 | 2717 |
| 2648 #endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ | 2718 #endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ |
| OLD | NEW |