JS_CallFunctionName

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_CallFunctionName
  • Revision title: JS_CallFunctionName
  • Revision id: 147222
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment Someone on the newsgroup was confused about argv, thought it meant a JS array

Revision Content

{{ Jsapi_ref_header("JS_CallFunctionName") }}

Call a method of an object by name.

Syntax

JSBool JS_CallFunctionName(JSContext *cx, JSObject *obj,
    const char *name, uintN argc, jsval *argv, jsval *rval);
Name Type Description
cx JSContext * The context in which to call the method. {{ Jsapi-requires-request() }}
obj JSObject * The object on which to call a method. If a method is found and called, obj is passed to it as this.
name const char * The name of the method to call.
argc uintN Number of arguments to pass to the function.
argv jsval * Pointer to the first element of a C array of argument values to pass to the function.
rval jsval * Out parameter. On success, *rval receives the method's return value.

Description

JS_CallFunctionName executes a function-valued property, name, belonging to a specified JS object, obj.

In argc, indicate the number of arguments passed to the function. In argv, pass a pointer to the actual argument values to use. There should be one value for each argument you pass to the function; the number of arguments you pass may be different from the number of parameters defined for the function.

rval is a pointer to a variable that will hold the function's return value, if any, on successful function execution.

If the called function executes successfully, JS_CallFunctionName returns JS_TRUE. Otherwise it returns JS_FALSE, and the value left in *rval is undefined.

To call a function stored in a jsval, use JS_CallFunctionValue.

See Also

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

JS_CallFunction, JS_GetFunctionObject

Revision Source

<p>{{ Jsapi_ref_header("JS_CallFunctionName") }}
</p><p>Call a method of an object by name.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSBool">JSBool</a> <b>JS_CallFunctionName</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj,
    const char *name, <a href="en/UintN">uintN</a> argc, <a href="en/Jsval">jsval</a> *argv, <a href="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/JSContext">JSContext</a> *</code></td>
<td>The context in which to call the method.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>The object on which to call a method. If a method is found and called, <code>obj</code> is passed to it as <code>this</code>.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code></td>
<td>The name of the method to call.</td>
</tr>
<tr>
<td><code>argc</code></td>
<td><code><a href="en/UintN">uintN</a></code></td>
<td>Number of arguments to pass to the function.</td>
</tr>
<tr>
<td><code>argv</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Pointer to the first element of a C array of argument values to pass to the function.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Out parameter. On success, <code>*rval</code> receives the method's return value.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_CallFunctionName</code> executes a function-valued property, <code>name</code>, belonging to a specified JS object, <code>obj</code>.
</p><p>In <code>argc</code>, indicate the number of arguments passed to the function. In <code>argv</code>, pass a pointer to the actual argument values to use. There should be one value for each argument you pass to the function; the number of arguments you pass may be different from the number of parameters defined for the function.
</p><p><code>rval</code> is a pointer to a variable that will hold the function's return value, if any, on successful function execution.
</p><p>If the called function executes successfully, <code>JS_CallFunctionName</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>, and the value left in <code>*rval</code> is undefined.
</p><p>To call a function stored in a <code>jsval</code>, use <code><a href="en/JS_CallFunctionValue">JS_CallFunctionValue</a></code>.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_CallFunctionName") }}
</p><p><a href="en/JS_CallFunction">JS_CallFunction</a>,
<a href="en/JS_GetFunctionObject">JS_GetFunctionObject</a>
</p>
Revert to this revision