This article needs a technical review. How you can help.

Defines a single function for an object.

Syntax

struct JSFunctionSpec {
    const char      *name;
    JSNativeWrapper call;
    uint16_t        nargs;
    uint16_t        flags;
    const char      *selfHostedName;
};

typedef struct JSNativeWrapper {
    JSNative        op;
    const JSJitInfo *info;
} JSNativeWrapper;
Name Type Description
name const char * The function's name.
call JSNativeWrapper 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 uint16_t The value used for Function.length. This no longer guarantees anything about the vp array.
flags uint16_t The bitwise OR of any number of function flags.
selfHostedName const char * The function's name in Self-Hosted JavaScript code.

Description

JSFunctionSpec defines the attributes for a single JS function to associate with an object. An application typically has an array of JSFunctionSpec to define all the functions for an object and calls JS_DefineFunctions or JS_InitClass 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.

To define an array of JSPropertySpec, use JS_FS, JS_FN, JS_SYM_FN, JS_FNINFO, JS_SELF_HOSTED_FN, JS_SELF_HOSTED_SYM_FN, JS_SYM_FNSPEC, JS_FNSPEC, and JS_FS_END.

See Also

Document Tags and Contributors

 Last updated by: arai,