OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #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 | 8 /** \mainpage Dart Embedding API Reference |
9 * | 9 * |
10 * Dart is a class-based programming language for creating structured | 10 * Dart is a class-based programming language for creating structured |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 * Dart_EnterScope) and go away when the current scope exits. Unless | 169 * Dart_EnterScope) and go away when the current scope exits. Unless |
170 * otherwise indicated, callers should assume that all functions in | 170 * otherwise indicated, callers should assume that all functions in |
171 * the Dart embedding api return local handles. | 171 * the Dart embedding api return local handles. |
172 * | 172 * |
173 * Persistent handles are allocated within the current isolate. They | 173 * Persistent handles are allocated within the current isolate. They |
174 * can be used to store objects across scopes. Persistent handles have | 174 * can be used to store objects across scopes. Persistent handles have |
175 * the lifetime of the current isolate unless they are explicitly | 175 * the lifetime of the current isolate unless they are explicitly |
176 * deallocated (see Dart_DeletePersistentHandle). | 176 * deallocated (see Dart_DeletePersistentHandle). |
177 */ | 177 */ |
178 typedef struct _Dart_Handle* Dart_Handle; | 178 typedef struct _Dart_Handle* Dart_Handle; |
| 179 typedef struct _Dart_PersistentHandle* Dart_PersistentHandle; |
| 180 typedef struct _Dart_WeakPersistentHandle* Dart_WeakPersistentHandle; |
179 | 181 |
180 typedef void (*Dart_WeakPersistentHandleFinalizer)(Dart_Handle handle, | 182 typedef void (*Dart_WeakPersistentHandleFinalizer)( |
181 void* peer); | 183 Dart_WeakPersistentHandle handle, |
| 184 void* peer); |
182 typedef void (*Dart_PeerFinalizer)(void* peer); | 185 typedef void (*Dart_PeerFinalizer)(void* peer); |
183 | 186 |
184 /** | 187 /** |
185 * Is this an error handle? | 188 * Is this an error handle? |
186 * | 189 * |
187 * Requires there to be a current isolate. | 190 * Requires there to be a current isolate. |
188 */ | 191 */ |
189 DART_EXPORT bool Dart_IsError(Dart_Handle handle); | 192 DART_EXPORT bool Dart_IsError(Dart_Handle handle); |
190 | 193 |
191 /** | 194 /** |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 * This is equivalent to using the triple-equals (===) operator. | 357 * This is equivalent to using the triple-equals (===) operator. |
355 * | 358 * |
356 * \param obj1 An object to be compared. | 359 * \param obj1 An object to be compared. |
357 * \param obj2 An object to be compared. | 360 * \param obj2 An object to be compared. |
358 * | 361 * |
359 * \return True if the objects are identically equal. False otherwise. | 362 * \return True if the objects are identically equal. False otherwise. |
360 */ | 363 */ |
361 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2); | 364 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2); |
362 | 365 |
363 /** | 366 /** |
| 367 * Allocates a handle in the current scope from a persistent handle. |
| 368 */ |
| 369 DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object); |
| 370 |
| 371 /** |
| 372 * Allocates a handle in the current scope from a weak persistent handle. |
| 373 */ |
| 374 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( |
| 375 Dart_WeakPersistentHandle object); |
| 376 |
| 377 /** |
364 * Allocates a persistent handle for an object. | 378 * Allocates a persistent handle for an object. |
365 * | 379 * |
366 * This handle has the lifetime of the current isolate unless it is | 380 * This handle has the lifetime of the current isolate unless it is |
367 * explicitly deallocated by calling Dart_DeletePersistentHandle. | 381 * explicitly deallocated by calling Dart_DeletePersistentHandle. |
368 * | 382 * |
369 * Requires there to be a current isolate. | 383 * Requires there to be a current isolate. |
370 */ | 384 */ |
371 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object); | 385 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object); |
372 | 386 |
373 /** | 387 /** |
374 * Deallocates a persistent handle. | 388 * Deallocates a persistent handle. |
375 * | 389 * |
376 * Requires there to be a current isolate. | 390 * Requires there to be a current isolate. |
377 */ | 391 */ |
378 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object); | 392 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object); |
379 | 393 |
380 /** | 394 /** |
381 * Allocates a weak persistent handle for an object. | 395 * Allocates a weak persistent handle for an object. |
382 * | 396 * |
383 * This handle has the lifetime of the current isolate unless it is | 397 * This handle has the lifetime of the current isolate unless it is |
384 * explicitly deallocated by calling Dart_DeletePersistentHandle. | 398 * explicitly deallocated by calling Dart_DeletePersistentHandle. |
385 * | 399 * |
386 * Requires there to be a current isolate. | 400 * Requires there to be a current isolate. |
387 * | 401 * |
388 * \param object An object. | 402 * \param object An object. |
389 * \param peer A pointer to a native object or NULL. This value is | 403 * \param peer A pointer to a native object or NULL. This value is |
390 * provided to callback when it is invoked. | 404 * provided to callback when it is invoked. |
391 * \param callback A function pointer that will be invoked sometime | 405 * \param callback A function pointer that will be invoked sometime |
392 * after the object is garbage collected. | 406 * after the object is garbage collected. |
393 * | 407 * |
394 * \return Success if the weak persistent handle was | 408 * \return Success if the weak persistent handle was |
395 * created. Otherwise, returns an error. | 409 * created. Otherwise, returns an error. |
396 */ | 410 */ |
397 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( | 411 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
398 Dart_Handle object, | 412 Dart_Handle object, |
399 void* peer, | 413 void* peer, |
400 Dart_WeakPersistentHandleFinalizer callback); | 414 Dart_WeakPersistentHandleFinalizer callback); |
401 | 415 |
402 /** | 416 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
403 * Is this object a weak persistent handle? | 417 Dart_WeakPersistentHandle object); |
404 * | |
405 * Requires there to be a current isolate. | |
406 */ | |
407 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object); | |
408 | 418 |
409 /** | 419 /** |
410 * Allocates a prologue weak persistent handle for an object. | 420 * Allocates a prologue weak persistent handle for an object. |
411 * | 421 * |
412 * Prologue weak persistent handles are similar to weak persistent | 422 * Prologue weak persistent handles are similar to weak persistent |
413 * handles but exhibit different behavior during garbage collections | 423 * handles but exhibit different behavior during garbage collections |
414 * that invoke the prologue and epilogue callbacks. While weak | 424 * that invoke the prologue and epilogue callbacks. While weak |
415 * persistent handles always weakly reference their referents, | 425 * persistent handles always weakly reference their referents, |
416 * prologue weak persistent handles weakly reference their referents | 426 * prologue weak persistent handles weakly reference their referents |
417 * only during a garbage collection that invokes the prologue and | 427 * only during a garbage collection that invokes the prologue and |
418 * epilogue callbacks. During all other garbage collections, prologue | 428 * epilogue callbacks. During all other garbage collections, prologue |
419 * weak persistent handles strongly reference their referents. | 429 * weak persistent handles strongly reference their referents. |
420 * | 430 * |
421 * This handle has the lifetime of the current isolate unless it is | 431 * This handle has the lifetime of the current isolate unless it is |
422 * explicitly deallocated by calling Dart_DeletePersistentHandle. | 432 * explicitly deallocated by calling Dart_DeletePersistentHandle. |
423 * | 433 * |
424 * Requires there to be a current isolate. | 434 * Requires there to be a current isolate. |
425 * | 435 * |
426 * \param object An object. | 436 * \param object An object. |
427 * \param peer A pointer to a native object or NULL. This value is | 437 * \param peer A pointer to a native object or NULL. This value is |
428 * provided to callback when it is invoked. | 438 * provided to callback when it is invoked. |
429 * \param callback A function pointer that will be invoked sometime | 439 * \param callback A function pointer that will be invoked sometime |
430 * after the object is garbage collected. | 440 * after the object is garbage collected. |
431 * | 441 * |
432 * \return Success if the prologue weak persistent handle was created. | 442 * \return Success if the prologue weak persistent handle was created. |
433 * Otherwise, returns an error. | 443 * Otherwise, returns an error. |
434 */ | 444 */ |
435 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( | 445 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
436 Dart_Handle object, | 446 Dart_Handle object, |
437 void* peer, | 447 void* peer, |
438 Dart_WeakPersistentHandleFinalizer callback); | 448 Dart_WeakPersistentHandleFinalizer callback); |
439 | 449 |
440 /** | 450 /** |
441 * Is this object a prologue weak persistent handle? | 451 * Is this object a prologue weak persistent handle? |
442 * | 452 * |
443 * Requires there to be a current isolate. | 453 * Requires there to be a current isolate. |
444 */ | 454 */ |
445 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object); | 455 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( |
| 456 Dart_WeakPersistentHandle object); |
446 | 457 |
447 /** | 458 /** |
448 * Constructs a set of weak references from the Cartesian product of | 459 * Constructs a set of weak references from the Cartesian product of |
449 * the objects in the key set and the objects in values set. | 460 * the objects in the key set and the objects in values set. |
450 * | 461 * |
451 * \param keys A set of object references. These references will be | 462 * \param keys A set of object references. These references will be |
452 * considered weak by the garbage collector. | 463 * considered weak by the garbage collector. |
453 * \param num_keys the number of objects in the keys set. | 464 * \param num_keys the number of objects in the keys set. |
454 * \param values A set of object references. These references will be | 465 * \param values A set of object references. These references will be |
455 * considered weak by garbage collector unless any object reference | 466 * considered weak by garbage collector unless any object reference |
456 * in 'keys' is found to be strong. | 467 * in 'keys' is found to be strong. |
457 * \param num_values the size of the values set | 468 * \param num_values the size of the values set |
458 * | 469 * |
459 * \return Success if the weak reference set could be created. | 470 * \return Success if the weak reference set could be created. |
460 * Otherwise, returns an error handle. | 471 * Otherwise, returns an error handle. |
461 */ | 472 */ |
462 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, | 473 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( |
463 intptr_t num_keys, | 474 Dart_WeakPersistentHandle* keys, |
464 Dart_Handle* values, | 475 intptr_t num_keys, |
465 intptr_t num_values); | 476 Dart_WeakPersistentHandle* values, |
| 477 intptr_t num_values); |
466 | 478 |
467 // --- Garbage Collection Callbacks --- | 479 // --- Garbage Collection Callbacks --- |
468 | 480 |
469 /** | 481 /** |
470 * Callbacks signal the beginning and end of a garbage collection. | 482 * Callbacks signal the beginning and end of a garbage collection. |
471 * | 483 * |
472 * These signals are intended to be used by the embedder to manage the | 484 * These signals are intended to be used by the embedder to manage the |
473 * lifetime of native objects with a managed object peer. | 485 * lifetime of native objects with a managed object peer. |
474 */ | 486 */ |
475 | 487 |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 * \param type The type of the data array. | 1771 * \param type The type of the data array. |
1760 * \param value A data array. This array must not move. | 1772 * \param value A data array. This array must not move. |
1761 * \param length The length of the data array (length in type units). | 1773 * \param length The length of the data array (length in type units). |
1762 * \param peer An external pointer to associate with this array. | 1774 * \param peer An external pointer to associate with this array. |
1763 * | 1775 * |
1764 * \return The TypedData object if no error occurs. Otherwise returns | 1776 * \return The TypedData object if no error occurs. Otherwise returns |
1765 * an error handle. The TypedData object is returned in a | 1777 * an error handle. The TypedData object is returned in a |
1766 * WeakPersistentHandle which needs to be deleted in the specified callback | 1778 * WeakPersistentHandle which needs to be deleted in the specified callback |
1767 * using Dart_DeletePersistentHandle. | 1779 * using Dart_DeletePersistentHandle. |
1768 */ | 1780 */ |
1769 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 1781 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, |
1770 Dart_TypedData_Type type, | 1782 void* data, |
1771 void* data, | 1783 intptr_t length); |
1772 intptr_t length, | |
1773 void* peer, | |
1774 Dart_WeakPersistentHandleFinalizer callback); | |
1775 | |
1776 /** | |
1777 * Retrieves the peer pointer associated with an external TypedData object. | |
1778 */ | |
1779 DART_EXPORT Dart_Handle Dart_ExternalTypedDataGetPeer(Dart_Handle object, | |
1780 void** peer); | |
1781 | 1784 |
1782 /** | 1785 /** |
1783 * Acquires access to the internal data address of a TypedData object. | 1786 * Acquires access to the internal data address of a TypedData object. |
1784 * | 1787 * |
1785 * \param object The typed data object whose internal data address is to | 1788 * \param object The typed data object whose internal data address is to |
1786 * be accessed. | 1789 * be accessed. |
1787 * \param type The type of the object is returned here. | 1790 * \param type The type of the object is returned here. |
1788 * \param data The internal data address is returned here. | 1791 * \param data The internal data address is returned here. |
1789 * \param len Size of the typed array is returned here. | 1792 * \param len Size of the typed array is returned here. |
1790 * | 1793 * |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 * | 2638 * |
2636 * \param object An object. | 2639 * \param object An object. |
2637 * \param peer A value to store in the peer field. | 2640 * \param peer A value to store in the peer field. |
2638 * | 2641 * |
2639 * \return Returns an error if 'object' is a subtype of Null, num, or | 2642 * \return Returns an error if 'object' is a subtype of Null, num, or |
2640 * bool. | 2643 * bool. |
2641 */ | 2644 */ |
2642 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); | 2645 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); |
2643 | 2646 |
2644 #endif // INCLUDE_DART_API_H_ | 2647 #endif // INCLUDE_DART_API_H_ |
OLD | NEW |