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