Chromium Code Reviews| 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 #ifndef INCLUDE_DART_API_H_ | 5 #ifndef INCLUDE_DART_API_H_ |
| 6 #define INCLUDE_DART_API_H_ | 6 #define INCLUDE_DART_API_H_ |
| 7 | 7 |
| 8 /** \mainpage Dart Embedding API Reference | |
| 9 * | |
| 10 * Dart is a class-based programming language for creating structured | |
| 11 * web applications. This reference describes the Dart embedding api, | |
| 12 * which is used to embed the Dart Virtual Machine within an | |
| 13 * application. | |
| 14 * | |
| 15 * This reference is generated from the header include/dart_api.h. | |
| 16 */ | |
| 17 | |
| 8 #ifdef __cplusplus | 18 #ifdef __cplusplus |
| 9 #define DART_EXTERN_C extern "C" | 19 #define DART_EXTERN_C extern "C" |
| 10 #else | 20 #else |
| 11 #define DART_EXTERN_C | 21 #define DART_EXTERN_C |
| 12 #endif | 22 #endif |
| 13 | 23 |
| 14 #if defined(__CYGWIN__) | 24 #if defined(__CYGWIN__) |
| 15 #error Tool chain and platform not supported. | 25 #error Tool chain and platform not supported. |
| 16 #elif defined(_WIN32) | 26 #elif defined(_WIN32) |
| 17 typedef signed __int8 int8_t; | 27 typedef signed __int8 int8_t; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 35 #else | 45 #else |
| 36 #define DART_EXPORT DART_EXTERN_C | 46 #define DART_EXPORT DART_EXTERN_C |
| 37 #endif | 47 #endif |
| 38 #else | 48 #else |
| 39 #error Tool chain not supported. | 49 #error Tool chain not supported. |
| 40 #endif | 50 #endif |
| 41 #endif | 51 #endif |
| 42 | 52 |
| 43 #include <assert.h> | 53 #include <assert.h> |
| 44 | 54 |
| 55 // --- Handles --- | |
| 56 | |
| 57 /** | |
| 58 * An object reference managed by the Dart VM garbage collector. | |
| 59 * | |
| 60 * Because the garbage collector may move objects, it is unsafe to | |
| 61 * refer to objects directly. Instead, we refer to objects through | |
| 62 * handles, which are known to the garbage collector and updates | |
|
Anton Muhin
2011/11/01 13:04:58
nit: wording is in plural, hence I think it should
turnidge
2011/11/01 17:47:36
Done.
| |
| 63 * automatically when the object is moved. Handles should be passed | |
| 64 * by value (except in cases like out-parameters) and should never be | |
| 65 * allocated on the heap. | |
| 66 * | |
| 67 * A handle may either be valid or invalid. Valid handles refer to a | |
| 68 * object in the Dart VM heap. Note that a valid handle may in some | |
| 69 * cases refer to null or an unhandled exception. Invalid handles are | |
| 70 * returned by many Dart api functions when they encounter an error. | |
| 71 * Invalid handles have an associated error message. | |
| 72 * | |
| 73 * Local handles are allocated within the current scope (see | |
| 74 * Dart_EnterScope) and go away when the current scope exits. Unless | |
| 75 * otherwise indicated, all functions in the Dart embedding api return | |
| 76 * local handles. | |
| 77 * | |
| 78 * Persistent handles are allocated within the current isolate. They | |
| 79 * can be used to store objects across scopes. Persistent handles | |
| 80 * need to be explicitly deallocated when they are no longer needed. | |
| 81 */ | |
| 82 typedef void* Dart_Handle; | |
| 83 | |
| 84 /** | |
| 85 * Is this handle valid? | |
| 86 * | |
| 87 * Requires there to be a current isolate. | |
| 88 */ | |
| 89 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle); | |
| 90 | |
| 91 /** | |
| 92 * Gets the error message from an invalid handle. | |
| 93 * | |
| 94 * Requires there to be a current isolate. | |
| 95 * | |
| 96 * \return A C string containing an error message if the handle is | |
| 97 * invalid. An empty C string ("") if the handle is valid. This C | |
| 98 * String is scope allocated and is only valid until the next call | |
| 99 * to Dart_ExitScope. | |
| 100 */ | |
| 101 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle); | |
| 102 | |
| 103 /** | |
| 104 * Produces an invalid handle with the provided error message. | |
|
Anton Muhin
2011/11/01 13:04:58
what about ownership in this case?
turnidge
2011/11/01 17:47:36
Added a comment.
| |
| 105 * | |
| 106 * Requires there to be a current isolate. | |
| 107 * | |
| 108 * \param error A C string containing an error message. | |
| 109 */ | |
| 110 DART_EXPORT Dart_Handle Dart_Error(const char* error); | |
| 111 // TODO(turnidge): Accept printf-style args here. | |
| 112 | |
| 113 /** | |
| 114 * Allocates a persistent handle for an object. | |
|
Anton Muhin
2011/11/01 13:04:58
AFAIK, it will fail currently if you attempt to pa
turnidge
2011/11/01 17:47:36
Good point. Added a TODO to fix this.
| |
| 115 * | |
| 116 * This handle has the lifetime of the current isolate unless it is | |
| 117 * explicitly deallocated by calling Dart_DeletePersistentHandle. | |
| 118 * | |
| 119 * Requires there to be a current isolate. | |
| 120 */ | |
| 121 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object); | |
| 122 | |
| 123 /** | |
| 124 * Deallocates a persistent handle. | |
| 125 * | |
| 126 * Requires there to be a current isolate. | |
| 127 */ | |
| 128 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object); | |
| 129 | |
| 130 /** | |
| 131 * Takes a persistent handle and makes it weak. | |
| 132 * | |
| 133 * UNIMPLEMENTED. | |
| 134 * | |
| 135 * Requires there to be a current isolate. | |
| 136 */ | |
| 137 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object); | |
| 138 // TODO(turnidge): Needs a "near death" callback here. | |
| 139 // TODO(turnidge): Add IsWeak, Clear, etc. | |
| 140 | |
| 141 /** | |
| 142 * Takes a weak persistent handle and makes it non-weak. | |
| 143 * | |
| 144 * UNIMPLEMENTED. | |
| 145 * | |
| 146 * Requires there to be a current isolate. | |
| 147 */ | |
| 148 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object); | |
| 149 | |
| 150 // --- Initialization and Globals --- | |
| 151 | |
| 152 /** | |
| 153 * An isolate initialization callback function. | |
| 154 * | |
| 155 * This callback, provided by the embedder, is called during isolate | |
| 156 * creation. It is called for all isolates, regardless of whether they | |
| 157 * are created via Dart_CreateIsolate or directly from Dart code. | |
| 158 * | |
| 159 * \param data Embedder-specific data used during isolate initialization. | |
| 160 * | |
| 161 * \return If the embedder returns NULL, then the isolate being | |
| 162 * initialized will be shut down without executing any Dart code. | |
| 163 * Otherwise, the embedder should return a pointer to | |
| 164 * embedder-specific data created during the initialization of this | |
| 165 * isolate. This data will, in turn, be passed by the VM to all | |
| 166 * isolates spawned from the isolate currently being initialized. | |
| 167 */ | |
| 168 typedef void* (*Dart_IsolateInitCallback)(void* embedder_data); | |
| 169 // TODO(iposva): Pass a specification of the app file being spawned. | |
| 170 // TODO(turnidge): We don't actually shut down the isolate on NULL yet. | |
| 171 // TODO(turnidge): Should we separate the two return values? | |
| 172 | |
| 173 /** | |
| 174 * Initializes the VM with the given commmand line flags. | |
| 175 * | |
| 176 * \param argc The length of the arguments array. | |
| 177 * \param argv An array of arguments. | |
| 178 * \param callback A function to be called during isolate creation. | |
| 179 * See Dart_IsolateInitCallback. | |
| 180 * | |
| 181 * \return True if initialization is successful. | |
| 182 */ | |
| 183 DART_EXPORT bool Dart_Initialize(int argc, char** argv, | |
| 184 Dart_IsolateInitCallback callback); | |
| 185 | |
| 186 /** | |
| 187 * Returns true if the named VM flag is set. | |
| 188 */ | |
| 189 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); | |
| 190 | |
| 191 // --- Isolates --- | |
| 192 | |
| 193 /** | |
| 194 * An isolate is the unit of concurrency in Dart. Each isolate has | |
| 195 * its own memory and thread of control. No state is shared between | |
| 196 * isolates. Instead, isolates communicate by message passing. | |
| 197 * | |
| 198 * There is a notion of a current isolate, which is the isolate which | |
|
Anton Muhin
2011/11/01 13:04:58
Not sure I can suggest better wording, but that so
turnidge
2011/11/01 17:47:36
Fidgeted with the wording a bit to make it feel st
| |
| 199 * is able to execute on the current thread. The current isolate may | |
| 200 * be NULL, in which case no isolate is ready to execute. Most of the | |
| 201 * Dart apis require there to be a current isolate in order to | |
| 202 * function properly. | |
| 203 */ | |
| 45 typedef void* Dart_Isolate; | 204 typedef void* Dart_Isolate; |
| 46 typedef void* Dart_Handle; | 205 |
| 206 /** | |
| 207 * A buffer containing a snapshot of the Dart VM. A snapshot can be | |
| 208 * used to restore the VM quickly to a saved state and is useful for | |
| 209 * fast startup. | |
| 210 */ | |
| 211 typedef void Dart_Snapshot; | |
| 212 | |
| 213 /** | |
| 214 * Creates a new isolate. If snapshot data is provided, the isolate | |
| 215 * will be started using that snapshot data. The new isolate becomes | |
| 216 * the current isolate. | |
| 217 * | |
| 218 * Requires there to be no current isolate. | |
| 219 * | |
| 220 * \param snapshot A buffer containing a VM snapshot or NULL if no | |
| 221 * snapshot is provided. | |
| 222 * \param data Embedder-specific data. See Dart_IsolateInitCallback. | |
| 223 * | |
| 224 * \return The new isolate is returned. May be NULL if an error | |
| 225 * occurs duing isolate initialization. | |
| 226 */ | |
| 227 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const Dart_Snapshot* snapshot, | |
| 228 void* data); | |
| 229 // TODO(turnidge): Document behavior when there is already a current | |
| 230 // isolate. | |
| 231 | |
| 232 /** | |
| 233 * Shuts down the current isolate. After this call, the current | |
| 234 * isolate is NULL. | |
| 235 * | |
| 236 * Requires there to be a current isolate. | |
| 237 */ | |
| 238 DART_EXPORT void Dart_ShutdownIsolate(); | |
| 239 // TODO(turnidge): Document behavior when there is no current isolate. | |
| 240 | |
| 241 /** | |
| 242 * Returns the current isolate. Will return NULL if there is no | |
| 243 * current isolate. | |
| 244 */ | |
| 245 DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); | |
| 246 | |
| 247 /** | |
| 248 * Enters an isolate. After calling this function, | |
| 249 * the current isolate will be set to the provided isolate. | |
| 250 * | |
| 251 * Requires there to be no current isolate. | |
| 252 */ | |
| 253 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); | |
|
Anton Muhin
2011/11/01 13:04:58
what if I do Dart_EnterIsolate on different thread
turnidge
2011/11/01 17:47:36
I have added a TODO for this. I need to add some
| |
| 254 | |
| 255 /** | |
| 256 * Exits an isolate. After this call, Dart_CurrentIsolate will | |
| 257 * return NULL. | |
| 258 * | |
| 259 * Requires there to be a current isolate. | |
| 260 */ | |
| 261 DART_EXPORT void Dart_ExitIsolate(); | |
| 262 | |
| 263 /** | |
| 264 * Creates a snapshot of the state of the current isolate. | |
|
Anton Muhin
2011/11/01 13:04:58
Does that include the current script or only libs?
turnidge
2011/11/01 17:47:36
I don't know. Added TODO to figure it out.
| |
| 265 */ | |
| 266 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snaphot_buffer, | |
| 267 intptr_t* snapshot_size); | |
| 268 | |
| 269 // --- Messages and Ports --- | |
| 270 | |
| 271 /** | |
| 272 * Messages are used to communicate between isolates. | |
| 273 */ | |
| 274 typedef void* Dart_Message; | |
| 275 | |
| 276 /** | |
| 277 * A port is used to send or receive inter-isolate messages | |
| 278 */ | |
| 279 typedef int64_t Dart_Port; | |
| 280 | |
| 281 const Dart_Port kNoReplyPort = 0; | |
| 282 | |
| 283 /** | |
| 284 * A message posting callback. | |
| 285 * | |
| 286 * This callback allows the embedder to provide an alternate delivery | |
| 287 * mechanism for inter-isolate messages. It is the responsibility of | |
| 288 * the embedder to call Dart_HandleMessage to process the message. | |
| 289 * | |
| 290 * If there is no reply port, then the constant 'kNoReplyPort' is | |
| 291 * passed as the 'reply_port' parameter. | |
| 292 * | |
| 293 * The memory pointed to by 'message' has been allocated by malloc. It | |
| 294 * is the responsibility of the callback to ensure that free(message) | |
| 295 * is called once the message has been processed. | |
| 296 * | |
| 297 * The callback should return false if it runs into a problem | |
| 298 * processing this message. | |
| 299 */ | |
| 300 typedef bool (*Dart_PostMessageCallback)(Dart_Isolate dest_isolate, | |
| 301 Dart_Port dest_port, | |
| 302 Dart_Port reply_port, | |
| 303 Dart_Message message); | |
| 304 // TODO(turnidge): Add a Dart_ReleaseMessage to hide allocation details. | |
| 305 | |
| 306 const Dart_Port kCloseAllPorts = 0; | |
| 307 | |
| 308 /** | |
| 309 * A close port callback. | |
| 310 * | |
| 311 * This callback allows the embedder to receive notification when a | |
| 312 * port is closed. The constant 'kCloseAllPorts' is passed as the | |
| 313 * 'port' parameter when all active ports are being closed at once. | |
| 314 */ | |
| 315 typedef void (*Dart_ClosePortCallback)(Dart_Isolate isolate, | |
| 316 Dart_Port port); | |
| 317 | |
| 318 /** | |
| 319 * Allows embedders to provide an alternative mechanism for sending | |
| 320 * inter-isolate messages. This setting only applies to the current | |
| 321 * isolate. | |
| 322 * | |
| 323 * Most embedders will only call this function once, before isolate | |
| 324 * execution begins. If this function is called after isolate | |
| 325 * execution begins, the embedder is responsible for threading issues. | |
| 326 */ | |
| 327 DART_EXPORT void Dart_SetMessageCallbacks( | |
| 328 Dart_PostMessageCallback post_message_callback, | |
| 329 Dart_ClosePortCallback close_port_callback); | |
| 330 // TODO(turnidge): Consider moving this to isolate creation so that it | |
| 331 // is impossible to mess up. | |
| 332 | |
| 333 /** | |
| 334 * Handles a message on the current isolate. | |
| 335 * | |
| 336 * Note that this function does not free the memory associated with | |
| 337 * 'dart_message'. | |
| 338 */ | |
| 339 DART_EXPORT void Dart_HandleMessage(Dart_Port dest_port, | |
| 340 Dart_Port reply_port, | |
| 341 Dart_Message dart_message); | |
| 342 // TODO(turnidge): Revisit memory management of 'dart_message'. | |
| 343 | |
| 344 /** | |
| 345 * Processes any incoming messages for the current isolate. | |
| 346 * | |
| 347 * This function may only be used when the embedder has not provided | |
| 348 * an alternate message delivery mechanism with | |
| 349 * Dart_SetMessageCallbacks. It is provided for convenience. | |
| 350 * | |
| 351 * This function waits for incoming messages for the current | |
| 352 * isolate. As new messages arrive, they are handled using | |
| 353 * Dart_HandleMessage. The routine exits when all ports to the | |
| 354 * current isolate are closed. | |
| 355 */ | |
| 356 DART_EXPORT Dart_Handle Dart_RunLoop(); | |
| 357 // TODO(turnidge): Should this be removed from the public api? | |
| 358 | |
| 359 /** | |
| 360 * Posts a message for some isolate. The message is built from a raw | |
| 361 * array. | |
| 362 * | |
| 363 * \param port The destination port. | |
| 364 * \param length The length of the data array. | |
| 365 * \param data A data array to be sent in the message. | |
| 366 * | |
| 367 * \return True if the message was posted. | |
| 368 */ | |
| 369 DART_EXPORT bool Dart_PostIntArray(Dart_Port port, | |
| 370 intptr_t length, | |
| 371 intptr_t* data); | |
| 372 // TODO(turnidge): Should this be intptr_t or some fixed length type? | |
| 373 // TODO(turnidge): Reverse length/data for consistency. | |
| 374 | |
| 375 /** | |
| 376 * Posts a message for some isolate. The message is a serialized | |
| 377 * object. | |
| 378 * | |
| 379 * Requires there to be a current isolate. | |
| 380 * | |
| 381 * \param port The destination port. | |
| 382 * \param object An object from the current isolate. | |
| 383 * | |
| 384 * \return True if the message was posted. | |
| 385 */ | |
| 386 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle object); | |
| 387 | |
| 388 // --- Scopes ---- | |
| 389 | |
| 390 /** | |
| 391 * Enters a new scope. | |
| 392 * | |
| 393 * All new local handles will be created in this scope. Additionally, | |
| 394 * some functions may return "scope allocated" memory which is only | |
| 395 * valid within this scope. | |
| 396 * | |
| 397 * Requires there to be a current isolate. | |
| 398 */ | |
| 399 DART_EXPORT void Dart_EnterScope(); | |
| 400 | |
| 401 /** | |
| 402 * Exits a scope. | |
| 403 * | |
| 404 * The previous scope (if any) becomes the current scope. | |
| 405 * | |
| 406 * Requires there to be a current isolate. | |
| 407 */ | |
| 408 DART_EXPORT void Dart_ExitScope(); | |
| 409 | |
| 410 // --- Objects ---- | |
| 411 | |
| 412 /** | |
| 413 * Is this object null? | |
| 414 */ | |
| 415 DART_EXPORT bool Dart_IsNull(Dart_Handle object); | |
| 416 | |
| 417 /** | |
| 418 * Converts an object to a string. | |
| 419 * | |
| 420 * If an exception occurs during the conversion, this is treated as an | |
| 421 * error. | |
| 422 * | |
| 423 * \return A handle to the converted string if no errors occur during | |
| 424 * the conversion. If an error does occur, an invalid handle is | |
| 425 * returned. | |
| 426 */ | |
| 427 DART_EXPORT Dart_Handle Dart_ObjectToString(Dart_Handle object); | |
| 428 // TODO(turnidge): Consider shortening name to Dart_ToString. | |
| 429 | |
| 430 /** | |
| 431 * Returns true if the two objects are equal. | |
| 432 * | |
| 433 * The result of the comparison is returned through the 'equal' | |
| 434 * parameter. The return value itself is used to indicate success or | |
| 435 * failure, not equality. | |
| 436 * | |
| 437 * \param obj1 An object to be compared. | |
| 438 * \param obj2 An object to be compared. | |
| 439 * \param equal Returns the result of the equality comparison. | |
| 440 * | |
| 441 * \return A valid handle if no error occurs during the comparison. | |
| 442 */ | |
| 443 DART_EXPORT Dart_Handle Dart_Objects_Equal(Dart_Handle obj1, | |
| 444 Dart_Handle obj2, | |
| 445 bool* equal); | |
| 446 // TODO(turnidge): Consider renaming for consistency. Maybe just | |
| 447 // Dart_Equals. | |
| 448 // TODO(turnidge): Need to add identity equality function. | |
| 449 | |
| 450 /** | |
| 451 * Is this object an instance of some type? | |
| 452 * | |
| 453 * The result of the test is returned through the 'instanceif' parameter. | |
| 454 * The return value itself is used to indicate success or failure. | |
| 455 * | |
| 456 * \param object An object. | |
| 457 * \param type A type. | |
| 458 * \param instanceof Return true if 'object' is an instance of type 'type'. | |
| 459 * | |
| 460 * \return A valid handle if no error occurs during the operation. | |
| 461 */ | |
| 462 DART_EXPORT Dart_Handle Dart_IsInstanceOf(Dart_Handle object, | |
| 463 Dart_Handle type, | |
| 464 bool* instanceof); | |
| 465 | |
| 466 // --- Numbers ---- | |
| 467 | |
| 468 /** | |
| 469 * Is this object a Number? | |
| 470 */ | |
| 471 DART_EXPORT bool Dart_IsNumber(Dart_Handle object); | |
| 472 | |
| 473 // --- Integers ---- | |
| 474 | |
| 475 /** | |
| 476 * Is this object an Integer? | |
| 477 */ | |
| 478 DART_EXPORT bool Dart_IsInteger(Dart_Handle object); | |
| 479 | |
| 480 /** | |
| 481 * Does this Integer fit into a 64-bit signed integer? | |
| 482 * | |
| 483 * \param integer An integer. | |
| 484 * \param fits Returns true if the integer fits into a 64-bit signed integer. | |
| 485 * | |
| 486 * \return A valid handle if no error occurs during the operation. | |
| 487 */ | |
| 488 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | |
| 489 bool* fits); | |
| 490 | |
| 491 /** | |
| 492 * Returns an Integer with the provided value. | |
| 493 * | |
| 494 * \param value The value of the integer. | |
| 495 * | |
| 496 * \return The Integer object if no errors occurs. Otherwise returns | |
| 497 * an invalid handle. | |
| 498 */ | |
| 499 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value); | |
| 500 | |
| 501 /** | |
| 502 * Returns an Integer with the provided value.. | |
|
Anton Muhin
2011/11/01 13:04:58
nit: double trailing ..
turnidge
2011/11/01 17:47:36
Fixed.
| |
| 503 * | |
| 504 * \param value The value of the integer represented as a C string | |
| 505 * containing a hexadecimal number. | |
| 506 * | |
| 507 * \return The Integer object if no errors occurs. Otherwise returns | |
| 508 * an invalid handle. | |
| 509 */ | |
| 510 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* value); | |
| 511 | |
| 512 /** | |
| 513 * Gets the value of an Integer. | |
| 514 * | |
| 515 * The integer must fit into a 64-bit signed integer, otherwise an error occurs. | |
| 516 * | |
| 517 * \param integer An Integer. | |
| 518 * \param value Returns the value of the Integer. | |
| 519 * | |
| 520 * \return A valid handle if no error occurs during the operation. | |
| 521 */ | |
| 522 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value); | |
| 523 | |
| 524 /** | |
| 525 * Gets the value of an integer as a hexadecimal C string. | |
| 526 * | |
| 527 * \param integer An Integer. | |
| 528 * \param value Returns the value of the Integer as a hexadecimal C | |
| 529 * string. This C string is scope allocated and is only valid until | |
| 530 * the next call to Dart_ExitScope. | |
| 531 * | |
| 532 * \return A valid handle if no error occurs during the operation. | |
| 533 */ | |
| 534 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, | |
| 535 const char** value); | |
| 536 | |
| 537 // --- Booleans ---- | |
| 538 | |
| 539 /** | |
| 540 * Is this object a Boolean? | |
| 541 */ | |
| 542 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object); | |
| 543 | |
| 544 /** | |
| 545 * Returns a Boolean with the provided value. | |
| 546 * | |
| 547 * \param value true or false. | |
| 548 * | |
| 549 * \return The Boolean object if no errors occurs. Otherwise returns | |
| 550 * an invalid handle. | |
| 551 */ | |
| 552 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value); | |
| 553 | |
| 554 /** | |
| 555 * Gets the value of a Boolean | |
| 556 * | |
| 557 * \param bool_object A Boolean | |
| 558 * \param value Returns the value of the Boolean. | |
| 559 * | |
| 560 * \return A valid handle if no error occurs during the operation. | |
| 561 */ | |
| 562 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, bool* value); | |
| 563 | |
| 564 // --- Doubles --- | |
| 565 | |
| 566 /** | |
| 567 * Is this object a Double? | |
| 568 */ | |
| 569 DART_EXPORT bool Dart_IsDouble(Dart_Handle object); | |
| 570 | |
| 571 /** | |
| 572 * Returns a Double with the provided value. | |
| 573 * | |
| 574 * \param value A double. | |
| 575 * | |
| 576 * \return The Double object if no errors occurs. Otherwise returns | |
| 577 * an invalid handle. | |
| 578 */ | |
| 579 DART_EXPORT Dart_Handle Dart_NewDouble(double value); | |
| 580 | |
| 581 /** | |
| 582 * Gets the value of a Double | |
| 583 * | |
| 584 * \param bool_object A Double | |
| 585 * \param value Returns the value of the Double. | |
| 586 * | |
| 587 * \return A valid handle if no error occurs during the operation. | |
| 588 */ | |
| 589 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle integer, double* result); | |
| 590 | |
| 591 // --- Strings --- | |
| 592 | |
| 593 /** | |
| 594 * Is this object a String? | |
| 595 */ | |
| 596 DART_EXPORT bool Dart_IsString(Dart_Handle object); | |
| 597 | |
| 598 /** | |
| 599 * Is this object a String whose codepoints all fit into 8 bits? | |
| 600 */ | |
| 601 DART_EXPORT bool Dart_IsString8(Dart_Handle object); | |
| 602 | |
| 603 /** | |
| 604 * Is this object a String whose codepoints all fit into 16 bits? | |
| 605 */ | |
| 606 DART_EXPORT bool Dart_IsString16(Dart_Handle object); | |
| 607 | |
| 608 /** | |
| 609 * Gets the length of a String. | |
| 610 * | |
| 611 * \param str A String. | |
| 612 * \param length Returns the length of the String. | |
| 613 * | |
| 614 * \return A valid handle if no error occurs during the operation. | |
| 615 */ | |
| 616 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); | |
| 617 | |
| 618 /** | |
| 619 * Returns a String built from the provided C string | |
| 620 * | |
| 621 * \param value A C String | |
| 622 * | |
| 623 * \return The String object if no errors occurs. Otherwise returns | |
| 624 * an invalid handle. | |
| 625 */ | |
| 626 DART_EXPORT Dart_Handle Dart_NewString(const char* str); | |
| 627 | |
| 628 /** | |
| 629 * Returns a String built from an array of 8-bit codepoints. | |
| 630 * | |
| 631 * \param value An array of 8-bit codepoints. | |
| 632 * \param length The length of the codepoints array. | |
| 633 * | |
| 634 * \return The String object if no errors occurs. Otherwise returns | |
| 635 * an invalid handle. | |
| 636 */ | |
| 637 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | |
| 638 intptr_t length); | |
| 639 | |
| 640 /** | |
| 641 * Returns a String built from an array of 16-bit codepoints. | |
| 642 * | |
| 643 * \param value An array of 16-bit codepoints. | |
| 644 * \param length The length of the codepoints array. | |
| 645 * | |
| 646 * \return The String object if no errors occurs. Otherwise returns | |
| 647 * an invalid handle. | |
| 648 */ | |
| 649 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | |
| 650 intptr_t length); | |
| 651 | |
| 652 /** | |
| 653 * Returns a String built from an array of 32-bit codepoints. | |
| 654 * | |
| 655 * \param value An array of 32-bit codepoints. | |
| 656 * \param length The length of the codepoints array. | |
| 657 * | |
| 658 * \return The String object if no errors occurs. Otherwise returns | |
| 659 * an invalid handle. | |
| 660 */ | |
| 661 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | |
| 662 intptr_t length); | |
| 663 | |
| 664 /** | |
| 665 * Gets the codepoints from a String. | |
| 666 * | |
| 667 * This function is only valid on strings for which Dart_IsString8 is | |
| 668 * true. Otherwise an error occurs. | |
| 669 * | |
| 670 * \param str A string. | |
| 671 * \param codepoints An array allocated by the caller, used to return | |
| 672 * the array of codepoints. | |
| 673 * \param length Used to pass in the length of the provided array. | |
| 674 * Used to return the length of the array which was actually used. | |
| 675 * | |
| 676 * \return A valid handle if no error occurs during the operation. | |
| 677 */ | |
| 678 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | |
| 679 uint8_t* codepoints, | |
| 680 intptr_t* length); | |
| 681 // TODO(turnidge): Rename to GetString8 to be consistent with the Is* | |
| 682 // and New* functions above? | |
| 683 | |
| 684 /** | |
| 685 * Gets the codepoints from a String. | |
| 686 * | |
| 687 * This function is only valid on strings for which Dart_IsString8 or | |
| 688 * Dart_IsString16 is true. Otherwise an error occurs. | |
| 689 * | |
| 690 * \param str A string. | |
| 691 * \param codepoints An array allocated by the caller, used to return | |
| 692 * the array of codepoints. | |
| 693 * \param length Used to pass in the length of the provided array. | |
| 694 * Used to return the length of the array which was actually used. | |
| 695 * | |
| 696 * \return A valid handle if no error occurs during the operation. | |
| 697 */ | |
| 698 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | |
| 699 uint16_t* codepoints, | |
| 700 intptr_t* length); | |
| 701 | |
| 702 /** | |
| 703 * Gets the codepoints from a String | |
| 704 * | |
| 705 * \param str A string. | |
| 706 * \param codepoints An array allocated by the caller, used to return | |
| 707 * the array of codepoints. | |
| 708 * \param length Used to pass in the length of the provided array. | |
| 709 * Used to return the length of the array which was actually used. | |
| 710 * | |
| 711 * \return A valid handle if no error occurs during the operation. | |
| 712 */ | |
| 713 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, | |
| 714 uint32_t* codepoints, | |
| 715 intptr_t* length); | |
| 716 | |
| 717 /** | |
| 718 * Gets the utf8 encoded representation of a String. | |
| 719 * | |
| 720 * \param str A string. | |
| 721 * \param utf8 Returns the String represented as a utf8 encoded C | |
| 722 * string. This C string is scope allocated and is only valid until | |
| 723 * the next call to Dart_ExitScope. | |
| 724 * | |
| 725 * \return A valid handle if no error occurs during the operation. | |
| 726 */ | |
| 727 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, | |
| 728 const char** utf8); | |
| 729 | |
| 730 // --- Arrays --- | |
| 731 | |
| 732 /** | |
| 733 * Is this object an Array? | |
| 734 */ | |
| 735 DART_EXPORT bool Dart_IsArray(Dart_Handle object); | |
| 736 // TODO(turnidge): Rename Array -> List. | |
| 737 | |
| 738 /** | |
| 739 * Returns an Array of the desired length. | |
| 740 * | |
| 741 * \param length The length of the array. | |
| 742 * | |
| 743 * \return The Array object if no errors occurs. Otherwise returns | |
| 744 * an invalid handle. | |
| 745 */ | |
| 746 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length); | |
| 747 // TODO(turnidge): Rename Array -> List. | |
| 748 | |
| 749 /** | |
| 750 * Gets the length of an Array. | |
| 751 * | |
| 752 * \param array An Array. | |
| 753 * \param length Returns the length of the Array. | |
| 754 * | |
| 755 * \return A valid handle if no error occurs during the operation. | |
| 756 */ | |
| 757 DART_EXPORT Dart_Handle Dart_GetLength(Dart_Handle array, intptr_t* length); | |
| 758 // TODO(turnidge): Rename Array -> List. | |
| 759 | |
| 760 /** | |
| 761 * Gets the Object at some index of an Array. | |
| 762 * | |
| 763 * If the index is out of bounds, an error occurs. | |
| 764 * | |
| 765 * \param array An Array. | |
| 766 * \param index A valid index into the Array. | |
| 767 * | |
| 768 * \return The Object in the Array at the specified index if no errors | |
| 769 * occurs. Otherwise returns an invalid handle. | |
| 770 */ | |
| 771 DART_EXPORT Dart_Handle Dart_ArrayGetAt(Dart_Handle array, | |
| 772 intptr_t index); | |
| 773 // TODO(turnidge): Rename Array -> List. | |
| 774 | |
| 775 /** | |
| 776 * Sets the Object at some index of an Array. | |
| 777 * | |
| 778 * If the index is out of bounds, an error occurs. | |
| 779 * | |
| 780 * \param array An Array. | |
| 781 * \param index A valid index into the Array. | |
| 782 * \param value The Object to put in the Array. | |
| 783 * | |
| 784 * \return A valid handle if no error occurs during the operation. | |
| 785 */ | |
| 786 DART_EXPORT Dart_Handle Dart_ArraySetAt(Dart_Handle array, | |
| 787 intptr_t index, | |
| 788 Dart_Handle value); | |
| 789 // TODO(turnidge): Rename Array -> List. | |
| 790 | |
| 791 // TODO(turnidge): Figure out what this is for. | |
| 792 DART_EXPORT Dart_Handle Dart_ArrayGet(Dart_Handle array, | |
| 793 intptr_t offset, | |
| 794 uint8_t* native_array, | |
| 795 intptr_t length); | |
| 796 | |
| 797 // TODO(turnidge): Figure out what this is for. | |
| 798 DART_EXPORT Dart_Handle Dart_ArraySet(Dart_Handle array, | |
| 799 intptr_t offset, | |
| 800 uint8_t* native_array, | |
| 801 intptr_t length); | |
| 802 | |
| 803 // --- Closures --- | |
| 804 | |
| 805 /** | |
| 806 * Is this object a Closure? | |
| 807 */ | |
| 808 DART_EXPORT bool Dart_IsClosure(Dart_Handle object); | |
| 809 | |
| 810 /** | |
| 811 * Invokes a Closure with the given arguments. | |
| 812 * | |
| 813 * \return If no error occurs during execution, then the result of | |
| 814 * invoking the closure is returned. Note that this may be an | |
| 815 * uncaught exception (see Dart_ExceptionOccurred) or the null | |
| 816 * Object. If an error occurred during execution, then an invalid | |
| 817 * handle is returned. | |
| 818 */ | |
| 819 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | |
| 820 int number_of_arguments, | |
| 821 Dart_Handle* arguments); | |
| 822 | |
| 823 // DEPRECATED: The API below is a temporary hack. | |
| 824 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object); | |
| 825 | |
| 826 // DEPRECATED: The API below is a temporary hack. | |
| 827 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value); | |
| 828 | |
| 829 // --- Methods and Fields --- | |
| 830 | |
| 831 /** | |
| 832 * Invokes a static method with the given arguments. | |
| 833 * | |
| 834 * \return If no error occurs during execution, then the result of | |
| 835 * invoking the closure is returned. Note that this may be an | |
| 836 * uncaught exception (see Dart_ExceptionOccurred) or the null | |
| 837 * Object. If an error occurred during execution, then an invalid | |
| 838 * handle is returned. | |
| 839 */ | |
| 840 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library, | |
| 841 Dart_Handle class_name, | |
| 842 Dart_Handle function_name, | |
| 843 int number_of_arguments, | |
| 844 Dart_Handle* arguments); | |
| 845 | |
| 846 /** | |
| 847 * Invokes an instance method with the given arguments. | |
| 848 * | |
| 849 * \return If no error occurs during execution, then the result of | |
| 850 * invoking the closure is returned. Note that this may be an | |
| 851 * uncaught exception (see Dart_ExceptionOccurred) or the null | |
| 852 * Object. If an error occurred during execution, then an invalid | |
| 853 * handle is returned. | |
| 854 */ | |
| 855 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle receiver, | |
| 856 Dart_Handle function_name, | |
| 857 int number_of_arguments, | |
| 858 Dart_Handle* arguments); | |
| 859 | |
| 860 /** | |
| 861 * Gets the value of a static field. | |
| 862 * | |
| 863 * \return If no error occurs, then the value of the field is | |
| 864 * returned. Otherwise an invalid handle is returned. | |
| 865 */ | |
| 866 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, Dart_Handle name); | |
| 867 | |
| 868 /** | |
| 869 * Sets the value of a static field. | |
| 870 * | |
| 871 * \return A valid handle if no error occurs. | |
| 872 */ | |
| 873 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | |
| 874 Dart_Handle name, | |
| 875 Dart_Handle value); | |
| 876 /** | |
| 877 * Gets the value of an instance field. | |
| 878 * | |
| 879 * \return If no error occurs, then the value of the field is | |
| 880 * returned. Otherwise an invalid handle is returned. | |
| 881 */ | |
| 882 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | |
| 883 Dart_Handle name); | |
| 884 /** | |
| 885 * Sets the value of an instance field. | |
| 886 * | |
| 887 * \return A valid handle if no error occurs. | |
| 888 */ | |
| 889 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | |
| 890 Dart_Handle name, | |
| 891 Dart_Handle value); | |
| 892 | |
| 893 /** | |
| 894 * Creates a native wrapper class. | |
| 895 * | |
| 896 * TODO(turnidge): Document. | |
| 897 */ | |
| 898 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | |
| 899 Dart_Handle class_name, | |
| 900 int field_count); | |
| 901 | |
| 902 /** | |
| 903 * Gets the value of a native field. | |
| 904 * | |
| 905 * TODO(turnidge): Document. | |
| 906 */ | |
| 907 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | |
| 908 int index, | |
| 909 intptr_t* value); | |
| 910 /** | |
| 911 * Sets the value of a native field. | |
| 912 * | |
| 913 * TODO(turnidge): Document. | |
| 914 */ | |
| 915 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | |
| 916 int index, | |
| 917 intptr_t value); | |
| 918 | |
| 919 // --- Exceptions ---- | |
| 920 | |
| 921 /** | |
| 922 * Does this handle hold information about an unhandled exception? | |
| 923 */ | |
| 924 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle handle); | |
| 925 // TODO(turnidge): Consider exposing the name of this thing. Maybe | |
| 926 // IsUnhandledException, IsUncaughtException, or IsThrownException. | |
| 927 // It is like a regular exception, but plus a stack trace. | |
| 928 // TODO(turnidge): Consider subsuming exception results into invalid | |
| 929 // handles so that only one error check needs to be done after method | |
| 930 // invocation. | |
| 931 | |
| 932 /** | |
| 933 * Gets the exception Object from an unhandled exception. | |
| 934 */ | |
| 935 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result); | |
| 936 | |
| 937 /** | |
| 938 * Gets the stack trace Object from an unhandled exception. | |
| 939 */ | |
| 940 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_exception); | |
| 941 | |
| 942 /** | |
| 943 * Throws an exception. | |
| 944 * | |
| 945 * Throws an exception, unwinding all dart frames on the stack. If | |
| 946 * successful, this function does not return. If there are no Dart | |
| 947 * frames on the stack, an error occurs. | |
| 948 * | |
| 949 * \return An invalid handle if the exception was not thrown. | |
| 950 * Otherwise the function does not return. | |
| 951 */ | |
| 952 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception); | |
| 953 | |
| 954 /** | |
| 955 * Rethrows an exception. | |
| 956 * | |
| 957 * Rethrows an exception, unwinding all dart frames on the stack. If | |
| 958 * successful, this function does not return. If there are no Dart | |
| 959 * frames on the stack, an error occurs. | |
| 960 * | |
| 961 * \return An invalid handle if the exception was not thrown. | |
| 962 * Otherwise the function does not return. | |
|
Anton Muhin
2011/11/01 13:04:58
you may want to emphasize that dtors of C++ object
turnidge
2011/11/01 17:47:36
Done.
| |
| 963 */ | |
| 964 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | |
| 965 Dart_Handle stacktrace); | |
| 966 // TODO(turnidge): ReThrow -> Rethrow. | |
| 967 | |
| 968 // --- Native functions --- | |
| 969 | |
| 970 /** | |
| 971 * The arguments to a native function. | |
| 972 * | |
| 973 * This object is passed to a native function to represent its | |
| 974 * arguments and return value. It allows access to the arguments to a | |
| 975 * native function by index. It also allows the return value of a | |
| 976 * native function to be set. | |
| 977 */ | |
| 47 typedef void* Dart_NativeArguments; | 978 typedef void* Dart_NativeArguments; |
| 48 | 979 |
| 980 /** | |
| 981 * Gets the native argument at some index. | |
| 982 */ | |
| 983 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | |
| 984 int index); | |
| 985 // TODO(turnidge): Specify the behavior of an out-of-bounds access. | |
| 986 | |
| 987 /** | |
| 988 * Gets the number of native arguments. | |
| 989 */ | |
| 990 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args); | |
| 991 | |
| 992 /** | |
| 993 * Sets the return value for a native function. | |
| 994 */ | |
| 995 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | |
| 996 Dart_Handle retval); | |
| 997 | |
| 998 /** | |
| 999 * A native function. | |
| 1000 */ | |
| 1001 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); | |
| 1002 | |
| 1003 /** | |
| 1004 * Native entry resolution callback. | |
| 1005 * | |
| 1006 * For libraries which have native functions, the embedder can provide | |
|
Anton Muhin
2011/11/01 13:04:58
nit: both libraries and scripts.
turnidge
2011/11/01 17:47:36
Thanks.
| |
| 1007 * a native entry resolver. This callback is used to map a name/arity | |
| 1008 * to a Dart_NativeFunction. If no function is found, the callback | |
| 1009 * should return NULL. | |
| 1010 * | |
| 1011 * See Dart_SetNativeResolver. | |
| 1012 */ | |
| 1013 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, | |
| 1014 int num_of_arguments); | |
| 1015 // TODO(turnidge): Consider renaming to NativeFunctionResolver or | |
| 1016 // NativeResolver. | |
| 1017 | |
| 1018 // --- Scripts and Libraries --- | |
| 1019 // TODO(turnidge): Finish documenting this section. | |
| 1020 | |
| 49 typedef enum { | 1021 typedef enum { |
| 50 kLibraryTag = 0, | 1022 kLibraryTag = 0, |
| 51 kImportTag, | 1023 kImportTag, |
| 52 kSourceTag, | 1024 kSourceTag, |
| 53 kCanonicalizeUrl, | 1025 kCanonicalizeUrl, |
| 54 } Dart_LibraryTag; | 1026 } Dart_LibraryTag; |
| 55 | 1027 |
| 56 typedef void Dart_Snapshot; | |
| 57 | |
| 58 typedef int64_t Dart_Port; | |
| 59 typedef void* Dart_Message; | |
| 60 | |
| 61 // Allow the embedder to intercept isolate creation. Both at startup | |
| 62 // and when spawning new isolates from Dart code. The result returned | |
| 63 // from this callback is handed to all isolates spawned from the | |
| 64 // isolate currently being initialized. | |
| 65 // | |
| 66 // Return NULL if an error is encountered. The isolate being | |
| 67 // initialized will be shutdown. No Dart code will execute before it | |
| 68 // is shutdown. | |
| 69 // | |
| 70 // TODO(iposva): Pass a specification of the app file being spawned. | |
| 71 typedef void* (*Dart_IsolateInitCallback)(void* data); | |
| 72 | |
| 73 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); | |
| 74 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, | |
| 75 int num_of_arguments); | |
| 76 typedef Dart_Handle (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, | 1028 typedef Dart_Handle (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, |
| 77 Dart_Handle library, | 1029 Dart_Handle library, |
| 78 Dart_Handle url); | 1030 Dart_Handle url); |
| 79 | 1031 |
| 80 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 1032 /** |
| 81 | 1033 * Loads the root script for the current isolate. |
| 82 // Return value handling after a Dart API call. | 1034 * |
| 83 DART_EXPORT bool Dart_IsValid(const Dart_Handle& result); | 1035 * TODO(turnidge): Document. |
| 84 | 1036 */ |
| 85 DART_EXPORT const char* Dart_GetError(const Dart_Handle& result); | 1037 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 86 DART_EXPORT Dart_Handle Dart_Error(const char* value); | 1038 Dart_Handle source, |
| 87 | 1039 Dart_LibraryTagHandler handler); |
| 88 | 1040 |
| 89 // Initialize the VM with commmand line flags. | 1041 /** |
| 90 DART_EXPORT bool Dart_Initialize(int argc, char** argv, | 1042 * Forces all loaded classes and functions to be compiled eagerly in |
| 91 Dart_IsolateInitCallback callback); | 1043 * the current isolate.. |
| 92 | 1044 * |
| 93 | 1045 * TODO(turnidge): Document. |
| 94 // Isolate handling. | 1046 */ |
| 95 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const Dart_Snapshot* snapshot, | 1047 DART_EXPORT Dart_Handle Dart_CompileAll(); |
| 96 void* data); | 1048 |
| 97 DART_EXPORT void Dart_ShutdownIsolate(); | 1049 /** |
| 98 | 1050 * Is this object a Library? |
| 99 DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); | 1051 */ |
| 100 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); | 1052 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object); |
| 101 DART_EXPORT void Dart_ExitIsolate(); | 1053 |
| 102 | 1054 /** |
| 103 // A convenience routine which processes any incoming messages for the | 1055 * Lookup a class by name from a Library. |
| 104 // current isolate. The routine exits when all ports to the current | 1056 * |
| 105 // isolate are closed. | 1057 * \return If no errors occur, the Library is returned. Otherwise an |
| 106 // | 1058 * invalid handle is returned. |
| 107 // This routine may only be used when the embedder has not provided an | 1059 */ |
| 108 // alternate message delivery mechanism with Dart_SetPostMessageCallback. | |
| 109 DART_EXPORT Dart_Handle Dart_RunLoop(); | |
| 110 | |
| 111 // Messages/ports | |
| 112 | |
| 113 // A post message callback allows the embedder to provide an alternate | |
| 114 // delivery mechanism for inter-isolate messages. It is the | |
| 115 // responsibility of the embedder to call Dart_HandleMessage to | |
| 116 // process the message. | |
| 117 // | |
| 118 // If there is no reply port, then the constant 'kNoReplyPort' is | |
| 119 // passed as the 'reply_port' parameter. | |
| 120 // | |
| 121 // The memory pointed to by 'message' has been allocated by malloc. It | |
| 122 // is the responsibility of the callback to ensure that free(message) | |
| 123 // is called once the message has been processed. | |
| 124 // | |
| 125 // The callback should return false if it runs into a problem | |
| 126 // processing this message. | |
| 127 // | |
| 128 // Todo(turnidge): Add a Dart_ReleaseMessage to hide allocation details? | |
| 129 typedef bool (*Dart_PostMessageCallback)(Dart_Isolate dest_isolate, | |
| 130 Dart_Port dest_port, | |
| 131 Dart_Port reply_port, | |
| 132 Dart_Message message); | |
| 133 const Dart_Port kNoReplyPort = 0; | |
| 134 | |
| 135 // A close port callback allows the embedder to receive notification | |
| 136 // when a port is closed. The constant 'kCloseAllPorts' is passed as | |
| 137 // the 'port' parameter when all active ports are being closed at | |
| 138 // once. | |
| 139 typedef void (*Dart_ClosePortCallback)(Dart_Isolate isolate, | |
| 140 Dart_Port port); | |
| 141 const Dart_Port kCloseAllPorts = 0; | |
| 142 | |
| 143 // Allows embedders to provide an alternative mechanism for sending | |
| 144 // inter-isolate messages. This setting only applies to the current | |
| 145 // isolate. | |
| 146 // | |
| 147 // Most embedders will only call this function once, before isolate | |
| 148 // execution begins. If this function is called after isolate | |
| 149 // execution begins, the embedder is responsible for threading issues. | |
| 150 // | |
| 151 // TODO(turnidge): Consider moving this to isolate creation so that it | |
| 152 // is impossible to mess up. | |
| 153 DART_EXPORT void Dart_SetMessageCallbacks( | |
| 154 Dart_PostMessageCallback post_message_callback, | |
| 155 Dart_ClosePortCallback close_port_callback); | |
| 156 | |
| 157 // Handle a message on the current isolate. | |
| 158 DART_EXPORT void Dart_HandleMessage(Dart_Port dest_port, | |
| 159 Dart_Port reply_port, | |
| 160 Dart_Message dart_message); | |
| 161 | |
| 162 | |
| 163 // Object. | |
| 164 DART_EXPORT Dart_Handle Dart_ObjectToString(Dart_Handle object); | |
| 165 DART_EXPORT bool Dart_IsNull(Dart_Handle object); | |
| 166 | |
| 167 | |
| 168 // Returns true if the two objects are equal. | |
| 169 DART_EXPORT Dart_Handle Dart_Objects_Equal(Dart_Handle obj1, | |
| 170 Dart_Handle obj2, | |
| 171 bool* value); | |
| 172 | |
| 173 | |
| 174 // Classes. | |
| 175 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name); | 1060 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name); |
| 176 DART_EXPORT Dart_Handle Dart_IsInstanceOf(Dart_Handle object, | 1061 |
| 177 Dart_Handle cls, | 1062 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); |
| 178 bool* value); | 1063 |
| 179 | |
| 180 | |
| 181 // Number. | |
| 182 DART_EXPORT bool Dart_IsNumber(Dart_Handle object); | |
| 183 | |
| 184 | |
| 185 // Integer. | |
| 186 DART_EXPORT bool Dart_IsInteger(Dart_Handle object); | |
| 187 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value); | |
| 188 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* value); | |
| 189 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value); | |
| 190 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, | |
| 191 const char** value); | |
| 192 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | |
| 193 bool* value); | |
| 194 | |
| 195 | |
| 196 // Boolean. | |
| 197 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object); | |
| 198 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value); | |
| 199 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, bool* value); | |
| 200 | |
| 201 | |
| 202 // Double. | |
| 203 DART_EXPORT bool Dart_IsDouble(Dart_Handle object); | |
| 204 DART_EXPORT Dart_Handle Dart_NewDouble(double value); | |
| 205 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle integer, double* result); | |
| 206 | |
| 207 | |
| 208 // String. | |
| 209 DART_EXPORT bool Dart_IsString(Dart_Handle object); | |
| 210 | |
| 211 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len); | |
| 212 | |
| 213 DART_EXPORT Dart_Handle Dart_NewString(const char* str); | |
| 214 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | |
| 215 intptr_t length); | |
| 216 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | |
| 217 intptr_t length); | |
| 218 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | |
| 219 intptr_t length); | |
| 220 | |
| 221 // The functions below test whether the object is a String and its codepoints | |
| 222 // all fit into 8 or 16 bits respectively. | |
| 223 DART_EXPORT bool Dart_IsString8(Dart_Handle object); | |
| 224 DART_EXPORT bool Dart_IsString16(Dart_Handle object); | |
| 225 | |
| 226 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | |
| 227 uint8_t* codepoints, | |
| 228 intptr_t* length); | |
| 229 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | |
| 230 uint16_t* codepoints, | |
| 231 intptr_t* length); | |
| 232 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, | |
| 233 uint32_t* codepoints, | |
| 234 intptr_t* length); | |
| 235 | |
| 236 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, | |
| 237 const char** result); | |
| 238 | |
| 239 | |
| 240 // Array. | |
| 241 DART_EXPORT bool Dart_IsArray(Dart_Handle object); | |
| 242 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length); | |
| 243 DART_EXPORT Dart_Handle Dart_GetLength(Dart_Handle array, intptr_t* len); | |
| 244 DART_EXPORT Dart_Handle Dart_ArrayGetAt(Dart_Handle array, | |
| 245 intptr_t index); | |
| 246 DART_EXPORT Dart_Handle Dart_ArrayGet(Dart_Handle array, | |
| 247 intptr_t offset, | |
| 248 uint8_t* native_array, | |
| 249 intptr_t length); | |
| 250 DART_EXPORT Dart_Handle Dart_ArraySetAt(Dart_Handle array, | |
| 251 intptr_t index, | |
| 252 Dart_Handle value); | |
| 253 DART_EXPORT Dart_Handle Dart_ArraySet(Dart_Handle array, | |
| 254 intptr_t offset, | |
| 255 uint8_t* native_array, | |
| 256 intptr_t length); | |
| 257 | |
| 258 // Closure. | |
| 259 DART_EXPORT bool Dart_IsClosure(Dart_Handle object); | |
| 260 // DEPRECATED: The API below is a temporary hack. | |
| 261 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object); | |
| 262 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value); | |
| 263 | |
| 264 | |
| 265 // Invocation of methods. | |
| 266 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library, | |
| 267 Dart_Handle class_name, | |
| 268 Dart_Handle function_name, | |
| 269 int number_of_arguments, | |
| 270 Dart_Handle* arguments); | |
| 271 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle receiver, | |
| 272 Dart_Handle function_name, | |
| 273 int number_of_arguments, | |
| 274 Dart_Handle* arguments); | |
| 275 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | |
| 276 int number_of_arguments, | |
| 277 Dart_Handle* arguments); | |
| 278 | |
| 279 | |
| 280 // Interaction with native methods. | |
| 281 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | |
| 282 int index); | |
| 283 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args); | |
| 284 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | |
| 285 Dart_Handle retval); | |
| 286 | |
| 287 // Library. | |
| 288 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object); | |
| 289 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); | 1064 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); |
| 290 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 1065 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
| 291 Dart_Handle import); | 1066 Dart_Handle import); |
| 292 | 1067 |
| 293 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); | |
| 294 | |
| 295 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 1068 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 296 Dart_Handle source); | 1069 Dart_Handle source); |
| 297 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 1070 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 298 Dart_Handle url, | 1071 Dart_Handle url, |
| 299 Dart_Handle source); | 1072 Dart_Handle source); |
| 1073 | |
| 1074 /** | |
| 1075 * Sets the callback used to resolve native functions for a library. | |
| 1076 * | |
| 1077 * \param library A library. | |
| 1078 * \param resolver A native entry resolver. | |
| 1079 * | |
| 1080 * \return A valid handle if the native resolver was set successfully. | |
| 1081 */ | |
| 300 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 1082 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
| 301 Dart_Handle library, | 1083 Dart_Handle library, |
| 302 Dart_NativeEntryResolver resolver); | 1084 Dart_NativeEntryResolver resolver); |
| 303 | 1085 |
| 304 | 1086 // --- Profiling support ---- |
| 305 // Script handling. | 1087 |
| 306 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 1088 // External pprof support for gathering and dumping symbolic |
| 307 Dart_Handle source, | 1089 // information that can be used for better profile reports for |
| 308 Dart_LibraryTagHandler handler); | 1090 // dynamically generated code. |
| 309 | |
| 310 // Compile all loaded classes and functions eagerly. | |
| 311 DART_EXPORT Dart_Handle Dart_CompileAll(); | |
| 312 | |
| 313 // Exception related. | |
| 314 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result); | |
| 315 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result); | |
| 316 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_exception); | |
| 317 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception); | |
| 318 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | |
| 319 Dart_Handle stacktrace); | |
| 320 | |
| 321 // Global Handles and Scope for local handles and zone based memory allocation. | |
| 322 DART_EXPORT void Dart_EnterScope(); | |
| 323 DART_EXPORT void Dart_ExitScope(); | |
| 324 | |
| 325 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object); | |
| 326 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object); | |
| 327 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object); | |
| 328 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object); | |
| 329 | |
| 330 // Fields. | |
| 331 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, Dart_Handle name); | |
| 332 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | |
| 333 Dart_Handle name, | |
| 334 Dart_Handle value); | |
| 335 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | |
| 336 Dart_Handle name); | |
| 337 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | |
| 338 Dart_Handle name, | |
| 339 Dart_Handle value); | |
| 340 | |
| 341 // Native fields. | |
| 342 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | |
| 343 Dart_Handle class_name, | |
| 344 int field_count); | |
| 345 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | |
| 346 int index, | |
| 347 intptr_t* value); | |
| 348 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | |
| 349 int index, | |
| 350 intptr_t value); | |
| 351 | |
| 352 // Snapshot creation. | |
| 353 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snaphot_buffer, | |
| 354 intptr_t* snapshot_size); | |
| 355 | |
| 356 // Message communication. | |
| 357 DART_EXPORT bool Dart_PostIntArray(Dart_Port port, | |
| 358 int field_count, | |
| 359 intptr_t* data); | |
| 360 | |
| 361 DART_EXPORT bool Dart_Post(Dart_Port port, Dart_Handle value); | |
| 362 | |
| 363 // External pprof support for gathering and dumping symbolic information | |
| 364 // that can be used for better profile reports for dynamically generated | |
| 365 // code. | |
| 366 DART_EXPORT void Dart_InitPprofSupport(); | 1091 DART_EXPORT void Dart_InitPprofSupport(); |
| 367 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); | 1092 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); |
| 368 | 1093 |
| 369 // Check set vm flags. | |
| 370 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); | |
| 371 | |
| 372 #endif // INCLUDE_DART_API_H_ | 1094 #endif // INCLUDE_DART_API_H_ |
| OLD | NEW |