JS_CallFunctionName

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_CallFunctionName
  • Revision title: JS_CallFunctionName
  • Revision id: 147218
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment Requires request (and other minor changes)

Revision Content

{{template.Jsapiref()}}

Function

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 * Pointer to a JS context from which to derive runtime information. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * The "current" object on which the function operates; the object specified here is "this" when the function executes.
name const char * The name of the method to call.
argc uintN Number of arguments you are passing to the function.
argv jsval * Pointer to the array of argument values to pass to the function.
rval jsval * Pointer to a variable to hold the return value from the function call.

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 arguments 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 rval is undefined.

Notes

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

See Also

Groups Functions
Documents {{template.LXRSearch("ident", "i", "JS_CallFunctionName", "LXR ID Search")}}
Entries

JS_CallFunction, JS_CallFunctionValue, JS_CompileFunction, JS_DecompileFunction, JS_DecompileFunctionBody, JS_DefineFunction, JS_DefineFunctions, JS_GetFunctionObject, JS_NewFunction, JS_SetBranchCallback, JS_ValueToFunction

Revision Source

<p> 
{{template.Jsapiref()}}
</p><p><b>Function</b>
</p><p>Call a method of an object by name.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">JSBool <b>JS_CallFunctionName</b>(JSContext *cx, JSObject *obj,
    const char *name, uintN argc, jsval *argv, jsval *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>JSContext *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>The "current" object on which the function operates; the object specified here is "this" when the function executes.</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>uintN</code></td>
<td>Number of arguments you are passing to the function.</td>
</tr>
<tr>
<td><code>argv</code></td>
<td><code>jsval *</code></td>
<td>Pointer to the array of argument values to pass to the function.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code>jsval *</code></td>
<td>Pointer to a variable to hold the return value from the function call.</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 arguments 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 <code>rval</code> is undefined.
</p>
<h3 name="Notes"> Notes </h3>
<p>To call a function stored in a jsval, use <code><a href="en/JS_CallFunctionValue">JS_CallFunctionValue</a></code>.
</p>
<h2 name="See_Also"> See Also </h2>
<table class="fullwidth-table">
<tbody><tr>
<td>Groups</td>
<td><a href="en/JSAPI_Reference#Functions">Functions</a></td>
</tr>
<tr>
<td>Documents</td>
<td>{{template.LXRSearch("ident", "i", "JS_CallFunctionName", "LXR ID Search")}}</td>
</tr>
<tr>
<td>Entries</td>
<td>
<p><a href="en/JS_CallFunction">JS_CallFunction</a>,
<a href="en/JS_CallFunctionValue">JS_CallFunctionValue</a>,
<a href="en/JS_CompileFunction">JS_CompileFunction</a>,
<a href="en/JS_DecompileFunction">JS_DecompileFunction</a>,
<a href="en/JS_DecompileFunctionBody">JS_DecompileFunctionBody</a>,
<a href="en/JS_DefineFunction">JS_DefineFunction</a>,
<a href="en/JS_DefineFunctions">JS_DefineFunctions</a>,
<a href="en/JS_GetFunctionObject">JS_GetFunctionObject</a>,
<a href="en/JS_NewFunction">JS_NewFunction</a>,
<a href="en/JS_SetBranchCallback">JS_SetBranchCallback</a>,
<a href="en/JS_ValueToFunction">JS_ValueToFunction</a>
</p>
</td>
</tr>
</tbody></table>
Revert to this revision