JS::MutableHandle

This article covers features introduced in SpiderMonkey 17

Reference to a T that has been rooted elsewhere. The underlying storage can be changed. This is useful for outparams.

Syntax

bool
someFunction(JSContext *cx, JS::MutableHandle<T> outParam) {
...
}

Methods

Here, ptr represents the private member of JS::MutableHandle<T>, typed with T *.

Method Description
const T &get() const Returns *ptr.
operator const T&() const
T operator->() const
T *address() Returns ptr.
void set(T v) Sets the value of *ptr to v.

Description

JS::MutableHandle<T> is a non-const reference to JS::Rooted&lt;T&gt;. It is used in the same way as JS::Handle&lt;T&gt; and includes a |set(const T &v)| method to allow updating the value of the referenced JS::Rooted&lt;T&gt;. A JS::MutableHandle<T> can be created from a JS::Rooted&lt;T&gt; by using |JS::Rooted<T>::operator&()|.

If you want to add additional methods to JS::MutableHandle for a specific specialization, define a js::MutableHandleBase<T> specialization containing them.

There are typedefs available for the main types:

namespace JS {
typedef MutableHandle<JSFunction*> MutableHandleFunction;
typedef MutableHandle<jsid>        MutableHandleId;
typedef MutableHandle<JSObject*>   MutableHandleObject;
typedef MutableHandle<JSScript*>   MutableHandleScript;
typedef MutableHandle<JSString*>   MutableHandleString;
typedef MutableHandle<JS::Symbol*> MutableHandleSymbol;
typedef MutableHandle<Value>       MutableHandleValue;
}

See Also