A weak reference to a JavaScript object.
Unlike a js::Value, a WeakValue doesn't keep its object alive, so the garbage collector can reclaim the object. Lock() gives you a Value for the object, or an empty Value once the object is collected or its page is gone:
UseCached(strong);
else
RebuildCache();
A handle to a live JavaScript value.
Definition Value.h:210
A weak reference to a JavaScript object.
Definition WeakValue.h:43
Use a WeakValue for objects the page keeps alive by itself (eg, a cached page object or a bound instance's own JavaScript object).
- Note
- WeakValue is move-only. For the thread rule, see the ultralight::js namespace overview (<Ultralight/JS.h>).
- Warning
- Don't use a WeakValue as the only reference to a callback. If nothing in the page holds the callback, it's collected and disappears. See "Ownership Cycles" in <Ultralight/js/Class.h> for how to break a reference cycle instead.
|
| | WeakValue ()=default |
| | Create an empty WeakValue (Lock() returns an empty Value).
|
| | WeakValue (const Value &target) |
| | Create a weak reference to target.
|
| | ~WeakValue () |
| | Destructor (releases the weak reference).
|
| | WeakValue (WeakValue &&other) noexcept |
| | Move constructor (other becomes empty).
|
| WeakValue & | operator= (WeakValue &&other) noexcept |
| | Move assignment (releases the current weak reference first).
|
| | WeakValue (const WeakValue &)=delete |
| WeakValue & | operator= (const WeakValue &)=delete |
| Value | Lock () const |
| | Get a Value for the object.
|
| template<typename F> |
| void | OnCollected (F &&on_collected) |
| | Set a callback to run after the object is garbage collected.
|
| bool | IsEmpty () const |
| | Whether or not this WeakValue holds nothing (it was default-constructed, moved from, released with LeakRef(), or created from something that isn't an object in a living page).
|
| ULJSWeakRef | raw () const |
| | Get the C API handle without transferring ownership.
|
| ULJSWeakRef | LeakRef () |
| | Give up ownership of the C API handle and return it.
|