JS_GetContextPrivate

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GetContextPrivate
  • Revision title: JS_GetContextPrivate
  • Revision id: 147027
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment merge from JS_SetContextPrivate

Revision Content

{{template.Jsapi_ref_header("JS_GetContextPrivate")}}

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

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

JS_GetRuntimePrivate, JS_SetRuntimePrivate, JS_GetPrivate, JS_SetPrivate, JS_GetInstancePrivate

Revision Source

<p>{{template.Jsapi_ref_header("JS_GetContextPrivate")}}
</p><p>Access a <code>JSContext</code> field for application-specific data.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">void * <b>JS_GetContextPrivate</b>(<a href="en/JSContext">JSContext</a> *cx);

void <b>JS_SetContextPrivate</b>(<a href="en/JSContext">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/JSContext">JSContext</a> *</code></td>
<td>Any context.</td>
</tr>
<tr>
<td><code>data</code></td>
<td><code>void *</code></td>
<td><i>(in <code>JS_SetContextPrivate</code>)</i> Pointer to application-defined data to be associated with the context <code>cx</code>.
</td></tr></tbody></table>
<h2 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 name="See_Also"> See Also </h2>
<p>{{template.LXRSearch("ident", "i", "JS_GetContextPrivate")}}<br>
{{template.LXRSearch("ident", "i", "JS_SetContextPrivate")}}
</p><p><a href="en/JS_GetRuntimePrivate">JS_GetRuntimePrivate</a>, <a href="en/JS_SetRuntimePrivate">JS_SetRuntimePrivate</a>, <a href="en/JS_GetPrivate">JS_GetPrivate</a>, <a href="en/JS_SetPrivate">JS_SetPrivate</a>, <a href="en/JS_GetInstancePrivate">JS_GetInstancePrivate</a>
</p>
Revert to this revision