Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: runtime/include/dart_api.h

Issue 8501034: Deal with unhandled exceptions the same way in all Dart api functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef INCLUDE_DART_API_H_ 5 #ifndef INCLUDE_DART_API_H_
6 #define INCLUDE_DART_API_H_ 6 #define INCLUDE_DART_API_H_
7 7
8 /** \mainpage Dart Embedding API Reference 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 /** 57 /**
58 * An object reference managed by the Dart VM garbage collector. 58 * An object reference managed by the Dart VM garbage collector.
59 * 59 *
60 * Because the garbage collector may move objects, it is unsafe to 60 * Because the garbage collector may move objects, it is unsafe to
61 * refer to objects directly. Instead, we refer to objects through 61 * refer to objects directly. Instead, we refer to objects through
62 * handles, which are known to the garbage collector and updated 62 * handles, which are known to the garbage collector and updated
63 * automatically when the object is moved. Handles should be passed 63 * automatically when the object is moved. Handles should be passed
64 * by value (except in cases like out-parameters) and should never be 64 * by value (except in cases like out-parameters) and should never be
65 * allocated on the heap. 65 * allocated on the heap.
66 * 66 *
67 * A handle may either be valid or invalid. Valid handles refer to a 67 * Most functions in the Dart Embedding API return a handle. When a
68 * object in the Dart VM heap. Note that a valid handle may in some 68 * function completes normally, this will be a valid handle to an
69 * cases refer to null or an unhandled exception. Invalid handles are 69 * object in the Dart VM heap. This handle may represent the result of
70 * returned by many Dart api functions when they encounter an error. 70 * the operation or it may be a special valid handle used merely to
71 * Invalid handles have an associated error message. 71 * indicate successful completion. Note that a valid handle may in
72 * some cases refer to the null object.
73 *
74 * When a function encounters a problem that prevents it from
75 * completing normally, it returns an error handle (See Dart_IsError).
76 * An error handle has an associated error message that gives more
77 * details about the problem (See Dart_GetError).
78 *
79 * When an unhandled exception occurs, it is returned as a special
80 * kind of error handle (See Dart_IsUnhandledException). This error
81 * handle retains information about the exception and the stack trace
82 * (See Dart_GetException, Dart_GetStacktrace, Dart_RethrowException).
72 * 83 *
73 * Local handles are allocated within the current scope (see 84 * Local handles are allocated within the current scope (see
74 * Dart_EnterScope) and go away when the current scope exits. Unless 85 * Dart_EnterScope) and go away when the current scope exits. Unless
75 * otherwise indicated, all functions in the Dart embedding api return 86 * otherwise indicated, callers should assume that all functions in
76 * local handles. 87 * the Dart embedding api return local handles.
77 * 88 *
78 * Persistent handles are allocated within the current isolate. They 89 * Persistent handles are allocated within the current isolate. They
79 * can be used to store objects across scopes. Persistent handles 90 * can be used to store objects across scopes. Persistent handles have
80 * need to be explicitly deallocated when they are no longer needed. 91 * the lifetime of the current isolate unless they are explicitly
92 * deallocated (see Dart_DeletePersistentHandle).
81 */ 93 */
82 typedef void* Dart_Handle; 94 typedef void* Dart_Handle;
83 95
84 /** 96 /**
85 * Is this handle valid? 97 * Is this an error handle?
86 * 98 *
87 * Requires there to be a current isolate. 99 * Requires there to be a current isolate.
88 */ 100 */
89 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle); 101 DART_EXPORT bool Dart_IsError(const Dart_Handle& handle);
90
91 // Internal routine used for reporting invalid handles.
92 DART_EXPORT void _Dart_ReportInvalidHandle(const char* file,
93 int line,
94 const char* handle_string,
95 const char* error);
96 102
97 /** 103 /**
98 * Aborts the process if 'handle' is invalid. 104 * Gets the error message from an error handle.
99 *
100 * Provided for convenience.
101 */
102 #define DART_CHECK_VALID(handle) \
103 if (!Dart_IsValid((handle))) { \
104 _Dart_ReportInvalidHandle(__FILE__, __LINE__, \
105 #handle, Dart_GetError(handle)); \
106 }
107
108 /**
109 * Gets the error message from an invalid handle.
110 * 105 *
111 * Requires there to be a current isolate. 106 * Requires there to be a current isolate.
112 * 107 *
113 * \return A C string containing an error message if the handle is 108 * \return A C string containing an error message if the handle is
114 * invalid. An empty C string ("") if the handle is valid. This C 109 * error. An empty C string ("") if the handle is valid. This C
115 * String is scope allocated and is only valid until the next call 110 * String is scope allocated and is only valid until the next call
116 * to Dart_ExitScope. 111 * to Dart_ExitScope.
117 */ 112 */
118 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle); 113 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle);
119 114
120 /** 115 /**
121 * Produces an invalid handle with the provided error message. 116 * Is this an error handle for an unhandled exception?
117 */
118 DART_EXPORT bool Dart_IsUnhandledException(Dart_Handle handle);
119
120 /**
121 * Gets the exception Object from an unhandled exception error handle.
122 */
123 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle handle);
124
125 /**
126 * Gets the stack trace Object from an unhandled exception error handle.
127 */
128 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle handle);
129
130 /**
131 * Produces an error handle with the provided error message.
122 * 132 *
123 * Requires there to be a current isolate. 133 * Requires there to be a current isolate.
124 * 134 *
125 * \param error A C string containing an error message. 135 * \param error A C string containing an error message.
126 */ 136 */
127 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...); 137 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...);
128 138
139 // Internal routine used for reporting error handles.
140 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
141 int line,
Anton Muhin 2011/11/09 12:34:03 nit: you may want to fix indentation: cf. const ch
turnidge 2011/11/09 19:53:41 Done.
142 const char* handle_string,
143 const char* error);
144
145 /**
146 * Aborts the process if 'handle' is an error handle.
147 *
148 * Provided for convenience.
149 */
150 #define DART_CHECK_VALID(handle) \
151 if (Dart_IsError((handle))) { \
152 _Dart_ReportErrorHandle(__FILE__, __LINE__, \
153 #handle, Dart_GetError(handle)); \
154 }
155
129 /** 156 /**
130 * Converts an object to a string. 157 * Converts an object to a string.
131 * 158 *
132 * If an exception occurs during the conversion, this is treated as an 159 * May generate an unhandled exception error.
133 * error.
134 * 160 *
135 * \return A handle to the converted string if no errors occur during 161 * \return A handle to the converted string if no error occurs during
136 * the conversion. If an error does occur, an invalid handle is 162 * the conversion. If an error does occur, an error handle is
137 * returned. 163 * returned.
138 */ 164 */
139 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object); 165 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object);
140 166
141 /** 167 /**
142 * Checks if the two objects are the same object 168 * Checks if the two objects are the same object
143 * 169 *
144 * The result of the comparison is returned through the 'same' 170 * The result of the comparison is returned through the 'same'
145 * parameter. The return value itself is used to indicate success or 171 * parameter. The return value itself is used to indicate success or
146 * failure, not identity. 172 * failure, not identity.
147 * 173 *
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 263
238 /** 264 /**
239 * An isolate is the unit of concurrency in Dart. Each isolate has 265 * An isolate is the unit of concurrency in Dart. Each isolate has
240 * its own memory and thread of control. No state is shared between 266 * its own memory and thread of control. No state is shared between
241 * isolates. Instead, isolates communicate by message passing. 267 * isolates. Instead, isolates communicate by message passing.
242 * 268 *
243 * Each thread keeps track of its current isolate, which is the 269 * Each thread keeps track of its current isolate, which is the
244 * isolate which is ready to execute on the current thread. The 270 * isolate which is ready to execute on the current thread. The
245 * current isolate may be NULL, in which case no isolate is ready to 271 * current isolate may be NULL, in which case no isolate is ready to
246 * execute. Most of the Dart apis require there to be a current 272 * execute. Most of the Dart apis require there to be a current
247 * isolate in order to function without error. The current isolate is 273 * isolate in order to function without error. The current isolate is
248 * set by any call to Dart_CreateIsolate or Dart_EnterIsolate. 274 * set by any call to Dart_CreateIsolate or Dart_EnterIsolate.
249 */ 275 */
250 typedef void* Dart_Isolate; 276 typedef void* Dart_Isolate;
251 277
252 /** 278 /**
253 * A buffer containing a snapshot of the Dart VM. A snapshot can be 279 * A buffer containing a snapshot of the Dart VM. A snapshot can be
254 * used to restore the VM quickly to a saved state and is useful for 280 * used to restore the VM quickly to a saved state and is useful for
255 * fast startup. 281 * fast startup.
256 */ 282 */
257 typedef void Dart_Snapshot; 283 typedef void Dart_Snapshot;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 DART_EXPORT Dart_Isolate Dart_CurrentIsolate(); 317 DART_EXPORT Dart_Isolate Dart_CurrentIsolate();
292 318
293 /** 319 /**
294 * Enters an isolate. After calling this function, 320 * Enters an isolate. After calling this function,
295 * the current isolate will be set to the provided isolate. 321 * the current isolate will be set to the provided isolate.
296 * 322 *
297 * Requires there to be no current isolate. 323 * Requires there to be no current isolate.
298 */ 324 */
299 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate); 325 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate);
300 // TODO(turnidge): Describe what happens if two threads attempt to 326 // TODO(turnidge): Describe what happens if two threads attempt to
301 // enter the same isolate simultaneously. Check for this in the code. 327 // enter the same isolate simultaneously. Check for this in the code.
302 // Describe whether isolates are allowed to migrate. 328 // Describe whether isolates are allowed to migrate.
303 329
304 /** 330 /**
305 * Exits an isolate. After this call, Dart_CurrentIsolate will 331 * Exits an isolate. After this call, Dart_CurrentIsolate will
306 * return NULL. 332 * return NULL.
307 * 333 *
308 * Requires there to be a current isolate. 334 * Requires there to be a current isolate.
309 */ 335 */
310 DART_EXPORT void Dart_ExitIsolate(); 336 DART_EXPORT void Dart_ExitIsolate();
311 // TODO(turnidge): We don't want users of the api to be able to exit a 337 // TODO(turnidge): We don't want users of the api to be able to exit a
312 // "pure" dart isolate. Implement and document. 338 // "pure" dart isolate. Implement and document.
313 339
314 /** 340 /**
315 * Creates a snapshot of the state of the current isolate. 341 * Creates a snapshot of the state of the current isolate.
316 */ 342 */
317 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snaphot_buffer, 343 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snaphot_buffer,
318 intptr_t* snapshot_size); 344 intptr_t* snapshot_size);
319 // TODO(turnidge): Does this include the current script or only libs? 345 // TODO(turnidge): Does this include the current script or only libs?
320 // is it possible to take a snapshot and load more scripts into it? 346 // is it possible to take a snapshot and load more scripts into it?
321 347
322 // --- Messages and Ports --- 348 // --- Messages and Ports ---
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 */ 405 */
380 DART_EXPORT void Dart_SetMessageCallbacks( 406 DART_EXPORT void Dart_SetMessageCallbacks(
381 Dart_PostMessageCallback post_message_callback, 407 Dart_PostMessageCallback post_message_callback,
382 Dart_ClosePortCallback close_port_callback); 408 Dart_ClosePortCallback close_port_callback);
383 // TODO(turnidge): Consider moving this to isolate creation so that it 409 // TODO(turnidge): Consider moving this to isolate creation so that it
384 // is impossible to mess up. 410 // is impossible to mess up.
385 411
386 /** 412 /**
387 * Handles a message on the current isolate. 413 * Handles a message on the current isolate.
388 * 414 *
415 * May generate an unhandled exception error.
416 *
389 * Note that this function does not free the memory associated with 417 * Note that this function does not free the memory associated with
390 * 'dart_message'. 418 * 'dart_message'.
419 *
420 * \return A valid handle if no error occurs during the operation.
391 */ 421 */
392 DART_EXPORT void Dart_HandleMessage(Dart_Port dest_port, 422 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port,
393 Dart_Port reply_port, 423 Dart_Port reply_port,
394 Dart_Message dart_message); 424 Dart_Message dart_message);
395 // TODO(turnidge): Revisit memory management of 'dart_message'. 425 // TODO(turnidge): Revisit memory management of 'dart_message'.
396 426
397 /** 427 /**
398 * Processes any incoming messages for the current isolate. 428 * Processes any incoming messages for the current isolate.
399 * 429 *
400 * This function may only be used when the embedder has not provided 430 * This function may only be used when the embedder has not provided
401 * an alternate message delivery mechanism with 431 * an alternate message delivery mechanism with
402 * Dart_SetMessageCallbacks. It is provided for convenience. 432 * Dart_SetMessageCallbacks. It is provided for convenience.
403 * 433 *
404 * This function waits for incoming messages for the current 434 * This function waits for incoming messages for the current
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 */ 506 */
477 DART_EXPORT bool Dart_IsNull(Dart_Handle object); 507 DART_EXPORT bool Dart_IsNull(Dart_Handle object);
478 508
479 /** 509 /**
480 * Checks if the two objects are equal. 510 * Checks if the two objects are equal.
481 * 511 *
482 * The result of the comparison is returned through the 'equal' 512 * The result of the comparison is returned through the 'equal'
483 * parameter. The return value itself is used to indicate success or 513 * parameter. The return value itself is used to indicate success or
484 * failure, not equality. 514 * failure, not equality.
485 * 515 *
516 * May generate an unhandled exception error.
517 *
486 * \param obj1 An object to be compared. 518 * \param obj1 An object to be compared.
487 * \param obj2 An object to be compared. 519 * \param obj2 An object to be compared.
488 * \param equal Returns the result of the equality comparison. 520 * \param equal Returns the result of the equality comparison.
489 * 521 *
490 * \return A valid handle if no error occurs during the comparison. 522 * \return A valid handle if no error occurs during the comparison.
491 */ 523 */
492 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, 524 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1,
493 Dart_Handle obj2, 525 Dart_Handle obj2,
494 bool* equal); 526 bool* equal);
495 527
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 * \return A valid handle if no error occurs during the operation. 564 * \return A valid handle if no error occurs during the operation.
533 */ 565 */
534 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 566 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
535 bool* fits); 567 bool* fits);
536 568
537 /** 569 /**
538 * Returns an Integer with the provided value. 570 * Returns an Integer with the provided value.
539 * 571 *
540 * \param value The value of the integer. 572 * \param value The value of the integer.
541 * 573 *
542 * \return The Integer object if no errors occurs. Otherwise returns 574 * \return The Integer object if no error occurs. Otherwise returns
543 * an invalid handle. 575 * an error handle.
544 */ 576 */
545 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value); 577 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value);
546 578
547 /** 579 /**
548 * Returns an Integer with the provided value. 580 * Returns an Integer with the provided value.
549 * 581 *
550 * \param value The value of the integer represented as a C string 582 * \param value The value of the integer represented as a C string
551 * containing a hexadecimal number. 583 * containing a hexadecimal number.
552 * 584 *
553 * \return The Integer object if no errors occurs. Otherwise returns 585 * \return The Integer object if no error occurs. Otherwise returns
554 * an invalid handle. 586 * an error handle.
555 */ 587 */
556 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* value); 588 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* value);
557 589
558 /** 590 /**
559 * Gets the value of an Integer. 591 * Gets the value of an Integer.
560 * 592 *
561 * The integer must fit into a 64-bit signed integer, otherwise an error occurs. 593 * The integer must fit into a 64-bit signed integer, otherwise an error occurs.
562 * 594 *
563 * \param integer An Integer. 595 * \param integer An Integer.
564 * \param value Returns the value of the Integer. 596 * \param value Returns the value of the Integer.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 /** 635 /**
604 * Is this object a Boolean? 636 * Is this object a Boolean?
605 */ 637 */
606 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object); 638 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object);
607 639
608 /** 640 /**
609 * Returns a Boolean with the provided value. 641 * Returns a Boolean with the provided value.
610 * 642 *
611 * \param value true or false. 643 * \param value true or false.
612 * 644 *
613 * \return The Boolean object if no errors occurs. Otherwise returns 645 * \return The Boolean object if no error occurs. Otherwise returns
614 * an invalid handle. 646 * an error handle.
615 */ 647 */
616 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value); 648 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value);
617 649
618 /** 650 /**
619 * Gets the value of a Boolean 651 * Gets the value of a Boolean
620 * 652 *
621 * \param bool_object A Boolean 653 * \param bool_object A Boolean
622 * \param value Returns the value of the Boolean. 654 * \param value Returns the value of the Boolean.
623 * 655 *
624 * \return A valid handle if no error occurs during the operation. 656 * \return A valid handle if no error occurs during the operation.
625 */ 657 */
626 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, bool* value); 658 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, bool* value);
627 659
628 // --- Doubles --- 660 // --- Doubles ---
629 661
630 /** 662 /**
631 * Is this object a Double? 663 * Is this object a Double?
632 */ 664 */
633 DART_EXPORT bool Dart_IsDouble(Dart_Handle object); 665 DART_EXPORT bool Dart_IsDouble(Dart_Handle object);
634 666
635 /** 667 /**
636 * Returns a Double with the provided value. 668 * Returns a Double with the provided value.
637 * 669 *
638 * \param value A double. 670 * \param value A double.
639 * 671 *
640 * \return The Double object if no errors occurs. Otherwise returns 672 * \return The Double object if no error occurs. Otherwise returns
641 * an invalid handle. 673 * an error handle.
642 */ 674 */
643 DART_EXPORT Dart_Handle Dart_NewDouble(double value); 675 DART_EXPORT Dart_Handle Dart_NewDouble(double value);
644 676
645 /** 677 /**
646 * Gets the value of a Double 678 * Gets the value of a Double
647 * 679 *
648 * \param bool_object A Double 680 * \param bool_object A Double
649 * \param value Returns the value of the Double. 681 * \param value Returns the value of the Double.
650 * 682 *
651 * \return A valid handle if no error occurs during the operation. 683 * \return A valid handle if no error occurs during the operation.
(...skipping 25 matching lines...) Expand all
677 * 709 *
678 * \return A valid handle if no error occurs during the operation. 710 * \return A valid handle if no error occurs during the operation.
679 */ 711 */
680 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); 712 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length);
681 713
682 /** 714 /**
683 * Returns a String built from the provided C string 715 * Returns a String built from the provided C string
684 * 716 *
685 * \param value A C String 717 * \param value A C String
686 * 718 *
687 * \return The String object if no errors occurs. Otherwise returns 719 * \return The String object if no error occurs. Otherwise returns
688 * an invalid handle. 720 * an error handle.
689 */ 721 */
690 DART_EXPORT Dart_Handle Dart_NewString(const char* str); 722 DART_EXPORT Dart_Handle Dart_NewString(const char* str);
691 723
692 /** 724 /**
693 * Returns a String built from an array of 8-bit codepoints. 725 * Returns a String built from an array of 8-bit codepoints.
694 * 726 *
695 * \param value An array of 8-bit codepoints. 727 * \param value An array of 8-bit codepoints.
696 * \param length The length of the codepoints array. 728 * \param length The length of the codepoints array.
697 * 729 *
698 * \return The String object if no errors occurs. Otherwise returns 730 * \return The String object if no error occurs. Otherwise returns
699 * an invalid handle. 731 * an error handle.
700 */ 732 */
701 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, 733 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints,
702 intptr_t length); 734 intptr_t length);
703 735
704 /** 736 /**
705 * Returns a String built from an array of 16-bit codepoints. 737 * Returns a String built from an array of 16-bit codepoints.
706 * 738 *
707 * \param value An array of 16-bit codepoints. 739 * \param value An array of 16-bit codepoints.
708 * \param length The length of the codepoints array. 740 * \param length The length of the codepoints array.
709 * 741 *
710 * \return The String object if no errors occurs. Otherwise returns 742 * \return The String object if no error occurs. Otherwise returns
711 * an invalid handle. 743 * an error handle.
712 */ 744 */
713 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, 745 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints,
714 intptr_t length); 746 intptr_t length);
715 747
716 /** 748 /**
717 * Returns a String built from an array of 32-bit codepoints. 749 * Returns a String built from an array of 32-bit codepoints.
718 * 750 *
719 * \param value An array of 32-bit codepoints. 751 * \param value An array of 32-bit codepoints.
720 * \param length The length of the codepoints array. 752 * \param length The length of the codepoints array.
721 * 753 *
722 * \return The String object if no errors occurs. Otherwise returns 754 * \return The String object if no error occurs. Otherwise returns
723 * an invalid handle. 755 * an error handle.
724 */ 756 */
725 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 757 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
726 intptr_t length); 758 intptr_t length);
727 759
728 /** 760 /**
729 * Gets the codepoints from a String. 761 * Gets the codepoints from a String.
730 * 762 *
731 * This function is only valid on strings for which Dart_IsString8 is 763 * This function is only valid on strings for which Dart_IsString8 is
732 * true. Otherwise an error occurs. 764 * true. Otherwise an error occurs.
733 * 765 *
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 /** 828 /**
797 * Is this object a List? 829 * Is this object a List?
798 */ 830 */
799 DART_EXPORT bool Dart_IsList(Dart_Handle object); 831 DART_EXPORT bool Dart_IsList(Dart_Handle object);
800 832
801 /** 833 /**
802 * Returns a List of the desired length. 834 * Returns a List of the desired length.
803 * 835 *
804 * \param length The length of the list. 836 * \param length The length of the list.
805 * 837 *
806 * \return The List object if no errors occurs. Otherwise returns 838 * \return The List object if no error occurs. Otherwise returns
807 * an invalid handle. 839 * an error handle.
808 */ 840 */
809 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length); 841 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length);
810 842
811 /** 843 /**
812 * Gets the length of a List. 844 * Gets the length of a List.
813 * 845 *
846 * May generate an unhandled exception error.
Anton Muhin 2011/11/09 12:34:03 I am slightly concerned with tagging API functions
turnidge 2011/11/09 19:53:41 I see your point. We don't want to have our hands
Ivan Posva 2011/11/10 18:05:46 Until we have a better place to stick this kind of
turnidge 2011/11/10 20:59:13 Okay. Leaving as is for now.
847 *
814 * \param list A List. 848 * \param list A List.
815 * \param length Returns the length of the List. 849 * \param length Returns the length of the List.
816 * 850 *
817 * \return A valid handle if no error occurs during the operation. 851 * \return A valid handle if no error occurs during the operation.
818 */ 852 */
819 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* length); 853 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* length);
820 854
821 /** 855 /**
822 * Gets the Object at some index of a List. 856 * Gets the Object at some index of a List.
823 * 857 *
824 * If the index is out of bounds, an error occurs. 858 * If the index is out of bounds, an error occurs.
825 * 859 *
860 * May generate an unhandled exception error.
861 *
826 * \param list A List. 862 * \param list A List.
827 * \param index A valid index into the List. 863 * \param index A valid index into the List.
828 * 864 *
829 * \return The Object in the List at the specified index if no errors 865 * \return The Object in the List at the specified index if no errors
830 * occurs. Otherwise returns an invalid handle. 866 * occurs. Otherwise returns an error handle.
831 */ 867 */
832 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, 868 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list,
833 intptr_t index); 869 intptr_t index);
834 870
835 /** 871 /**
836 * Sets the Object at some index of a List. 872 * Sets the Object at some index of a List.
837 * 873 *
838 * If the index is out of bounds, an error occurs. 874 * If the index is out of bounds, an error occurs.
839 * 875 *
876 * May generate an unhandled exception error.
877 *
840 * \param array A List. 878 * \param array A List.
841 * \param index A valid index into the List. 879 * \param index A valid index into the List.
842 * \param value The Object to put in the List. 880 * \param value The Object to put in the List.
843 * 881 *
844 * \return A valid handle if no error occurs during the operation. 882 * \return A valid handle if no error occurs during the operation.
845 */ 883 */
846 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 884 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
847 intptr_t index, 885 intptr_t index,
848 Dart_Handle value); 886 Dart_Handle value);
849 887
888 /**
889 * May generate an unhandled exception error.
890 */
850 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, 891 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list,
851 intptr_t offset, 892 intptr_t offset,
852 uint8_t* native_array, 893 uint8_t* native_array,
853 intptr_t length); 894 intptr_t length);
854 895
896 /**
897 * May generate an unhandled exception error.
898 */
855 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, 899 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list,
856 intptr_t offset, 900 intptr_t offset,
857 uint8_t* native_array, 901 uint8_t* native_array,
858 intptr_t length); 902 intptr_t length);
859 903
860 // --- Closures --- 904 // --- Closures ---
861 905
862 /** 906 /**
863 * Is this object a Closure? 907 * Is this object a Closure?
864 */ 908 */
865 DART_EXPORT bool Dart_IsClosure(Dart_Handle object); 909 DART_EXPORT bool Dart_IsClosure(Dart_Handle object);
866 910
867 /** 911 /**
868 * Invokes a Closure with the given arguments. 912 * Invokes a Closure with the given arguments.
869 * 913 *
914 * May generate an unhandled exception error.
915 *
870 * \return If no error occurs during execution, then the result of 916 * \return If no error occurs during execution, then the result of
871 * invoking the closure is returned. Note that this may be an 917 * invoking the closure is returned. If an error occurs during
872 * uncaught exception (see Dart_ExceptionOccurred) or the null 918 * execution, then an error handle is returned.
873 * Object. If an error occurred during execution, then an invalid
874 * handle is returned.
875 */ 919 */
876 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 920 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
877 int number_of_arguments, 921 int number_of_arguments,
878 Dart_Handle* arguments); 922 Dart_Handle* arguments);
879 923
880 // DEPRECATED: The API below is a temporary hack. 924 // DEPRECATED: The API below is a temporary hack.
881 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object); 925 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object);
882 926
883 // DEPRECATED: The API below is a temporary hack. 927 // DEPRECATED: The API below is a temporary hack.
884 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value); 928 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value);
885 929
886 // --- Methods and Fields --- 930 // --- Methods and Fields ---
887 931
888 /** 932 /**
889 * Invokes a static method with the given arguments. 933 * Invokes a static method with the given arguments.
890 * 934 *
935 * May generate an unhandled exception error.
936 *
891 * \return If no error occurs during execution, then the result of 937 * \return If no error occurs during execution, then the result of
892 * invoking the closure is returned. Note that this may be an 938 * invoking the method is returned. If an error occurs during
893 * uncaught exception (see Dart_ExceptionOccurred) or the null 939 * execution, then an error handle is returned.
894 * Object. If an error occurred during execution, then an invalid
895 * handle is returned.
896 */ 940 */
897 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library, 941 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library,
898 Dart_Handle class_name, 942 Dart_Handle class_name,
899 Dart_Handle function_name, 943 Dart_Handle function_name,
900 int number_of_arguments, 944 int number_of_arguments,
901 Dart_Handle* arguments); 945 Dart_Handle* arguments);
902 946
903 /** 947 /**
904 * Invokes an instance method with the given arguments. 948 * Invokes an instance method with the given arguments.
905 * 949 *
950 * May generate an unhandled exception error.
951 *
906 * \return If no error occurs during execution, then the result of 952 * \return If no error occurs during execution, then the result of
907 * invoking the closure is returned. Note that this may be an 953 * invoking the method is returned. If an error occurs during
908 * uncaught exception (see Dart_ExceptionOccurred) or the null 954 * execution, then an error handle is returned.
909 * Object. If an error occurred during execution, then an invalid
910 * handle is returned.
911 */ 955 */
912 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle receiver, 956 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle receiver,
913 Dart_Handle function_name, 957 Dart_Handle function_name,
914 int number_of_arguments, 958 int number_of_arguments,
915 Dart_Handle* arguments); 959 Dart_Handle* arguments);
916 960
917 /** 961 /**
918 * Gets the value of a static field. 962 * Gets the value of a static field.
919 * 963 *
964 * May generate an unhandled exception error.
965 *
920 * \return If no error occurs, then the value of the field is 966 * \return If no error occurs, then the value of the field is
921 * returned. Otherwise an invalid handle is returned. 967 * returned. Otherwise an error handle is returned.
922 */ 968 */
923 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, Dart_Handle name); 969 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, Dart_Handle name);
924 970
925 /** 971 /**
926 * Sets the value of a static field. 972 * Sets the value of a static field.
927 * 973 *
974 * May generate an unhandled exception error.
975 *
928 * \return A valid handle if no error occurs. 976 * \return A valid handle if no error occurs.
929 */ 977 */
930 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, 978 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
931 Dart_Handle name, 979 Dart_Handle name,
932 Dart_Handle value); 980 Dart_Handle value);
981
933 /** 982 /**
934 * Gets the value of an instance field. 983 * Gets the value of an instance field.
935 * 984 *
985 * May generate an unhandled exception error.
986 *
936 * \return If no error occurs, then the value of the field is 987 * \return If no error occurs, then the value of the field is
937 * returned. Otherwise an invalid handle is returned. 988 * returned. Otherwise an error handle is returned.
938 */ 989 */
939 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, 990 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj,
940 Dart_Handle name); 991 Dart_Handle name);
941 /** 992 /**
942 * Sets the value of an instance field. 993 * Sets the value of an instance field.
943 * 994 *
995 * May generate an unhandled exception error.
996 *
944 * \return A valid handle if no error occurs. 997 * \return A valid handle if no error occurs.
945 */ 998 */
946 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, 999 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
947 Dart_Handle name, 1000 Dart_Handle name,
948 Dart_Handle value); 1001 Dart_Handle value);
949 1002
950 /** 1003 /**
951 * Creates a native wrapper class. 1004 * Creates a native wrapper class.
952 * 1005 *
953 * TODO(turnidge): Document. 1006 * TODO(turnidge): Document.
(...skipping 15 matching lines...) Expand all
969 * 1022 *
970 * TODO(turnidge): Document. 1023 * TODO(turnidge): Document.
971 */ 1024 */
972 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, 1025 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
973 int index, 1026 int index,
974 intptr_t value); 1027 intptr_t value);
975 1028
976 // --- Exceptions ---- 1029 // --- Exceptions ----
977 1030
978 /** 1031 /**
979 * Does this handle hold information about an unhandled exception?
980 */
981 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle handle);
982 // TODO(turnidge): Consider exposing the name of this thing. Maybe
983 // IsUnhandledException, IsUncaughtException, or IsThrownException.
984 // It is like a regular exception, but plus a stack trace.
985 // TODO(turnidge): Consider subsuming exception results into invalid
986 // handles so that only one error check needs to be done after method
987 // invocation.
988
989 /**
990 * Gets the exception Object from an unhandled exception.
991 */
992 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result);
993
994 /**
995 * Gets the stack trace Object from an unhandled exception.
996 */
997 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_exception);
998
999 /**
1000 * Throws an exception. 1032 * Throws an exception.
1001 * 1033 *
1002 * Throws an exception, unwinding all dart frames on the stack. If 1034 * Throws an exception, unwinding all dart frames on the stack. If
1003 * successful, this function does not return. Note that this means 1035 * successful, this function does not return. Note that this means
1004 * that the destructors of any stack-allocated C++ objects will not be 1036 * that the destructors of any stack-allocated C++ objects will not be
1005 * called. If there are no Dart frames on the stack, an error occurs. 1037 * called. If there are no Dart frames on the stack, an error occurs.
1006 * 1038 *
1007 * \return An invalid handle if the exception was not thrown. 1039 * \return An error handle if the exception was not thrown.
1008 * Otherwise the function does not return. 1040 * Otherwise the function does not return.
1009 */ 1041 */
1010 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception); 1042 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception);
1011 1043
1012 /** 1044 /**
1013 * Rethrows an exception. 1045 * Rethrows an exception.
1014 * 1046 *
1015 * Rethrows an exception, unwinding all dart frames on the stack. If 1047 * Rethrows an exception, unwinding all dart frames on the stack. If
1016 * successful, this function does not return. Note that this means 1048 * successful, this function does not return. Note that this means
1017 * that the destructors of any stack-allocated C++ objects will not be 1049 * that the destructors of any stack-allocated C++ objects will not be
1018 * called. If there are no Dart frames on the stack, an error occurs. 1050 * called. If there are no Dart frames on the stack, an error occurs.
1019 * 1051 *
1020 * \return An invalid handle if the exception was not thrown. 1052 * \return An error handle if the exception was not thrown.
1021 * Otherwise the function does not return. 1053 * Otherwise the function does not return.
1022 */ 1054 */
1023 DART_EXPORT Dart_Handle Dart_RethrowException(Dart_Handle exception, 1055 DART_EXPORT Dart_Handle Dart_RethrowException(Dart_Handle exception,
1024 Dart_Handle stacktrace); 1056 Dart_Handle stacktrace);
1025 1057
1026 // --- Native functions --- 1058 // --- Native functions ---
1027 1059
1028 /** 1060 /**
1029 * The arguments to a native function. 1061 * The arguments to a native function.
1030 * 1062 *
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 DART_EXPORT Dart_Handle Dart_CompileAll(); 1137 DART_EXPORT Dart_Handle Dart_CompileAll();
1106 1138
1107 /** 1139 /**
1108 * Is this object a Library? 1140 * Is this object a Library?
1109 */ 1141 */
1110 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object); 1142 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object);
1111 1143
1112 /** 1144 /**
1113 * Lookup a class by name from a Library. 1145 * Lookup a class by name from a Library.
1114 * 1146 *
1115 * \return If no errors occur, the Library is returned. Otherwise an 1147 * \return If no error occurs, the Library is returned. Otherwise an
1116 * invalid handle is returned. 1148 * error handle is returned.
1117 */ 1149 */
1118 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name); 1150 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name);
1119 1151
1120 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url); 1152 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url);
1121 1153
1122 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library); 1154 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library);
1123 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, 1155 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
1124 Dart_Handle import); 1156 Dart_Handle import);
1125 1157
1126 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 1158 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
(...skipping 16 matching lines...) Expand all
1143 1175
1144 // --- Profiling support ---- 1176 // --- Profiling support ----
1145 1177
1146 // External pprof support for gathering and dumping symbolic 1178 // External pprof support for gathering and dumping symbolic
1147 // information that can be used for better profile reports for 1179 // information that can be used for better profile reports for
1148 // dynamically generated code. 1180 // dynamically generated code.
1149 DART_EXPORT void Dart_InitPprofSupport(); 1181 DART_EXPORT void Dart_InitPprofSupport();
1150 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); 1182 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size);
1151 1183
1152 #endif // INCLUDE_DART_API_H_ 1184 #endif // INCLUDE_DART_API_H_
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | runtime/vm/dart_api_impl.h » ('j') | runtime/vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698