OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 /* |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 // BSD-style license that can be found in the LICENSE file. | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. |
| 5 */ |
4 | 6 |
5 #ifndef INCLUDE_DART_API_H_ | 7 #ifndef INCLUDE_DART_API_H_ |
6 #define INCLUDE_DART_API_H_ | 8 #define INCLUDE_DART_API_H_ |
7 | 9 |
8 /** \mainpage Dart Embedding API Reference | 10 /** \mainpage Dart Embedding API Reference |
9 * | 11 * |
10 * Dart is a class-based programming language for creating structured | 12 * Dart is a class-based programming language for creating structured |
11 * web applications. This reference describes the Dart embedding api, | 13 * web applications. This reference describes the Dart embedding api, |
12 * which is used to embed the Dart Virtual Machine within an | 14 * which is used to embed the Dart Virtual Machine within an |
13 * application. | 15 * application. |
(...skipping 17 matching lines...) Expand all Loading... |
31 typedef unsigned __int8 uint8_t; | 33 typedef unsigned __int8 uint8_t; |
32 typedef unsigned __int16 uint16_t; | 34 typedef unsigned __int16 uint16_t; |
33 typedef unsigned __int32 uint32_t; | 35 typedef unsigned __int32 uint32_t; |
34 typedef unsigned __int64 uint64_t; | 36 typedef unsigned __int64 uint64_t; |
35 #if defined(DART_SHARED_LIB) | 37 #if defined(DART_SHARED_LIB) |
36 #define DART_EXPORT DART_EXTERN_C __declspec(dllexport) | 38 #define DART_EXPORT DART_EXTERN_C __declspec(dllexport) |
37 #else | 39 #else |
38 #define DART_EXPORT DART_EXTERN_C | 40 #define DART_EXPORT DART_EXTERN_C |
39 #endif | 41 #endif |
40 #else | 42 #else |
41 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 43 /* __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
42 // enable platform independent printf format specifiers. | 44 * enable platform independent printf format specifiers. */ |
43 #ifndef __STDC_FORMAT_MACROS | 45 #ifndef __STDC_FORMAT_MACROS |
44 #define __STDC_FORMAT_MACROS | 46 #define __STDC_FORMAT_MACROS |
45 #endif | 47 #endif |
46 #include <inttypes.h> | 48 #include <inttypes.h> |
47 #include <stdbool.h> | 49 #include <stdbool.h> |
48 #if __GNUC__ >= 4 | 50 #if __GNUC__ >= 4 |
49 #if defined(DART_SHARED_LIB) | 51 #if defined(DART_SHARED_LIB) |
50 #define DART_EXPORT DART_EXTERN_C __attribute__ ((visibility("default"))) | 52 #define DART_EXPORT DART_EXTERN_C __attribute__ ((visibility("default"))) |
51 #else | 53 #else |
52 #define DART_EXPORT DART_EXTERN_C | 54 #define DART_EXPORT DART_EXTERN_C |
53 #endif | 55 #endif |
54 #else | 56 #else |
55 #error Tool chain not supported. | 57 #error Tool chain not supported. |
56 #endif | 58 #endif |
57 #endif | 59 #endif |
58 | 60 |
59 #include <assert.h> | 61 #include <assert.h> |
60 | 62 |
61 // --- Handles --- | 63 /* --- Handles --- */ |
62 | 64 |
63 /** | 65 /** |
64 * An object reference managed by the Dart VM garbage collector. | 66 * An object reference managed by the Dart VM garbage collector. |
65 * | 67 * |
66 * Because the garbage collector may move objects, it is unsafe to | 68 * Because the garbage collector may move objects, it is unsafe to |
67 * refer to objects directly. Instead, we refer to objects through | 69 * refer to objects directly. Instead, we refer to objects through |
68 * handles, which are known to the garbage collector and updated | 70 * handles, which are known to the garbage collector and updated |
69 * automatically when the object is moved. Handles should be passed | 71 * automatically when the object is moved. Handles should be passed |
70 * by value (except in cases like out-parameters) and should never be | 72 * by value (except in cases like out-parameters) and should never be |
71 * allocated on the heap. | 73 * allocated on the heap. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 278 |
277 /** | 279 /** |
278 * Produces a new unhandled exception error handle. | 280 * Produces a new unhandled exception error handle. |
279 * | 281 * |
280 * Requires there to be a current isolate. | 282 * Requires there to be a current isolate. |
281 * | 283 * |
282 * \param exception An instance of a Dart object to be thrown. | 284 * \param exception An instance of a Dart object to be thrown. |
283 */ | 285 */ |
284 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception); | 286 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception); |
285 | 287 |
286 // Deprecated. | 288 /* Deprecated. */ |
287 // TODO(turnidge): Remove all uses and delete. | 289 /* TODO(turnidge): Remove all uses and delete. */ |
288 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...); | 290 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...); |
289 | 291 |
290 /** | 292 /** |
291 * Propagates an error. | 293 * Propagates an error. |
292 * | 294 * |
293 * If the provided handle is an unhandled exception error, this | 295 * If the provided handle is an unhandled exception error, this |
294 * function will cause the unhandled exception to be rethrown. This | 296 * function will cause the unhandled exception to be rethrown. This |
295 * will proceeed in the standard way, walking up Dart frames until an | 297 * will proceeed in the standard way, walking up Dart frames until an |
296 * appropriate 'catch' block is found, executing 'finally' blocks, | 298 * appropriate 'catch' block is found, executing 'finally' blocks, |
297 * etc. | 299 * etc. |
298 * | 300 * |
299 * If the error is not an unhandled exception error, we will unwind | 301 * If the error is not an unhandled exception error, we will unwind |
300 * the stack to the next C frame. Intervening Dart frames will be | 302 * the stack to the next C frame. Intervening Dart frames will be |
301 * discarded; specifically, 'finally' blocks will not execute. This | 303 * discarded; specifically, 'finally' blocks will not execute. This |
302 * is the standard way that compilation errors (and the like) are | 304 * is the standard way that compilation errors (and the like) are |
303 * handled by the Dart runtime. | 305 * handled by the Dart runtime. |
304 * | 306 * |
305 * In either case, when an error is propagated any current scopes | 307 * In either case, when an error is propagated any current scopes |
306 * created by Dart_EnterScope will be exited. | 308 * created by Dart_EnterScope will be exited. |
307 * | 309 * |
308 * See the additonal discussion under "Propagating Errors" at the | 310 * See the additonal discussion under "Propagating Errors" at the |
309 * beginning of this file. | 311 * beginning of this file. |
310 * | 312 * |
311 * \param An error handle (See Dart_IsError) | 313 * \param An error handle (See Dart_IsError) |
312 * | 314 * |
313 * \return On success, this function does not return. On failure, an | 315 * \return On success, this function does not return. On failure, an |
314 * error handle is returned. | 316 * error handle is returned. |
315 */ | 317 */ |
316 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle); | 318 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle); |
317 // TODO(turnidge): Should this really return an error handle? | 319 /* TODO(turnidge): Should this really return an error handle? */ |
318 // Consider just terminating. | 320 /* Consider just terminating. */ |
319 | 321 |
320 // Internal routine used for reporting error handles. | 322 /* Internal routine used for reporting error handles. */ |
321 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 323 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
322 int line, | 324 int line, |
323 const char* handle_string, | 325 const char* handle_string, |
324 const char* error); | 326 const char* error); |
325 | 327 |
326 // TODO(turnidge): Move DART_CHECK_VALID to some sort of dart_utils | 328 /* TODO(turnidge): Move DART_CHECK_VALID to some sort of dart_utils |
327 // header instead of this header. | 329 * header instead of this header. */ |
328 /** | 330 /** |
329 * Aborts the process if 'handle' is an error handle. | 331 * Aborts the process if 'handle' is an error handle. |
330 * | 332 * |
331 * Provided for convenience. | 333 * Provided for convenience. |
332 */ | 334 */ |
333 #define DART_CHECK_VALID(handle) \ | 335 #define DART_CHECK_VALID(handle) \ |
334 { \ | 336 { \ |
335 Dart_Handle __handle = handle; \ | 337 Dart_Handle __handle = handle; \ |
336 if (Dart_IsError((__handle))) { \ | 338 if (Dart_IsError((__handle))) { \ |
337 _Dart_ReportErrorHandle(__FILE__, __LINE__, \ | 339 _Dart_ReportErrorHandle(__FILE__, __LINE__, \ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 * | 471 * |
470 * \return Success if the weak reference set could be created. | 472 * \return Success if the weak reference set could be created. |
471 * Otherwise, returns an error handle. | 473 * Otherwise, returns an error handle. |
472 */ | 474 */ |
473 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( | 475 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( |
474 Dart_WeakPersistentHandle* keys, | 476 Dart_WeakPersistentHandle* keys, |
475 intptr_t num_keys, | 477 intptr_t num_keys, |
476 Dart_WeakPersistentHandle* values, | 478 Dart_WeakPersistentHandle* values, |
477 intptr_t num_values); | 479 intptr_t num_values); |
478 | 480 |
479 // --- Garbage Collection Callbacks --- | 481 /* --- Garbage Collection Callbacks --- */ |
480 | 482 |
481 /** | 483 /** |
482 * Callbacks signal the beginning and end of a garbage collection. | 484 * Callbacks signal the beginning and end of a garbage collection. |
483 * | 485 * |
484 * These signals are intended to be used by the embedder to manage the | 486 * These signals are intended to be used by the embedder to manage the |
485 * lifetime of native objects with a managed object peer. | 487 * lifetime of native objects with a managed object peer. |
486 */ | 488 */ |
487 | 489 |
488 /** | 490 /** |
489 * A callback invoked at the beginning of a garbage collection. | 491 * A callback invoked at the beginning of a garbage collection. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 * \param callback A function pointer to an epilogue callback | 541 * \param callback A function pointer to an epilogue callback |
540 * function. This function must have been added as an epilogue | 542 * function. This function must have been added as an epilogue |
541 * callback. | 543 * callback. |
542 * | 544 * |
543 * \return Success if the callback was removed. Otherwise, returns an | 545 * \return Success if the callback was removed. Otherwise, returns an |
544 * error handle. | 546 * error handle. |
545 */ | 547 */ |
546 DART_EXPORT Dart_Handle Dart_RemoveGcEpilogueCallback( | 548 DART_EXPORT Dart_Handle Dart_RemoveGcEpilogueCallback( |
547 Dart_GcEpilogueCallback callback); | 549 Dart_GcEpilogueCallback callback); |
548 | 550 |
549 // --- Initialization and Globals --- | 551 /* --- Initialization and Globals --- */ |
550 | 552 |
551 /** | 553 /** |
552 * Gets the version string for the Dart VM. | 554 * Gets the version string for the Dart VM. |
553 * | 555 * |
554 * The version of the Dart VM can be accessed without initializing the VM. | 556 * The version of the Dart VM can be accessed without initializing the VM. |
555 * | 557 * |
556 * \return The version string for the embedded Dart VM. | 558 * \return The version string for the embedded Dart VM. |
557 */ | 559 */ |
558 DART_EXPORT const char* Dart_VersionString(); | 560 DART_EXPORT const char* Dart_VersionString(); |
559 | 561 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 * This callback, provided by the embedder, is called when an isolate | 622 * This callback, provided by the embedder, is called when an isolate |
621 * is interrupted as a result of a call to Dart_InterruptIsolate(). | 623 * is interrupted as a result of a call to Dart_InterruptIsolate(). |
622 * When the callback is called, Dart_CurrentIsolate can be used to | 624 * When the callback is called, Dart_CurrentIsolate can be used to |
623 * figure out which isolate is being interrupted. | 625 * figure out which isolate is being interrupted. |
624 * | 626 * |
625 * \return The embedder returns true if the isolate should continue | 627 * \return The embedder returns true if the isolate should continue |
626 * execution. If the embedder returns false, the isolate will be | 628 * execution. If the embedder returns false, the isolate will be |
627 * unwound (currently unimplemented). | 629 * unwound (currently unimplemented). |
628 */ | 630 */ |
629 typedef bool (*Dart_IsolateInterruptCallback)(); | 631 typedef bool (*Dart_IsolateInterruptCallback)(); |
630 // TODO(turnidge): Define and implement unwinding. | 632 /* TODO(turnidge): Define and implement unwinding. */ |
631 | 633 |
632 /** | 634 /** |
633 * An isolate unhandled exception callback function. | 635 * An isolate unhandled exception callback function. |
634 * | 636 * |
635 * This callback, provided by the embedder, is called when an unhandled | 637 * This callback, provided by the embedder, is called when an unhandled |
636 * exception or internal error is thrown during isolate execution. When the | 638 * exception or internal error is thrown during isolate execution. When the |
637 * callback is invoked, Dart_CurrentIsolate can be used to figure out which | 639 * callback is invoked, Dart_CurrentIsolate can be used to figure out which |
638 * isolate was running when the exception was thrown. | 640 * isolate was running when the exception was thrown. |
639 * | 641 * |
640 * \param error The unhandled exception or error. This handle's scope is | 642 * \param error The unhandled exception or error. This handle's scope is |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 * | 732 * |
731 * \return True if VM flags set successfully. | 733 * \return True if VM flags set successfully. |
732 */ | 734 */ |
733 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv); | 735 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv); |
734 | 736 |
735 /** | 737 /** |
736 * Returns true if the named VM flag is set. | 738 * Returns true if the named VM flag is set. |
737 */ | 739 */ |
738 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); | 740 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); |
739 | 741 |
740 // --- Isolates --- | 742 /* --- Isolates --- */ |
741 | 743 |
742 /** | 744 /** |
743 * Creates a new isolate. The new isolate becomes the current isolate. | 745 * Creates a new isolate. The new isolate becomes the current isolate. |
744 * | 746 * |
745 * A snapshot can be used to restore the VM quickly to a saved state | 747 * A snapshot can be used to restore the VM quickly to a saved state |
746 * and is useful for fast startup. If snapshot data is provided, the | 748 * and is useful for fast startup. If snapshot data is provided, the |
747 * isolate will be started using that snapshot data. | 749 * isolate will be started using that snapshot data. |
748 * | 750 * |
749 * Requires there to be no current isolate. | 751 * Requires there to be no current isolate. |
750 * | 752 * |
751 * \param script_uri The name of the script this isolate will load. | 753 * \param script_uri The name of the script this isolate will load. |
752 * Provided only for advisory purposes to improve debugging messages. | 754 * Provided only for advisory purposes to improve debugging messages. |
753 * \param main The name of the main entry point this isolate will run. | 755 * \param main The name of the main entry point this isolate will run. |
754 * Provided only for advisory purposes to improve debugging messages. | 756 * Provided only for advisory purposes to improve debugging messages. |
755 * \param snapshot A buffer containing a VM snapshot or NULL if no | 757 * \param snapshot A buffer containing a VM snapshot or NULL if no |
756 * snapshot is provided. | 758 * snapshot is provided. |
757 * \param callback_data Embedder data. This data will be passed to | 759 * \param callback_data Embedder data. This data will be passed to |
758 * the Dart_IsolateCreateCallback when new isolates are spawned from | 760 * the Dart_IsolateCreateCallback when new isolates are spawned from |
759 * this parent isolate. | 761 * this parent isolate. |
760 * \param error DOCUMENT | 762 * \param error DOCUMENT |
761 * | 763 * |
762 * \return The new isolate is returned. May be NULL if an error | 764 * \return The new isolate is returned. May be NULL if an error |
763 * occurs duing isolate initialization. | 765 * occurs duing isolate initialization. |
764 */ | 766 */ |
765 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 767 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
766 const char* main, | 768 const char* main, |
767 const uint8_t* snapshot, | 769 const uint8_t* snapshot, |
768 void* callback_data, | 770 void* callback_data, |
769 char** error); | 771 char** error); |
770 // TODO(turnidge): Document behavior when there is already a current | 772 /* TODO(turnidge): Document behavior when there is already a current |
771 // isolate. | 773 * isolate. */ |
772 | 774 |
773 /** | 775 /** |
774 * Shuts down the current isolate. After this call, the current | 776 * Shuts down the current isolate. After this call, the current |
775 * isolate is NULL. | 777 * isolate is NULL. |
776 * | 778 * |
777 * Requires there to be a current isolate. | 779 * Requires there to be a current isolate. |
778 */ | 780 */ |
779 DART_EXPORT void Dart_ShutdownIsolate(); | 781 DART_EXPORT void Dart_ShutdownIsolate(); |
780 // TODO(turnidge): Document behavior when there is no current isolate. | 782 /* TODO(turnidge): Document behavior when there is no current isolate. */ |
781 | 783 |
782 /** | 784 /** |
783 * Returns the current isolate. Will return NULL if there is no | 785 * Returns the current isolate. Will return NULL if there is no |
784 * current isolate. | 786 * current isolate. |
785 */ | 787 */ |
786 DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); | 788 DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); |
787 | 789 |
788 /** | 790 /** |
789 * Returns the callback data which was passed to the isolate when it | 791 * Returns the callback data which was passed to the isolate when it |
790 * was created. | 792 * was created. |
791 */ | 793 */ |
792 DART_EXPORT void* Dart_CurrentIsolateData(); | 794 DART_EXPORT void* Dart_CurrentIsolateData(); |
793 | 795 |
794 /** | 796 /** |
795 * Returns the debugging name for the current isolate. | 797 * Returns the debugging name for the current isolate. |
796 * | 798 * |
797 * This name is unique to each isolate and should only be used to make | 799 * This name is unique to each isolate and should only be used to make |
798 * debugging messages more comprehensible. | 800 * debugging messages more comprehensible. |
799 */ | 801 */ |
800 DART_EXPORT Dart_Handle Dart_DebugName(); | 802 DART_EXPORT Dart_Handle Dart_DebugName(); |
801 | 803 |
802 /** | 804 /** |
803 * Enters an isolate. After calling this function, | 805 * Enters an isolate. After calling this function, |
804 * the current isolate will be set to the provided isolate. | 806 * the current isolate will be set to the provided isolate. |
805 * | 807 * |
806 * Requires there to be no current isolate. | 808 * Requires there to be no current isolate. |
807 */ | 809 */ |
808 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); | 810 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); |
809 // TODO(turnidge): Describe what happens if two threads attempt to | 811 /* TODO(turnidge): Describe what happens if two threads attempt to |
810 // enter the same isolate simultaneously. Check for this in the code. | 812 * enter the same isolate simultaneously. Check for this in the code. |
811 // Describe whether isolates are allowed to migrate. | 813 * Describe whether isolates are allowed to migrate. */ |
812 | 814 |
813 /** | 815 /** |
814 * Exits an isolate. After this call, Dart_CurrentIsolate will | 816 * Exits an isolate. After this call, Dart_CurrentIsolate will |
815 * return NULL. | 817 * return NULL. |
816 * | 818 * |
817 * Requires there to be a current isolate. | 819 * Requires there to be a current isolate. |
818 */ | 820 */ |
819 DART_EXPORT void Dart_ExitIsolate(); | 821 DART_EXPORT void Dart_ExitIsolate(); |
820 // TODO(turnidge): We don't want users of the api to be able to exit a | 822 /* TODO(turnidge): We don't want users of the api to be able to exit a |
821 // "pure" dart isolate. Implement and document. | 823 * "pure" dart isolate. Implement and document. */ |
822 | 824 |
823 /** | 825 /** |
824 * Creates a full snapshot of the current isolate heap. | 826 * Creates a full snapshot of the current isolate heap. |
825 * | 827 * |
826 * A full snapshot is a compact representation of the dart heap state and | 828 * A full snapshot is a compact representation of the dart heap state and |
827 * can be used for fast initialization of an isolate. A Snapshot of the heap | 829 * can be used for fast initialization of an isolate. A Snapshot of the heap |
828 * can only be created before any dart code has executed. | 830 * can only be created before any dart code has executed. |
829 * | 831 * |
830 * Requires there to be a current isolate. | 832 * Requires there to be a current isolate. |
831 * | 833 * |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 * When isolates are spawned this function is used to indicate that | 882 * When isolates are spawned this function is used to indicate that |
881 * the creation and initialization (including script loading) of the | 883 * the creation and initialization (including script loading) of the |
882 * isolate is complete and the isolate can start. | 884 * isolate is complete and the isolate can start. |
883 * This function does not expect there to be a current isolate. | 885 * This function does not expect there to be a current isolate. |
884 * | 886 * |
885 * \param isolate The isolate to be made runnable. | 887 * \param isolate The isolate to be made runnable. |
886 */ | 888 */ |
887 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate); | 889 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate); |
888 | 890 |
889 | 891 |
890 // --- Messages and Ports --- | 892 /* --- Messages and Ports --- */ |
891 | 893 |
892 /** | 894 /** |
893 * A port is used to send or receive inter-isolate messages | 895 * A port is used to send or receive inter-isolate messages |
894 */ | 896 */ |
895 typedef int64_t Dart_Port; | 897 typedef int64_t Dart_Port; |
896 | 898 |
897 /** | 899 /** |
898 * ILLEGAL_PORT is a port number guaranteed never to be associated with a valid | 900 * ILLEGAL_PORT is a port number guaranteed never to be associated with a valid |
899 * port. | 901 * port. |
900 */ | 902 */ |
(...skipping 13 matching lines...) Expand all Loading... |
914 * Allows embedders to provide an alternative wakeup mechanism for the | 916 * Allows embedders to provide an alternative wakeup mechanism for the |
915 * delivery of inter-isolate messages. This setting only applies to | 917 * delivery of inter-isolate messages. This setting only applies to |
916 * the current isolate. | 918 * the current isolate. |
917 * | 919 * |
918 * Most embedders will only call this function once, before isolate | 920 * Most embedders will only call this function once, before isolate |
919 * execution begins. If this function is called after isolate | 921 * execution begins. If this function is called after isolate |
920 * execution begins, the embedder is responsible for threading issues. | 922 * execution begins, the embedder is responsible for threading issues. |
921 */ | 923 */ |
922 DART_EXPORT void Dart_SetMessageNotifyCallback( | 924 DART_EXPORT void Dart_SetMessageNotifyCallback( |
923 Dart_MessageNotifyCallback message_notify_callback); | 925 Dart_MessageNotifyCallback message_notify_callback); |
924 // TODO(turnidge): Consider moving this to isolate creation so that it | 926 /* TODO(turnidge): Consider moving this to isolate creation so that it |
925 // is impossible to mess up. | 927 * is impossible to mess up. */ |
926 | 928 |
927 /** | 929 /** |
928 * Handles the next pending message for the current isolate. | 930 * Handles the next pending message for the current isolate. |
929 * | 931 * |
930 * May generate an unhandled exception error. | 932 * May generate an unhandled exception error. |
931 * | 933 * |
932 * \return A valid handle if no error occurs during the operation. | 934 * \return A valid handle if no error occurs during the operation. |
933 */ | 935 */ |
934 DART_EXPORT Dart_Handle Dart_HandleMessage(); | 936 DART_EXPORT Dart_Handle Dart_HandleMessage(); |
935 | 937 |
936 /** | 938 /** |
937 * Processes any incoming messages for the current isolate. | 939 * Processes any incoming messages for the current isolate. |
938 * | 940 * |
939 * This function may only be used when the embedder has not provided | 941 * This function may only be used when the embedder has not provided |
940 * an alternate message delivery mechanism with | 942 * an alternate message delivery mechanism with |
941 * Dart_SetMessageCallbacks. It is provided for convenience. | 943 * Dart_SetMessageCallbacks. It is provided for convenience. |
942 * | 944 * |
943 * This function waits for incoming messages for the current | 945 * This function waits for incoming messages for the current |
944 * isolate. As new messages arrive, they are handled using | 946 * isolate. As new messages arrive, they are handled using |
945 * Dart_HandleMessage. The routine exits when all ports to the | 947 * Dart_HandleMessage. The routine exits when all ports to the |
946 * current isolate are closed. | 948 * current isolate are closed. |
947 * | 949 * |
948 * \return A valid handle if the run loop exited successfully. If an | 950 * \return A valid handle if the run loop exited successfully. If an |
949 * exception or other error occurs while processing messages, an | 951 * exception or other error occurs while processing messages, an |
950 * error handle is returned. | 952 * error handle is returned. |
951 */ | 953 */ |
952 DART_EXPORT Dart_Handle Dart_RunLoop(); | 954 DART_EXPORT Dart_Handle Dart_RunLoop(); |
953 // TODO(turnidge): Should this be removed from the public api? | 955 /* TODO(turnidge): Should this be removed from the public api? */ |
954 | 956 |
955 /** | 957 /** |
956 * Gets the main port id for the current isolate. | 958 * Gets the main port id for the current isolate. |
957 */ | 959 */ |
958 DART_EXPORT Dart_Port Dart_GetMainPortId(); | 960 DART_EXPORT Dart_Port Dart_GetMainPortId(); |
959 | 961 |
960 /** | 962 /** |
961 * Does the current isolate have live ReceivePorts? | 963 * Does the current isolate have live ReceivePorts? |
962 * | 964 * |
963 * A ReceivePort is live when it has not been closed. | 965 * A ReceivePort is live when it has not been closed. |
964 */ | 966 */ |
965 DART_EXPORT bool Dart_HasLivePorts(); | 967 DART_EXPORT bool Dart_HasLivePorts(); |
966 | 968 |
967 /** | 969 /** |
968 * Posts a message for some isolate. The message is a serialized | 970 * Posts a message for some isolate. The message is a serialized |
969 * object. | 971 * object. |
970 * | 972 * |
971 * Requires there to be a current isolate. | 973 * Requires there to be a current isolate. |
972 * | 974 * |
973 * \param port The destination port. | 975 * \param port The destination port. |
974 * \param object An object from the current isolate. | 976 * \param object An object from the current isolate. |
975 * | 977 * |
976 * \return True if the message was posted. | 978 * \return True if the message was posted. |
977 */ | 979 */ |
978 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle object); | 980 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle object); |
979 | 981 |
980 // --- Message sending/receiving from native code ---- | |
981 | |
982 /** | |
983 * A Dart_CObject is used for representing Dart objects as native C | |
984 * data outside the Dart heap. These objects are totally detached from | |
985 * the Dart heap. Only a subset of the Dart objects have a | |
986 * representation as a Dart_CObject. | |
987 * | |
988 * The string encoding in the 'value.as_string' is UTF-8. | |
989 * | |
990 * All the different types from dart:typed_data are exposed as type | |
991 * kTypedData. The specific type from dart:typed_data is in the type | |
992 * field of the as_typed_data structure. The length in the | |
993 * as_typed_data structure is always in bytes. | |
994 */ | |
995 typedef struct _Dart_CObject { | |
996 enum Type { | |
997 kNull = 0, | |
998 kBool, | |
999 kInt32, | |
1000 kInt64, | |
1001 kBigint, | |
1002 kDouble, | |
1003 kString, | |
1004 kArray, | |
1005 kTypedData, | |
1006 kExternalTypedData, | |
1007 kUnsupported, | |
1008 kNumberOfTypes | |
1009 } type; | |
1010 | |
1011 enum TypedDataType { | |
1012 kInt8Array = 0, | |
1013 kUint8Array, | |
1014 kUint8ClampedArray, | |
1015 kInt16Array, | |
1016 kUint16Array, | |
1017 kInt32Array, | |
1018 kUint32Array, | |
1019 kInt64Array, | |
1020 kUint64Array, | |
1021 kFloat32Array, | |
1022 kFloat64Array, | |
1023 kNumberOfTypedDataTypes | |
1024 }; | |
1025 | |
1026 union { | |
1027 bool as_bool; | |
1028 int32_t as_int32; | |
1029 int64_t as_int64; | |
1030 double as_double; | |
1031 char* as_string; | |
1032 char* as_bigint; | |
1033 struct { | |
1034 int length; | |
1035 struct _Dart_CObject** values; | |
1036 } as_array; | |
1037 struct { | |
1038 TypedDataType type; | |
1039 int length; | |
1040 uint8_t* values; | |
1041 } as_typed_data; | |
1042 struct { | |
1043 TypedDataType type; | |
1044 int length; | |
1045 uint8_t* data; | |
1046 void* peer; | |
1047 Dart_WeakPersistentHandleFinalizer callback; | |
1048 } as_external_typed_data; | |
1049 } value; | |
1050 } Dart_CObject; | |
1051 | |
1052 /** | |
1053 * Posts a message on some port. The message will contain the | |
1054 * Dart_CObject object graph rooted in 'message'. | |
1055 * | |
1056 * While the message is being sent the state of the graph of | |
1057 * Dart_CObject structures rooted in 'message' should not be accessed, | |
1058 * as the message generation will make temporary modifications to the | |
1059 * data. When the message has been sent the graph will be fully | |
1060 * restored. | |
1061 * | |
1062 * \param port_id The destination port. | |
1063 * \param message The message to send. | |
1064 * | |
1065 * \return True if the message was posted. | |
1066 */ | |
1067 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message); | |
1068 | |
1069 /** | |
1070 * A native message handler. | |
1071 * | |
1072 * This handler is associated with a native port by calling | |
1073 * Dart_NewNativePort. | |
1074 * | |
1075 * The message received is decoded into the message structure. The | |
1076 * lifetime of the message data is controlled by the caller. All the | |
1077 * data references from the message are allocated by the caller and | |
1078 * will be reclaimed when returning to it. | |
1079 */ | |
1080 | |
1081 typedef void (*Dart_NativeMessageHandler)(Dart_Port dest_port_id, | |
1082 Dart_Port reply_port_id, | |
1083 Dart_CObject* message); | |
1084 | |
1085 /** | |
1086 * Creates a new native port. When messages are received on this | |
1087 * native port, then they will be dispatched to the provided native | |
1088 * message handler. | |
1089 * | |
1090 * \param name The name of this port in debugging messages. | |
1091 * \param handler The C handler to run when messages arrive on the port. | |
1092 * \param handle_concurrently Is it okay to process requests on this | |
1093 * native port concurrently? | |
1094 * | |
1095 * \return If successful, returns the port id for the native port. In | |
1096 * case of error, returns ILLEGAL_PORT. | |
1097 */ | |
1098 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, | |
1099 Dart_NativeMessageHandler handler, | |
1100 bool handle_concurrently); | |
1101 // TODO(turnidge): Currently handle_concurrently is ignored. | |
1102 | |
1103 /** | |
1104 * Closes the native port with the given id. | |
1105 * | |
1106 * The port must have been allocated by a call to Dart_NewNativePort. | |
1107 * | |
1108 * \param native_port_id The id of the native port to close. | |
1109 * | |
1110 * \return Returns true if the port was closed successfully. | |
1111 */ | |
1112 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id); | |
1113 | |
1114 /** | 982 /** |
1115 * Returns a new SendPort with the provided port id. | 983 * Returns a new SendPort with the provided port id. |
1116 */ | 984 */ |
1117 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id); | 985 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id); |
1118 | 986 |
1119 /** | 987 /** |
1120 * Gets the ReceivePort for the provided port id, creating it if necessary. | 988 * Gets the ReceivePort for the provided port id, creating it if necessary. |
1121 * | 989 * |
1122 * Note that there is at most one ReceivePort for a given port id. | 990 * Note that there is at most one ReceivePort for a given port id. |
1123 */ | 991 */ |
1124 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id); | 992 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id); |
1125 | 993 |
1126 // --- Scopes ---- | 994 /* --- Scopes ---- */ |
1127 | 995 |
1128 /** | 996 /** |
1129 * Enters a new scope. | 997 * Enters a new scope. |
1130 * | 998 * |
1131 * All new local handles will be created in this scope. Additionally, | 999 * All new local handles will be created in this scope. Additionally, |
1132 * some functions may return "scope allocated" memory which is only | 1000 * some functions may return "scope allocated" memory which is only |
1133 * valid within this scope. | 1001 * valid within this scope. |
1134 * | 1002 * |
1135 * Requires there to be a current isolate. | 1003 * Requires there to be a current isolate. |
1136 */ | 1004 */ |
(...skipping 25 matching lines...) Expand all Loading... |
1162 * All the memory allocated this way will be reclaimed either on the | 1030 * All the memory allocated this way will be reclaimed either on the |
1163 * next call to Dart_ExitScope or when the native port handler exits. | 1031 * next call to Dart_ExitScope or when the native port handler exits. |
1164 * | 1032 * |
1165 * \param size Size of the memory to allocate. | 1033 * \param size Size of the memory to allocate. |
1166 * | 1034 * |
1167 * \return A pointer to the allocated memory. NULL if allocation | 1035 * \return A pointer to the allocated memory. NULL if allocation |
1168 * failed. Failure might due to is no current VM zone. | 1036 * failed. Failure might due to is no current VM zone. |
1169 */ | 1037 */ |
1170 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size); | 1038 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size); |
1171 | 1039 |
1172 // --- Objects ---- | 1040 /* --- Objects ---- */ |
1173 | 1041 |
1174 /** | 1042 /** |
1175 * Returns the null object. | 1043 * Returns the null object. |
1176 * | 1044 * |
1177 * Requires there to be a current isolate. | 1045 * Requires there to be a current isolate. |
1178 * | 1046 * |
1179 * \return A handle to the null object. | 1047 * \return A handle to the null object. |
1180 */ | 1048 */ |
1181 DART_EXPORT Dart_Handle Dart_Null(); | 1049 DART_EXPORT Dart_Handle Dart_Null(); |
1182 | 1050 |
(...skipping 30 matching lines...) Expand all Loading... |
1213 * \param object An object. | 1081 * \param object An object. |
1214 * \param type A type. | 1082 * \param type A type. |
1215 * \param instanceof Return true if 'object' is an instance of type 'type'. | 1083 * \param instanceof Return true if 'object' is an instance of type 'type'. |
1216 * | 1084 * |
1217 * \return A valid handle if no error occurs during the operation. | 1085 * \return A valid handle if no error occurs during the operation. |
1218 */ | 1086 */ |
1219 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1087 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
1220 Dart_Handle type, | 1088 Dart_Handle type, |
1221 bool* instanceof); | 1089 bool* instanceof); |
1222 | 1090 |
1223 // --- Instances ---- | 1091 /* --- Instances ---- |
1224 // For the purposes of the embedding api, not all objects returned are | 1092 * For the purposes of the embedding api, not all objects returned are |
1225 // Dart language objects. Within the api, we use the term 'Instance' | 1093 * Dart language objects. Within the api, we use the term 'Instance' |
1226 // to indicate handles which refer to true Dart language objects. | 1094 * to indicate handles which refer to true Dart language objects. |
1227 // | 1095 * |
1228 // TODO(turnidge): Reorganize the "Object" section above, pulling down | 1096 * TODO(turnidge): Reorganize the "Object" section above, pulling down |
1229 // any functions that more properly belong here. | 1097 * any functions that more properly belong here. */ |
1230 | 1098 |
1231 /** | 1099 /** |
1232 * Does this handle refer to some Dart language object? | 1100 * Does this handle refer to some Dart language object? |
1233 */ | 1101 */ |
1234 DART_EXPORT bool Dart_IsInstance(Dart_Handle object); | 1102 DART_EXPORT bool Dart_IsInstance(Dart_Handle object); |
1235 | 1103 |
1236 /** | 1104 /** |
1237 * Gets the class for some Dart language object. | 1105 * Gets the class for some Dart language object. |
1238 * | 1106 * |
1239 * \param instance Some Dart object. | 1107 * \param instance Some Dart object. |
1240 * | 1108 * |
1241 * \return If no error occurs, the class is returned. Otherwise an | 1109 * \return If no error occurs, the class is returned. Otherwise an |
1242 * error handle is returned. | 1110 * error handle is returned. |
1243 */ | 1111 */ |
1244 DART_EXPORT Dart_Handle Dart_InstanceGetClass(Dart_Handle instance); | 1112 DART_EXPORT Dart_Handle Dart_InstanceGetClass(Dart_Handle instance); |
1245 | 1113 |
1246 // --- Numbers ---- | 1114 /* --- Numbers ---- */ |
1247 | 1115 |
1248 /** | 1116 /** |
1249 * Is this object a Number? | 1117 * Is this object a Number? |
1250 */ | 1118 */ |
1251 DART_EXPORT bool Dart_IsNumber(Dart_Handle object); | 1119 DART_EXPORT bool Dart_IsNumber(Dart_Handle object); |
1252 | 1120 |
1253 // --- Integers ---- | 1121 /* --- Integers ---- */ |
1254 | 1122 |
1255 /** | 1123 /** |
1256 * Is this object an Integer? | 1124 * Is this object an Integer? |
1257 */ | 1125 */ |
1258 DART_EXPORT bool Dart_IsInteger(Dart_Handle object); | 1126 DART_EXPORT bool Dart_IsInteger(Dart_Handle object); |
1259 | 1127 |
1260 /** | 1128 /** |
1261 * Does this Integer fit into a 64-bit signed integer? | 1129 * Does this Integer fit into a 64-bit signed integer? |
1262 * | 1130 * |
1263 * \param integer An integer. | 1131 * \param integer An integer. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 * \param integer An Integer. | 1201 * \param integer An Integer. |
1334 * \param value Returns the value of the Integer as a hexadecimal C | 1202 * \param value Returns the value of the Integer as a hexadecimal C |
1335 * string. This C string is scope allocated and is only valid until | 1203 * string. This C string is scope allocated and is only valid until |
1336 * the next call to Dart_ExitScope. | 1204 * the next call to Dart_ExitScope. |
1337 * | 1205 * |
1338 * \return A valid handle if no error occurs during the operation. | 1206 * \return A valid handle if no error occurs during the operation. |
1339 */ | 1207 */ |
1340 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 1208 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
1341 const char** value); | 1209 const char** value); |
1342 | 1210 |
1343 // --- Booleans ---- | 1211 /* --- Booleans ---- */ |
1344 | 1212 |
1345 /** | 1213 /** |
1346 * Returns the True object. | 1214 * Returns the True object. |
1347 * | 1215 * |
1348 * Requires there to be a current isolate. | 1216 * Requires there to be a current isolate. |
1349 * | 1217 * |
1350 * \return A handle to the True object. | 1218 * \return A handle to the True object. |
1351 */ | 1219 */ |
1352 DART_EXPORT Dart_Handle Dart_True(); | 1220 DART_EXPORT Dart_Handle Dart_True(); |
1353 | 1221 |
(...skipping 24 matching lines...) Expand all Loading... |
1378 /** | 1246 /** |
1379 * Gets the value of a Boolean | 1247 * Gets the value of a Boolean |
1380 * | 1248 * |
1381 * \param boolean_obj A Boolean | 1249 * \param boolean_obj A Boolean |
1382 * \param value Returns the value of the Boolean. | 1250 * \param value Returns the value of the Boolean. |
1383 * | 1251 * |
1384 * \return A valid handle if no error occurs during the operation. | 1252 * \return A valid handle if no error occurs during the operation. |
1385 */ | 1253 */ |
1386 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, bool* value); | 1254 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, bool* value); |
1387 | 1255 |
1388 // --- Doubles --- | 1256 /* --- Doubles --- */ |
1389 | 1257 |
1390 /** | 1258 /** |
1391 * Is this object a Double? | 1259 * Is this object a Double? |
1392 */ | 1260 */ |
1393 DART_EXPORT bool Dart_IsDouble(Dart_Handle object); | 1261 DART_EXPORT bool Dart_IsDouble(Dart_Handle object); |
1394 | 1262 |
1395 /** | 1263 /** |
1396 * Returns a Double with the provided value. | 1264 * Returns a Double with the provided value. |
1397 * | 1265 * |
1398 * \param value A double. | 1266 * \param value A double. |
1399 * | 1267 * |
1400 * \return The Double object if no error occurs. Otherwise returns | 1268 * \return The Double object if no error occurs. Otherwise returns |
1401 * an error handle. | 1269 * an error handle. |
1402 */ | 1270 */ |
1403 DART_EXPORT Dart_Handle Dart_NewDouble(double value); | 1271 DART_EXPORT Dart_Handle Dart_NewDouble(double value); |
1404 | 1272 |
1405 /** | 1273 /** |
1406 * Gets the value of a Double | 1274 * Gets the value of a Double |
1407 * | 1275 * |
1408 * \param double_obj A Double | 1276 * \param double_obj A Double |
1409 * \param value Returns the value of the Double. | 1277 * \param value Returns the value of the Double. |
1410 * | 1278 * |
1411 * \return A valid handle if no error occurs during the operation. | 1279 * \return A valid handle if no error occurs during the operation. |
1412 */ | 1280 */ |
1413 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value); | 1281 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value); |
1414 | 1282 |
1415 // --- Strings --- | 1283 /* --- Strings --- */ |
1416 | 1284 |
1417 /** | 1285 /** |
1418 * Is this object a String? | 1286 * Is this object a String? |
1419 */ | 1287 */ |
1420 DART_EXPORT bool Dart_IsString(Dart_Handle object); | 1288 DART_EXPORT bool Dart_IsString(Dart_Handle object); |
1421 | 1289 |
1422 /** | 1290 /** |
1423 * Is this object a Latin-1 (ISO-8859-1) String? | 1291 * Is this object a Latin-1 (ISO-8859-1) String? |
1424 */ | 1292 */ |
1425 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object); | 1293 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object); |
(...skipping 13 matching lines...) Expand all Loading... |
1439 * (There is an implicit assumption that the C string passed in contains | 1307 * (There is an implicit assumption that the C string passed in contains |
1440 * UTF-8 encoded characters and '\0' is considered as a termination | 1308 * UTF-8 encoded characters and '\0' is considered as a termination |
1441 * character). | 1309 * character). |
1442 * | 1310 * |
1443 * \param value A C String | 1311 * \param value A C String |
1444 * | 1312 * |
1445 * \return The String object if no error occurs. Otherwise returns | 1313 * \return The String object if no error occurs. Otherwise returns |
1446 * an error handle. | 1314 * an error handle. |
1447 */ | 1315 */ |
1448 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str); | 1316 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str); |
1449 // TODO(turnidge): Document what happens when we run out of memory | 1317 /* TODO(turnidge): Document what happens when we run out of memory |
1450 // during this call. | 1318 * during this call. */ |
1451 | 1319 |
1452 /** | 1320 /** |
1453 * Returns a String built from an array of UTF-8 encoded characters. | 1321 * Returns a String built from an array of UTF-8 encoded characters. |
1454 * | 1322 * |
1455 * \param utf8_array An array of UTF-8 encoded characters. | 1323 * \param utf8_array An array of UTF-8 encoded characters. |
1456 * \param length The length of the codepoints array. | 1324 * \param length The length of the codepoints array. |
1457 * | 1325 * |
1458 * \return The String object if no error occurs. Otherwise returns | 1326 * \return The String object if no error occurs. Otherwise returns |
1459 * an error handle. | 1327 * an error handle. |
1460 */ | 1328 */ |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 * result = Dart_MakeExternalString(str, data, size, NULL, NULL); | 1500 * result = Dart_MakeExternalString(str, data, size, NULL, NULL); |
1633 * | 1501 * |
1634 */ | 1502 */ |
1635 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, | 1503 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, |
1636 void* array, | 1504 void* array, |
1637 intptr_t length, | 1505 intptr_t length, |
1638 void* peer, | 1506 void* peer, |
1639 Dart_PeerFinalizer cback); | 1507 Dart_PeerFinalizer cback); |
1640 | 1508 |
1641 | 1509 |
1642 // --- Lists --- | 1510 /* --- Lists --- */ |
1643 | 1511 |
1644 /** | 1512 /** |
1645 * Is this object a List? | 1513 * Is this object a List? |
1646 */ | 1514 */ |
1647 DART_EXPORT bool Dart_IsList(Dart_Handle object); | 1515 DART_EXPORT bool Dart_IsList(Dart_Handle object); |
1648 | 1516 |
1649 /** | 1517 /** |
1650 * Returns a List of the desired length. | 1518 * Returns a List of the desired length. |
1651 * | 1519 * |
1652 * \param length The length of the list. | 1520 * \param length The length of the list. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 intptr_t length); | 1578 intptr_t length); |
1711 | 1579 |
1712 /** | 1580 /** |
1713 * May generate an unhandled exception error. | 1581 * May generate an unhandled exception error. |
1714 */ | 1582 */ |
1715 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 1583 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
1716 intptr_t offset, | 1584 intptr_t offset, |
1717 uint8_t* native_array, | 1585 uint8_t* native_array, |
1718 intptr_t length); | 1586 intptr_t length); |
1719 | 1587 |
1720 // --- Typed Data --- | 1588 /* --- Typed Data --- */ |
1721 | 1589 |
1722 typedef enum { | 1590 typedef enum { |
1723 kByteData = 0, | 1591 Dart_TypedData_kByteData = 0, |
1724 kInt8, | 1592 Dart_TypedData_kInt8, |
1725 kUint8, | 1593 Dart_TypedData_kUint8, |
1726 kUint8Clamped, | 1594 Dart_TypedData_kUint8Clamped, |
1727 kInt16, | 1595 Dart_TypedData_kInt16, |
1728 kUint16, | 1596 Dart_TypedData_kUint16, |
1729 kInt32, | 1597 Dart_TypedData_kInt32, |
1730 kUint32, | 1598 Dart_TypedData_kUint32, |
1731 kInt64, | 1599 Dart_TypedData_kInt64, |
1732 kUint64, | 1600 Dart_TypedData_kUint64, |
1733 kFloat32, | 1601 Dart_TypedData_kFloat32, |
1734 kFloat64, | 1602 Dart_TypedData_kFloat64, |
1735 kFloat32x4, | 1603 Dart_TypedData_kFloat32x4, |
1736 kInvalid | 1604 Dart_TypedData_kInvalid |
1737 } Dart_TypedData_Type; | 1605 } Dart_TypedData_Type; |
1738 | 1606 |
1739 /** | 1607 /** |
1740 * Return type if this object is a TypedData object. | 1608 * Return type if this object is a TypedData object. |
1741 * | 1609 * |
1742 * \return kInvalid if the object is not a TypedData object or the appropriate | 1610 * \return kInvalid if the object is not a TypedData object or the appropriate |
1743 * Dart_TypedData_Type. | 1611 * Dart_TypedData_Type. |
1744 */ | 1612 */ |
1745 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object); | 1613 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object); |
1746 | 1614 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 * | 1677 * |
1810 * \param object The typed data object whose internal data address is to be | 1678 * \param object The typed data object whose internal data address is to be |
1811 * released. | 1679 * released. |
1812 * | 1680 * |
1813 * \return Success if the internal data address is released successfully. | 1681 * \return Success if the internal data address is released successfully. |
1814 * Otherwise, returns an error handle. | 1682 * Otherwise, returns an error handle. |
1815 */ | 1683 */ |
1816 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object); | 1684 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object); |
1817 | 1685 |
1818 | 1686 |
1819 // --- Closures --- | 1687 /* --- Closures --- */ |
1820 | 1688 |
1821 /** | 1689 /** |
1822 * Is this object a Closure? | 1690 * Is this object a Closure? |
1823 */ | 1691 */ |
1824 DART_EXPORT bool Dart_IsClosure(Dart_Handle object); | 1692 DART_EXPORT bool Dart_IsClosure(Dart_Handle object); |
1825 | 1693 |
1826 /** | 1694 /** |
1827 * Retrieves the function of a closure. | 1695 * Retrieves the function of a closure. |
1828 * | 1696 * |
1829 * \return A handle to the function of the closure, or an error handle if the | 1697 * \return A handle to the function of the closure, or an error handle if the |
1830 * argument is not a closure. | 1698 * argument is not a closure. |
1831 */ | 1699 */ |
1832 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure); | 1700 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure); |
1833 | 1701 |
1834 /** | 1702 /** |
1835 * Invokes a Closure with the given arguments. | 1703 * Invokes a Closure with the given arguments. |
1836 * | 1704 * |
1837 * May generate an unhandled exception error. | 1705 * May generate an unhandled exception error. |
1838 * | 1706 * |
1839 * \return If no error occurs during execution, then the result of | 1707 * \return If no error occurs during execution, then the result of |
1840 * invoking the closure is returned. If an error occurs during | 1708 * invoking the closure is returned. If an error occurs during |
1841 * execution, then an error handle is returned. | 1709 * execution, then an error handle is returned. |
1842 */ | 1710 */ |
1843 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 1711 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
1844 int number_of_arguments, | 1712 int number_of_arguments, |
1845 Dart_Handle* arguments); | 1713 Dart_Handle* arguments); |
1846 | 1714 |
1847 // --- Classes and Interfaces --- | 1715 /* --- Classes and Interfaces --- */ |
1848 | 1716 |
1849 /** | 1717 /** |
1850 * Is this a class handle? | 1718 * Is this a class handle? |
1851 */ | 1719 */ |
1852 DART_EXPORT bool Dart_IsClass(Dart_Handle handle); | 1720 DART_EXPORT bool Dart_IsClass(Dart_Handle handle); |
1853 | 1721 |
1854 /** | 1722 /** |
1855 * Is this an abstract class handle? | 1723 * Is this an abstract class handle? |
1856 */ | 1724 */ |
1857 DART_EXPORT bool Dart_IsAbstractClass(Dart_Handle handle); | 1725 DART_EXPORT bool Dart_IsAbstractClass(Dart_Handle handle); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 /** | 1780 /** |
1913 * Returns a function handle representing the signature associated | 1781 * Returns a function handle representing the signature associated |
1914 * with a function type. | 1782 * with a function type. |
1915 * | 1783 * |
1916 * The return value is a function handle (See Dart_IsFunction, etc.). | 1784 * The return value is a function handle (See Dart_IsFunction, etc.). |
1917 * | 1785 * |
1918 * TODO(turnidge): Finish documentation. | 1786 * TODO(turnidge): Finish documentation. |
1919 */ | 1787 */ |
1920 DART_EXPORT Dart_Handle Dart_ClassGetFunctionTypeSignature(Dart_Handle clazz); | 1788 DART_EXPORT Dart_Handle Dart_ClassGetFunctionTypeSignature(Dart_Handle clazz); |
1921 | 1789 |
1922 // --- Function and Variable Declarations --- | 1790 /* --- Function and Variable Declarations --- */ |
1923 | 1791 |
1924 /** | 1792 /** |
1925 * Returns a list of the names of all functions or methods declared in | 1793 * Returns a list of the names of all functions or methods declared in |
1926 * a library or class. | 1794 * a library or class. |
1927 * | 1795 * |
1928 * \param target A library or class. | 1796 * \param target A library or class. |
1929 * | 1797 * |
1930 * \return If no error occurs, a list of strings is returned. | 1798 * \return If no error occurs, a list of strings is returned. |
1931 * Otherwise an error handle is returned. | 1799 * Otherwise an error handle is returned. |
1932 */ | 1800 */ |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 /** | 1870 /** |
2003 * Determines whether a function handle referes to a constructor. | 1871 * Determines whether a function handle referes to a constructor. |
2004 * | 1872 * |
2005 * \param function A handle to a function or method declaration. | 1873 * \param function A handle to a function or method declaration. |
2006 * \param is_static Returns whether the function or method is a constructor. | 1874 * \param is_static Returns whether the function or method is a constructor. |
2007 * | 1875 * |
2008 * \return A valid handle if no error occurs during the operation. | 1876 * \return A valid handle if no error occurs during the operation. |
2009 */ | 1877 */ |
2010 DART_EXPORT Dart_Handle Dart_FunctionIsConstructor(Dart_Handle function, | 1878 DART_EXPORT Dart_Handle Dart_FunctionIsConstructor(Dart_Handle function, |
2011 bool* is_constructor); | 1879 bool* is_constructor); |
2012 // TODO(turnidge): Document behavior for factory constructors too. | 1880 /* TODO(turnidge): Document behavior for factory constructors too. */ |
2013 | 1881 |
2014 /** | 1882 /** |
2015 * Determines whether a function or method is a getter. | 1883 * Determines whether a function or method is a getter. |
2016 * | 1884 * |
2017 * \param function A handle to a function or method declaration. | 1885 * \param function A handle to a function or method declaration. |
2018 * \param is_static Returns whether the function or method is a getter. | 1886 * \param is_static Returns whether the function or method is a getter. |
2019 * | 1887 * |
2020 * \return A valid handle if no error occurs during the operation. | 1888 * \return A valid handle if no error occurs during the operation. |
2021 */ | 1889 */ |
2022 DART_EXPORT Dart_Handle Dart_FunctionIsGetter(Dart_Handle function, | 1890 DART_EXPORT Dart_Handle Dart_FunctionIsGetter(Dart_Handle function, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 | 2046 |
2179 /** | 2047 /** |
2180 * Returns the upper bound of a type variable. | 2048 * Returns the upper bound of a type variable. |
2181 * | 2049 * |
2182 * The upper bound of a type variable is ... | 2050 * The upper bound of a type variable is ... |
2183 * | 2051 * |
2184 * \return A valid handle to a type, or an error handle if the | 2052 * \return A valid handle to a type, or an error handle if the |
2185 * argument is not a valid handle. | 2053 * argument is not a valid handle. |
2186 */ | 2054 */ |
2187 DART_EXPORT Dart_Handle Dart_TypeVariableUpperBound(Dart_Handle type_variable); | 2055 DART_EXPORT Dart_Handle Dart_TypeVariableUpperBound(Dart_Handle type_variable); |
2188 // TODO(turnidge): Finish documentation. | 2056 /* TODO(turnidge): Finish documentation. */ |
2189 | 2057 |
2190 // --- Constructors, Methods, and Fields --- | 2058 /* --- Constructors, Methods, and Fields --- */ |
2191 | 2059 |
2192 /** | 2060 /** |
2193 * Invokes a constructor, creating a new object. | 2061 * Invokes a constructor, creating a new object. |
2194 * | 2062 * |
2195 * This function allows hidden constructors (constructors with leading | 2063 * This function allows hidden constructors (constructors with leading |
2196 * underscores) to be called. | 2064 * underscores) to be called. |
2197 * | 2065 * |
2198 * \param clazz A class or an interface. | 2066 * \param clazz A class or an interface. |
2199 * \param constructor_name The name of the constructor to invoke. Use | 2067 * \param constructor_name The name of the constructor to invoke. Use |
2200 * Dart_Null() to invoke the unnamed constructor. This name should | 2068 * Dart_Null() to invoke the unnamed constructor. This name should |
(...skipping 29 matching lines...) Expand all Loading... |
2230 * \param arguments An array of arguments to the function. | 2098 * \param arguments An array of arguments to the function. |
2231 * | 2099 * |
2232 * \return If the function or method is called and completes | 2100 * \return If the function or method is called and completes |
2233 * successfully, then the return value is returned. If an error | 2101 * successfully, then the return value is returned. If an error |
2234 * occurs during execution, then an error handle is returned. | 2102 * occurs during execution, then an error handle is returned. |
2235 */ | 2103 */ |
2236 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 2104 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
2237 Dart_Handle name, | 2105 Dart_Handle name, |
2238 int number_of_arguments, | 2106 int number_of_arguments, |
2239 Dart_Handle* arguments); | 2107 Dart_Handle* arguments); |
2240 // TODO(turnidge): Document how to invoke operators. | 2108 /* TODO(turnidge): Document how to invoke operators. */ |
2241 | 2109 |
2242 /** | 2110 /** |
2243 * Gets the value of a field. | 2111 * Gets the value of a field. |
2244 * | 2112 * |
2245 * The 'container' parameter may be an object, class, or library. If | 2113 * The 'container' parameter may be an object, class, or library. If |
2246 * 'container' is an object, then this function will access an | 2114 * 'container' is an object, then this function will access an |
2247 * instance field. If 'container' is a class, then this function will | 2115 * instance field. If 'container' is a class, then this function will |
2248 * access a static field. If 'container' is a library, then this | 2116 * access a static field. If 'container' is a library, then this |
2249 * function will access a top-level variable. | 2117 * function will access a top-level variable. |
2250 * | 2118 * |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 intptr_t* value); | 2177 intptr_t* value); |
2310 /** | 2178 /** |
2311 * Sets the value of a native field. | 2179 * Sets the value of a native field. |
2312 * | 2180 * |
2313 * TODO(turnidge): Document. | 2181 * TODO(turnidge): Document. |
2314 */ | 2182 */ |
2315 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 2183 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
2316 int index, | 2184 int index, |
2317 intptr_t value); | 2185 intptr_t value); |
2318 | 2186 |
2319 // --- Exceptions ---- | 2187 /* --- Exceptions ---- |
2320 // TODO(turnidge): Remove these functions from the api and replace all | 2188 * TODO(turnidge): Remove these functions from the api and replace all |
2321 // uses with Dart_NewUnhandledExceptionError. | 2189 * uses with Dart_NewUnhandledExceptionError. */ |
2322 | 2190 |
2323 /** | 2191 /** |
2324 * Throws an exception. | 2192 * Throws an exception. |
2325 * | 2193 * |
2326 * This function causes a Dart language exception to be thrown. This | 2194 * This function causes a Dart language exception to be thrown. This |
2327 * will proceeed in the standard way, walking up Dart frames until an | 2195 * will proceeed in the standard way, walking up Dart frames until an |
2328 * appropriate 'catch' block is found, executing 'finally' blocks, | 2196 * appropriate 'catch' block is found, executing 'finally' blocks, |
2329 * etc. | 2197 * etc. |
2330 * | 2198 * |
2331 * If successful, this function does not return. Note that this means | 2199 * If successful, this function does not return. Note that this means |
(...skipping 12 matching lines...) Expand all Loading... |
2344 * successful, this function does not return. Note that this means | 2212 * successful, this function does not return. Note that this means |
2345 * that the destructors of any stack-allocated C++ objects will not be | 2213 * that the destructors of any stack-allocated C++ objects will not be |
2346 * called. If there are no Dart frames on the stack, an error occurs. | 2214 * called. If there are no Dart frames on the stack, an error occurs. |
2347 * | 2215 * |
2348 * \return An error handle if the exception was not thrown. | 2216 * \return An error handle if the exception was not thrown. |
2349 * Otherwise the function does not return. | 2217 * Otherwise the function does not return. |
2350 */ | 2218 */ |
2351 DART_EXPORT Dart_Handle Dart_RethrowException(Dart_Handle exception, | 2219 DART_EXPORT Dart_Handle Dart_RethrowException(Dart_Handle exception, |
2352 Dart_Handle stacktrace); | 2220 Dart_Handle stacktrace); |
2353 | 2221 |
2354 // --- Native functions --- | 2222 /* --- Native functions --- */ |
2355 | 2223 |
2356 /** | 2224 /** |
2357 * The arguments to a native function. | 2225 * The arguments to a native function. |
2358 * | 2226 * |
2359 * This object is passed to a native function to represent its | 2227 * This object is passed to a native function to represent its |
2360 * arguments and return value. It allows access to the arguments to a | 2228 * arguments and return value. It allows access to the arguments to a |
2361 * native function by index. It also allows the return value of a | 2229 * native function by index. It also allows the return value of a |
2362 * native function to be set. | 2230 * native function to be set. |
2363 */ | 2231 */ |
2364 typedef struct _Dart_NativeArguments* Dart_NativeArguments; | 2232 typedef struct _Dart_NativeArguments* Dart_NativeArguments; |
2365 | 2233 |
2366 /** | 2234 /** |
2367 * Gets the native argument at some index. | 2235 * Gets the native argument at some index. |
2368 */ | 2236 */ |
2369 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 2237 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
2370 int index); | 2238 int index); |
2371 // TODO(turnidge): Specify the behavior of an out-of-bounds access. | 2239 /* TODO(turnidge): Specify the behavior of an out-of-bounds access. */ |
2372 | 2240 |
2373 /** | 2241 /** |
2374 * Gets the number of native arguments. | 2242 * Gets the number of native arguments. |
2375 */ | 2243 */ |
2376 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args); | 2244 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args); |
2377 | 2245 |
2378 /** | 2246 /** |
2379 * Sets the return value for a native function. | 2247 * Sets the return value for a native function. |
2380 */ | 2248 */ |
2381 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 2249 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
2382 Dart_Handle retval); | 2250 Dart_Handle retval); |
2383 | 2251 |
2384 /** | 2252 /** |
2385 * A native function. | 2253 * A native function. |
2386 */ | 2254 */ |
2387 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); | 2255 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); |
2388 | 2256 |
2389 /** | 2257 /** |
2390 * Native entry resolution callback. | 2258 * Native entry resolution callback. |
2391 * | 2259 * |
2392 * For libraries and scripts which have native functions, the embedder | 2260 * For libraries and scripts which have native functions, the embedder |
2393 * can provide a native entry resolver. This callback is used to map a | 2261 * can provide a native entry resolver. This callback is used to map a |
2394 * name/arity to a Dart_NativeFunction. If no function is found, the | 2262 * name/arity to a Dart_NativeFunction. If no function is found, the |
2395 * callback should return NULL. | 2263 * callback should return NULL. |
2396 * | 2264 * |
2397 * See Dart_SetNativeResolver. | 2265 * See Dart_SetNativeResolver. |
2398 */ | 2266 */ |
2399 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, | 2267 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, |
2400 int num_of_arguments); | 2268 int num_of_arguments); |
2401 // TODO(turnidge): Consider renaming to NativeFunctionResolver or | 2269 /* TODO(turnidge): Consider renaming to NativeFunctionResolver or |
2402 // NativeResolver. | 2270 * NativeResolver. */ |
2403 | 2271 |
2404 // --- Scripts and Libraries --- | 2272 /* --- Scripts and Libraries --- |
2405 // TODO(turnidge): Finish documenting this section. | 2273 * TODO(turnidge): Finish documenting this section. */ |
2406 | 2274 |
2407 typedef enum { | 2275 typedef enum { |
2408 kLibraryTag = 0, | 2276 Dart_kLibraryTag = 0, |
2409 kImportTag, | 2277 Dart_kImportTag, |
2410 kSourceTag, | 2278 Dart_kSourceTag, |
2411 kCanonicalizeUrl | 2279 Dart_kCanonicalizeUrl |
2412 } Dart_LibraryTag; | 2280 } Dart_LibraryTag; |
2413 | 2281 |
2414 // TODO(turnidge): Document. | 2282 /* TODO(turnidge): Document. */ |
2415 typedef Dart_Handle (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, | 2283 typedef Dart_Handle (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, |
2416 Dart_Handle library, | 2284 Dart_Handle library, |
2417 Dart_Handle url); | 2285 Dart_Handle url); |
2418 | 2286 |
2419 /** | 2287 /** |
2420 * Sets library tag handler for the current isolate. This handler is | 2288 * Sets library tag handler for the current isolate. This handler is |
2421 * used to handle the various tags encountered while loading libraries | 2289 * used to handle the various tags encountered while loading libraries |
2422 * or scripts in the isolate. | 2290 * or scripts in the isolate. |
2423 * | 2291 * |
2424 * \param handler Handler code to be used for handling the various tags | 2292 * \param handler Handler code to be used for handling the various tags |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 * Lookup a class or interface by name from a Library. | 2363 * Lookup a class or interface by name from a Library. |
2496 * | 2364 * |
2497 * \param library The library containing the class or interface. | 2365 * \param library The library containing the class or interface. |
2498 * \param class_name The name of the class or interface. | 2366 * \param class_name The name of the class or interface. |
2499 * | 2367 * |
2500 * \return If no error occurs, the class or interface is | 2368 * \return If no error occurs, the class or interface is |
2501 * returned. Otherwise an error handle is returned. | 2369 * returned. Otherwise an error handle is returned. |
2502 */ | 2370 */ |
2503 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, | 2371 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, |
2504 Dart_Handle class_name); | 2372 Dart_Handle class_name); |
2505 // TODO(turnidge): Consider returning Dart_Null() when the class is | 2373 /* TODO(turnidge): Consider returning Dart_Null() when the class is |
2506 // not found to distinguish that from a true error case. | 2374 * not found to distinguish that from a true error case. */ |
2507 | 2375 |
2508 /** | 2376 /** |
2509 * Returns the name of a library as declared in the #library directive. | 2377 * Returns the name of a library as declared in the #library directive. |
2510 */ | 2378 */ |
2511 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library); | 2379 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library); |
2512 | 2380 |
2513 /** | 2381 /** |
2514 * Returns the url from which a library was loaded. | 2382 * Returns the url from which a library was loaded. |
2515 */ | 2383 */ |
2516 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); | 2384 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); |
2517 | 2385 |
2518 /** | 2386 /** |
2519 * Returns a list of the names of all classes and interfaces declared | 2387 * Returns a list of the names of all classes and interfaces declared |
2520 * in a library. | 2388 * in a library. |
2521 * | 2389 * |
2522 * \return If no error occurs, a list of strings is returned. | 2390 * \return If no error occurs, a list of strings is returned. |
2523 * Otherwise an error handle is returned. | 2391 * Otherwise an error handle is returned. |
2524 */ | 2392 */ |
2525 DART_EXPORT Dart_Handle Dart_LibraryGetClassNames(Dart_Handle library); | 2393 DART_EXPORT Dart_Handle Dart_LibraryGetClassNames(Dart_Handle library); |
2526 | 2394 |
2527 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); | 2395 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); |
2528 // TODO(turnidge): Consider returning Dart_Null() when the library is | 2396 /* TODO(turnidge): Consider returning Dart_Null() when the library is |
2529 // not found to distinguish that from a true error case. | 2397 * not found to distinguish that from a true error case. */ |
2530 | 2398 |
2531 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 2399 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
2532 Dart_Handle source); | 2400 Dart_Handle source); |
2533 | 2401 |
2534 /** | 2402 /** |
2535 * Imports a library into another library, optionally with a prefix. | 2403 * Imports a library into another library, optionally with a prefix. |
2536 * If no prefix is required, an empty string or Dart_Null() can be | 2404 * If no prefix is required, an empty string or Dart_Null() can be |
2537 * supplied. | 2405 * supplied. |
2538 * | 2406 * |
2539 * \param library The library into which to import another library. | 2407 * \param library The library into which to import another library. |
(...skipping 11 matching lines...) Expand all Loading... |
2551 * | 2419 * |
2552 * \param library A library | 2420 * \param library A library |
2553 * \param url A url identifying the origin of the source | 2421 * \param url A url identifying the origin of the source |
2554 * \param source A string of Dart source | 2422 * \param source A string of Dart source |
2555 * | 2423 * |
2556 * \return A valid handle if no error occurs during the operation. | 2424 * \return A valid handle if no error occurs during the operation. |
2557 */ | 2425 */ |
2558 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 2426 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
2559 Dart_Handle url, | 2427 Dart_Handle url, |
2560 Dart_Handle source); | 2428 Dart_Handle source); |
2561 // TODO(turnidge): Rename to Dart_LibraryLoadSource? | 2429 /* TODO(turnidge): Rename to Dart_LibraryLoadSource? */ |
2562 | 2430 |
2563 | 2431 |
2564 /** | 2432 /** |
2565 * Loads a patch source string into a library. | 2433 * Loads a patch source string into a library. |
2566 * | 2434 * |
2567 * \param library A library | 2435 * \param library A library |
2568 * \param url A url identifying the origin of the patch source | 2436 * \param url A url identifying the origin of the patch source |
2569 * \param source A string of Dart patch source | 2437 * \param source A string of Dart patch source |
2570 */ | 2438 */ |
2571 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, | 2439 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, |
2572 Dart_Handle url, | 2440 Dart_Handle url, |
2573 Dart_Handle patch_source); | 2441 Dart_Handle patch_source); |
2574 | 2442 |
2575 /** | 2443 /** |
2576 * Sets the callback used to resolve native functions for a library. | 2444 * Sets the callback used to resolve native functions for a library. |
2577 * | 2445 * |
2578 * \param library A library. | 2446 * \param library A library. |
2579 * \param resolver A native entry resolver. | 2447 * \param resolver A native entry resolver. |
2580 * | 2448 * |
2581 * \return A valid handle if the native resolver was set successfully. | 2449 * \return A valid handle if the native resolver was set successfully. |
2582 */ | 2450 */ |
2583 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 2451 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
2584 Dart_Handle library, | 2452 Dart_Handle library, |
2585 Dart_NativeEntryResolver resolver); | 2453 Dart_NativeEntryResolver resolver); |
2586 // TODO(turnidge): Rename to Dart_LibrarySetNativeResolver? | 2454 /* TODO(turnidge): Rename to Dart_LibrarySetNativeResolver? */ |
2587 | 2455 |
2588 // --- Profiling support ---- | 2456 /* --- Profiling support ---- */ |
2589 | 2457 |
2590 // External pprof support for gathering and dumping symbolic | 2458 /* External pprof support for gathering and dumping symbolic |
2591 // information that can be used for better profile reports for | 2459 * information that can be used for better profile reports for |
2592 // dynamically generated code. | 2460 * dynamically generated code. */ |
2593 DART_EXPORT void Dart_InitPprofSupport(); | 2461 DART_EXPORT void Dart_InitPprofSupport(); |
2594 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); | 2462 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); |
2595 | 2463 |
2596 // Support for generating symbol maps for use by the Linux perf tool. | 2464 /* Support for generating symbol maps for use by the Linux perf tool. */ |
2597 DART_EXPORT void Dart_InitPerfEventsSupport(void* perf_events_file); | 2465 DART_EXPORT void Dart_InitPerfEventsSupport(void* perf_events_file); |
2598 | 2466 |
2599 // --- Heap Profiler --- | 2467 /* --- Heap Profiler --- */ |
2600 | 2468 |
2601 /** | 2469 /** |
2602 * Generates a heap profile. | 2470 * Generates a heap profile. |
2603 * | 2471 * |
2604 * \param callback A function pointer that will be repeatedly invoked | 2472 * \param callback A function pointer that will be repeatedly invoked |
2605 * with heap profile data. | 2473 * with heap profile data. |
2606 * \param stream A pointer that will be passed to the callback. This | 2474 * \param stream A pointer that will be passed to the callback. This |
2607 * is a convenient way to provide an open stream to the callback. | 2475 * is a convenient way to provide an open stream to the callback. |
2608 * | 2476 * |
2609 * \return Success if the heap profile is successful. | 2477 * \return Success if the heap profile is successful. |
2610 */ | 2478 */ |
2611 DART_EXPORT Dart_Handle Dart_HeapProfile(Dart_FileWriteCallback callback, | 2479 DART_EXPORT Dart_Handle Dart_HeapProfile(Dart_FileWriteCallback callback, |
2612 void* stream); | 2480 void* stream); |
2613 | 2481 |
2614 // --- Peers --- | 2482 /* --- Peers --- */ |
2615 | 2483 |
2616 /** | 2484 /** |
2617 * The peer field is a lazily allocated field intendend for storage of | 2485 * The peer field is a lazily allocated field intendend for storage of |
2618 * an uncommonly used values. Most instances types can have a peer | 2486 * an uncommonly used values. Most instances types can have a peer |
2619 * field allocated. The exceptions are subtypes of Null, num, and | 2487 * field allocated. The exceptions are subtypes of Null, num, and |
2620 * bool. | 2488 * bool. |
2621 */ | 2489 */ |
2622 | 2490 |
2623 /** | 2491 /** |
2624 * Returns the value of peer field of 'object' in 'peer'. | 2492 * Returns the value of peer field of 'object' in 'peer'. |
(...skipping 12 matching lines...) Expand all Loading... |
2637 * 'peer'. | 2505 * 'peer'. |
2638 * | 2506 * |
2639 * \param object An object. | 2507 * \param object An object. |
2640 * \param peer A value to store in the peer field. | 2508 * \param peer A value to store in the peer field. |
2641 * | 2509 * |
2642 * \return Returns an error if 'object' is a subtype of Null, num, or | 2510 * \return Returns an error if 'object' is a subtype of Null, num, or |
2643 * bool. | 2511 * bool. |
2644 */ | 2512 */ |
2645 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); | 2513 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); |
2646 | 2514 |
2647 #endif // INCLUDE_DART_API_H_ | 2515 /* --- Message sending/receiving from native code ---- */ |
| 2516 |
| 2517 /** |
| 2518 * A Dart_CObject is used for representing Dart objects as native C |
| 2519 * data outside the Dart heap. These objects are totally detached from |
| 2520 * the Dart heap. Only a subset of the Dart objects have a |
| 2521 * representation as a Dart_CObject. |
| 2522 * |
| 2523 * The string encoding in the 'value.as_string' is UTF-8. |
| 2524 * |
| 2525 * All the different types from dart:typed_data are exposed as type |
| 2526 * kTypedData. The specific type from dart:typed_data is in the type |
| 2527 * field of the as_typed_data structure. The length in the |
| 2528 * as_typed_data structure is always in bytes. |
| 2529 */ |
| 2530 typedef enum { |
| 2531 Dart_CObject_kNull = 0, |
| 2532 Dart_CObject_kBool, |
| 2533 Dart_CObject_kInt32, |
| 2534 Dart_CObject_kInt64, |
| 2535 Dart_CObject_kBigint, |
| 2536 Dart_CObject_kDouble, |
| 2537 Dart_CObject_kString, |
| 2538 Dart_CObject_kArray, |
| 2539 Dart_CObject_kTypedData, |
| 2540 Dart_CObject_kExternalTypedData, |
| 2541 Dart_CObject_kUnsupported, |
| 2542 Dart_CObject_kNumberOfTypes |
| 2543 } Dart_CObject_Type; |
| 2544 |
| 2545 typedef struct _Dart_CObject { |
| 2546 Dart_CObject_Type type; |
| 2547 union { |
| 2548 bool as_bool; |
| 2549 int32_t as_int32; |
| 2550 int64_t as_int64; |
| 2551 double as_double; |
| 2552 char* as_string; |
| 2553 char* as_bigint; |
| 2554 struct { |
| 2555 int length; |
| 2556 struct _Dart_CObject** values; |
| 2557 } as_array; |
| 2558 struct { |
| 2559 Dart_TypedData_Type type; |
| 2560 int length; |
| 2561 uint8_t* values; |
| 2562 } as_typed_data; |
| 2563 struct { |
| 2564 Dart_TypedData_Type type; |
| 2565 int length; |
| 2566 uint8_t* data; |
| 2567 void* peer; |
| 2568 Dart_WeakPersistentHandleFinalizer callback; |
| 2569 } as_external_typed_data; |
| 2570 } value; |
| 2571 } Dart_CObject; |
| 2572 |
| 2573 /** |
| 2574 * Posts a message on some port. The message will contain the |
| 2575 * Dart_CObject object graph rooted in 'message'. |
| 2576 * |
| 2577 * While the message is being sent the state of the graph of |
| 2578 * Dart_CObject structures rooted in 'message' should not be accessed, |
| 2579 * as the message generation will make temporary modifications to the |
| 2580 * data. When the message has been sent the graph will be fully |
| 2581 * restored. |
| 2582 * |
| 2583 * \param port_id The destination port. |
| 2584 * \param message The message to send. |
| 2585 * |
| 2586 * \return True if the message was posted. |
| 2587 */ |
| 2588 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message); |
| 2589 |
| 2590 /** |
| 2591 * A native message handler. |
| 2592 * |
| 2593 * This handler is associated with a native port by calling |
| 2594 * Dart_NewNativePort. |
| 2595 * |
| 2596 * The message received is decoded into the message structure. The |
| 2597 * lifetime of the message data is controlled by the caller. All the |
| 2598 * data references from the message are allocated by the caller and |
| 2599 * will be reclaimed when returning to it. |
| 2600 */ |
| 2601 |
| 2602 typedef void (*Dart_NativeMessageHandler)(Dart_Port dest_port_id, |
| 2603 Dart_Port reply_port_id, |
| 2604 Dart_CObject* message); |
| 2605 |
| 2606 /** |
| 2607 * Creates a new native port. When messages are received on this |
| 2608 * native port, then they will be dispatched to the provided native |
| 2609 * message handler. |
| 2610 * |
| 2611 * \param name The name of this port in debugging messages. |
| 2612 * \param handler The C handler to run when messages arrive on the port. |
| 2613 * \param handle_concurrently Is it okay to process requests on this |
| 2614 * native port concurrently? |
| 2615 * |
| 2616 * \return If successful, returns the port id for the native port. In |
| 2617 * case of error, returns ILLEGAL_PORT. |
| 2618 */ |
| 2619 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
| 2620 Dart_NativeMessageHandler handler, |
| 2621 bool handle_concurrently); |
| 2622 /* TODO(turnidge): Currently handle_concurrently is ignored. */ |
| 2623 |
| 2624 /** |
| 2625 * Closes the native port with the given id. |
| 2626 * |
| 2627 * The port must have been allocated by a call to Dart_NewNativePort. |
| 2628 * |
| 2629 * \param native_port_id The id of the native port to close. |
| 2630 * |
| 2631 * \return Returns true if the port was closed successfully. |
| 2632 */ |
| 2633 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id); |
| 2634 |
| 2635 #endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ |
OLD | NEW |