@@ -244,8 +244,9 @@ typedef struct _Dart_IsolateGroup* Dart_IsolateGroup;
244244 * the object is garbage collected. It is never safe to use these handles
245245 * unless you know the object is still reachable.
246246 *
247- * WeakPersistentHandles are persistent handles which are auto deleted
248- * when the object is garbage collected.
247+ * WeakPersistentHandles are persistent handles which are automatically set
248+ * to point Dart_Null when the object is garbage collected. They are not auto
249+ * deleted, so it is safe to use them after the object has become unreachable.
249250 */
250251typedef struct _Dart_Handle * Dart_Handle ;
251252typedef Dart_Handle Dart_PersistentHandle ;
@@ -254,10 +255,6 @@ typedef struct _Dart_FinalizableHandle* Dart_FinalizableHandle;
254255// These structs are versioned by DART_API_DL_MAJOR_VERSION, bump the
255256// version when changing this struct.
256257
257- typedef void (* Dart_WeakPersistentHandleFinalizer )(
258- void * isolate_callback_data ,
259- Dart_WeakPersistentHandle handle ,
260- void * peer );
261258typedef void (* Dart_HandleFinalizer )(void * isolate_callback_data , void * peer );
262259
263260/**
@@ -423,6 +420,8 @@ DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object);
423420
424421/**
425422 * Allocates a handle in the current scope from a weak persistent handle.
423+ *
424+ * This will be a handle to Dart_Null if the object has been garbage collected.
426425 */
427426DART_EXPORT Dart_Handle
428427Dart_HandleFromWeakPersistent (Dart_WeakPersistentHandle object );
@@ -461,24 +460,18 @@ DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object);
461460/**
462461 * Allocates a weak persistent handle for an object.
463462 *
464- * This handle has the lifetime of the current isolate unless the object
465- * pointed to by the handle is garbage collected, in this case the VM
466- * automatically deletes the handle after invoking the callback associated
467- * with the handle. The handle can also be explicitly deallocated by
468- * calling Dart_DeleteWeakPersistentHandle.
469- *
470- * If the object becomes unreachable the callback is invoked with the weak
471- * persistent handle and the peer as arguments. The callback can be executed on
472- * any thread, will have an isolate group, but will not have a current isolate.
473- * The callback can only call Dart_DeletePersistentHandle or
474- * Dart_DeleteWeakPersistentHandle. The callback must not call
475- * Dart_DeleteWeakPersistentHandle for the handle being finalized, as it is
476- * automatically deleted by the VM after the callback returns. This gives the
477- * embedder the ability to cleanup data associated with the object and clear
478- * out any cached references to the handle. All references to this handle after
479- * the callback will be invalid. It is illegal to call into the VM with any
480- * other Dart_* functions from the callback. If the handle is deleted before
481- * the object becomes unreachable, the callback is never invoked.
463+ * This handle has the lifetime of the current isolate. The handle can also be
464+ * explicitly deallocated by calling Dart_DeleteWeakPersistentHandle.
465+ *
466+ * If the object becomes unreachable the callback is invoked with the peer as
467+ * argument. The callback can be executed on any thread, will have a current
468+ * isolate group, but will not have a current isolate. The callback can only
469+ * call Dart_DeletePersistentHandle or Dart_DeleteWeakPersistentHandle. This
470+ * gives the embedder the ability to cleanup data associated with the object.
471+ * The handle will point to the Dart_Null object after the finalizer has been
472+ * run. It is illegal to call into the VM with any other Dart_* functions from
473+ * the callback. If the handle is deleted before the object becomes
474+ * unreachable, the callback is never invoked.
482475 *
483476 * Requires there to be a current isolate.
484477 *
@@ -498,7 +491,7 @@ DART_EXPORT Dart_WeakPersistentHandle
498491Dart_NewWeakPersistentHandle (Dart_Handle object ,
499492 void * peer ,
500493 intptr_t external_allocation_size ,
501- Dart_WeakPersistentHandleFinalizer callback );
494+ Dart_HandleFinalizer callback );
502495
503496/**
504497 * Deletes the given weak persistent [object] handle.
@@ -2046,7 +2039,7 @@ Dart_NewExternalLatin1String(const uint8_t* latin1_array,
20462039 intptr_t length ,
20472040 void * peer ,
20482041 intptr_t external_allocation_size ,
2049- Dart_WeakPersistentHandleFinalizer callback );
2042+ Dart_HandleFinalizer callback );
20502043
20512044/**
20522045 * Returns a String which references an external array of UTF-16 encoded
@@ -2067,7 +2060,7 @@ Dart_NewExternalUTF16String(const uint16_t* utf16_array,
20672060 intptr_t length ,
20682061 void * peer ,
20692062 intptr_t external_allocation_size ,
2070- Dart_WeakPersistentHandleFinalizer callback );
2063+ Dart_HandleFinalizer callback );
20712064
20722065/**
20732066 * Gets the C string representation of a String.
@@ -2440,13 +2433,13 @@ DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type,
24402433 * \return The TypedData object if no error occurs. Otherwise returns
24412434 * an error handle.
24422435 */
2443- DART_EXPORT Dart_Handle Dart_NewExternalTypedDataWithFinalizer (
2444- Dart_TypedData_Type type ,
2445- void * data ,
2446- intptr_t length ,
2447- void * peer ,
2448- intptr_t external_allocation_size ,
2449- Dart_WeakPersistentHandleFinalizer callback );
2436+ DART_EXPORT Dart_Handle
2437+ Dart_NewExternalTypedDataWithFinalizer ( Dart_TypedData_Type type ,
2438+ void * data ,
2439+ intptr_t length ,
2440+ void * peer ,
2441+ intptr_t external_allocation_size ,
2442+ Dart_HandleFinalizer callback );
24502443
24512444/**
24522445 * Returns a ByteBuffer object for the typed data.
0 commit comments