Visit Mozilla.org

JS ValueToFunction

From MDC

Convert a jsval to a JSFunction.

[edit] Syntax

JSFunction * JS_ValueToFunction(JSContext *cx, jsval v);
Name Type Description
cx JSContext * The context in which to perform the conversion.

Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)

v jsval The JS value to convert.

[edit] Description

JS_ValueToFunction converts a specified JS value, v, to a JS function.

  • If v is a Function object, this returns the associated JSFunction.
  • If v is null, undefined, a boolean, a number, or a string, an error is reported and JS_ValueToFunction returns NULL.
  • Otherwise, v is an object. The JavaScript engine attempts to convert it to a function. The actual conversion is performed by the object's convert operation. (Implementation note: the object's JSObjectOps.defaultValue method is called with hint=JSTYPE_FUNCTION.) JS_ValueToFunction returns a pointer to the converted function. If conversion fails with an error or exception, JS_ValueToFunction returns NULL.

[edit] See Also

LXR ID Search for JS_ValueToFunction

JS_ConvertArguments, JS_ConvertValue, JS_GetTypeName, JS_TypeOfValue, JS_ValueToBoolean, JS_ValueToInt32, JS_ValueToNumber, JS_ValueToObject, JS_ValueToString