Visit Mozilla.org

JSFunctionSpec

From MDC

Defines a single function for an object.

[edit] Syntax

struct JSFunctionSpec {
    const char *name;
    JSNative call;
    uint8 nargs;
    uint8 flags;
    uint32 extra;
};
Name Type Description
name const char * Name to assign to the function.
call JSNative The built-in JS call wrapped by this function. If the function does not wrap a native JS call, set this value to NULL.
nargs uint8 The minimum number of items in the argv array when your function is called.

E.g. if you specify nargs as 2, argv[0] and argv[1] will always exist, even if the actual caller didn't provide them. argc will reflect the actual number passed by the caller (which could be less, the same, or more than nargs). Any values missing from the actual arguments provided by the caller will be filled with JSVAL_VOID.

flags uint8 Function attributes. If set to 0 the function has no attributes. Otherwise, existing applications can set flags to either or both of the following attributes OR'd:

Note that these attributes are deprecated, and continue to be supported only for backward compatibility with existing applications. New applications should not use these attributes.

extra uint32 The lower 16 bits indicate the number of extra local roots the function desires, available at argv[MAX(nargs, argc)] onward. The upper 16 bits must be zero and are currently reserved. In older versions of SpiderMonkey, this field was a uint16 required to be 0.

[edit] Description

JSFuctionSpec defines the attributes for a single JS function to associate with an object. Generally, you populate an array of JSFunctionSpec to define all the functions for an object, and then call JS_DefineFunctions to create the functions and assign them to an object.

JSFunctionSpec can also be used to define an array element rather than a named property. Array elements are actually individual properties. To define an array element, cast the element's index value to const char*, initialize the name field with it, and specify the JSPROP_INDEX attribute in flags.

[edit] See Also

LXR ID Search for JSFunctionSpec

JSFUN_BOUND_METHOD, JSFUN_GLOBAL_PARENT, JSPROP_INDEX, JS_CallFunction, JS_CallFunctionName, JS_CallFunctionValue, JS_CompileFunction, JS_DecompileFunction, JS_DecompileFunctionBody, JS_DefineFunction, JS_DefineFunctions, JS_GetFunctionName, JS_GetFunctionObject, JS_NewFunction, JS_SetBranchCallback