JS_GetContextPrivate

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GetContextPrivate
  • Revision title: JS_GetContextPrivate
  • Revision id: 147030
  • Created:
  • Creator: Jorend
  • Is current revision? Yes
  • Comment 14 words removed

Revision Content

Access a JSContext field for application-specific data.

Syntax

void * JS_GetContextPrivate(JSContext *cx);

void JS_SetContextPrivate(JSContext *cx, void *data);
Name Type Description
cx JSContext * Any context.
data void * (in JS_SetContextPrivate) Pointer to application-defined data to be associated with the context cx.

Description

Each JSContext has a field of type void * which the application may use for any purpose. It is especially useful for storing data needed by callbacks. JS_GetContextPrivate gets this field and JS_SetContextPrivate sets it. The field is initially NULL.

Memory management for this private data is the application's responsibility. The JavaScript engine itself never uses it.

See Also

{{ LXRSearch("ident", "i", "JS_GetContextPrivate") }}
{{ LXRSearch("ident", "i", "JS_SetContextPrivate") }}

JS_GetRuntimePrivate, JS_SetRuntimePrivate, JS_GetPrivate, JS_SetPrivate, JS_GetInstancePrivate

Revision Source

<p>Access a <code>JSContext</code> field for application-specific data.
</p>
<h2 id="Syntax" name="Syntax"> Syntax </h2>
<pre class="eval">void * <strong>JS_GetContextPrivate</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx);

void <strong>JS_SetContextPrivate</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, void *data);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>Any context.</td>
</tr>
<tr>
<td><code>data</code></td>
<td><code>void *</code></td>
<td><em>(in <code>JS_SetContextPrivate</code>)</em> Pointer to application-defined data to be associated with the context <code>cx</code>.
</td></tr></tbody></table>
<h2 id="Description" name="Description"> Description </h2>
<p>Each <code>JSContext</code> has a field of type <code>void *</code> which the application may use for any purpose. It is especially useful for storing data needed by callbacks. <code>JS_GetContextPrivate</code> gets this field and <code>JS_SetContextPrivate</code> sets it. The field is initially <code>NULL</code>.
</p><p>Memory management for this private data is the application's responsibility. The JavaScript engine itself never uses it.
</p>
<h2 id="See_Also" name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_GetContextPrivate") }}<br>
{{ LXRSearch("ident", "i", "JS_SetContextPrivate") }}
</p><p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetRuntimePrivate" title="en/JS_GetRuntimePrivate">JS_GetRuntimePrivate</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetRuntimePrivate" title="en/JS_GetRuntimePrivate">JS_SetRuntimePrivate</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPrivate" title="en/JS_GetPrivate">JS_GetPrivate</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrivate" title="en/JS_SetPrivate">JS_SetPrivate</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetInstancePrivate" title="en/JS_GetInstancePrivate">JS_GetInstancePrivate</a>
</p>
Revert to this revision