We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JS CallFunctionValue

Calls a specified JS function.


JSBool JS_CallFunctionValue(JSContext *cx, JSObject *obj,
    jsval fval, uintN argc, jsval *argv, jsval *rval);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The "this" argument to pass to the function.
fval jsval The function to call.
argc uintN The number of arguments to pass to the function. This may be NULL.
argv jsval * Pointer to the array of argument values to pass to the function. If argc is 0, argv may be NULL.
rval jsval * Out parameter. On success, *rval receives the return value from the function call.


JS_CallFunctionValue applies a function, fval, to a given object obj and an array of arguments argv.

JS_CallFunctionValue(cx, obj, fval, argc, argv, rval) is analogous to the JavaScript statement rval = fval.apply(obj, argv);.

If obj is NULL, then the JavaScript value null is passed as the "this" argument. The consequences depend on the function:

  • If fval is a strict-mode function, this will actually be null.
  • If fval is a non-strict-mode function, it will silently replace the null "this" argument with the global object under which it was created.
  • If fval is a native function, then it will find that vp[1] is JSVAL_NULL, but note that APIs such as JS_THIS and JS_THIS_OBJECT silently replace this with the function's global object.

If the called function executes successfully, JS_CallFunctionValue stores the return value in *rval and returns JS_TRUE. Otherwise it returns JS_FALSE, and the value left in *rval is unspecified.

To call a method of an object or to call a global function, use JS_CallFunctionName instead. To call a function as though with the new keyword, use JS_New.

MXR ID Search for JS_CallFunctionValue

Document Tags and Contributors

Last updated by: Jorend,