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

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

Powered by Google App Engine
This is Rietveld 408576698