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

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

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

Powered by Google App Engine
This is Rietveld 408576698