JS_LeaveLocalRootScopeWithResult

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_LeaveLocalRootScopeWithResult
  • Revision title: JS_LeaveLocalRootScopeWithResult
  • Revision id: 75377
  • Created:
  • Creator: MarkGiffin
  • Is current revision? No
  • Comment 6 words added

Revision Content

{{ Obsolete_header() }}

Leave a local root scope, transferring the result value to the next enclosing root scope.

Syntax

void JS_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval);
Name Type Description
cx JSContext * Pointer to the context. This must be the same context that was passed to JS_EnterLocalRootScope. {{ Jsapi-requires-request() }}
rval jsval The result value that should remain protected from garbage collection.

Description

See JS_EnterLocalRootScope for an explanation of local root scopes.

The protection this function affords to rval is tenuous. If there is an enclosing local root scope, then rval is transferred to it. Otherwise, the value is stored in an internal per-JSContext slot. This slot is rooted, but the value will eventually be overwritten by some other operation, and it is very difficult to figure out exactly when this will happen—or more to the point, guarantee that it won't happen in the time it takes some specific chunk of code to run.

In any case, all other newborn values protected by the local root scope, aside from rval, become subject to garbage collection.

See Also

{{ LXRSearch("ident", "i", "JS_EnterLocalRootScope") }}

{{ Jsapixref("JS_AddRoot") }}, {{ Jsapixref("JS_LeaveLocalRootScope") }}, {{ Jsapixref("JS_ForgetLocalRoot") }}

Revision Source

<p>{{ Obsolete_header() }}</p>
<p>Leave a local root scope, transferring the result value to the next enclosing root scope.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">void <strong>JS_LeaveLocalRootScopeWithResult</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> rval);
</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>Pointer to the context. This must be the same context that was passed to <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EnterLocalRootScope" title="en/JS_EnterLocalRootScope">JS_EnterLocalRootScope</a></code>. {{ Jsapi-requires-request() }}</td> </tr> <tr> <td><code>rval</code></td> <td><code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></code></td> <td>The result value that should remain protected from garbage collection.</td> </tr> </tbody>
</table>
<h3 id="Description" name="Description">Description</h3>
<p>See <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EnterLocalRootScope" title="en/JS_EnterLocalRootScope">JS_EnterLocalRootScope</a></code> for an explanation of local root scopes.</p>
<p>The protection this function affords to <code>rval</code> is tenuous. If there is an enclosing local root scope, then <code>rval</code> is transferred to it. Otherwise, the value is stored in an internal per-<code>JSContext</code> slot. This slot is rooted, but the value will eventually be overwritten by some other operation, and it is very difficult to figure out exactly when this will happen—or more to the point, guarantee that it won't happen in the time it takes some specific chunk of code to run.</p>
<p>In any case, all <em>other</em> newborn values protected by the local root scope, aside from <code>rval</code>, become subject to garbage collection.</p>
<h3 id="See_Also" name="See_Also">See Also</h3>
<p>{{ LXRSearch("ident", "i", "JS_EnterLocalRootScope") }}</p>
<p>{{ Jsapixref("JS_AddRoot") }}, {{ Jsapixref("JS_LeaveLocalRootScope") }}, {{ Jsapixref("JS_ForgetLocalRoot") }}</p>
Revert to this revision