Macros for describing functions, for use with JS_DefineProperties and JS_InitClass.
Syntax
#define JS_FS(name,call,nargs,flags) ... #define JS_FN(name,call,nargs,flags) ... #define JS_SYM_FN(symbol,call,nargs,flags) ... // Added in SpiderMonkey 38 #define JS_FNINFO(name,call,info,nargs,flags) ... // Added in SpiderMonkey 17 #define JS_SELF_HOSTED_FN(name,selfHostedName,nargs,flags) ... // Added in SpiderMonkey 31 #define JS_SELF_HOSTED_SYM_FN(symbol, selfHostedName, nargs, flags) ... // Added in SpiderMonkey 38 #define JS_SYM_FNSPEC(symbol, call, info, nargs, flags, selfHostedName) ... // Added in SpiderMonkey 38 #define JS_FNSPEC(name,call,info,nargs,flags,selfHostedName) ... // Added in SpiderMonkey 31 #define JS_FS_END ...
| Name | Type | Description | 
|---|---|---|
| name | const char * | The JavaScript name for the function. (or index, if JSPROP_INDEXis present in flags) | 
| symbol | a member name of JS::SymbolCode | The JavaScript symbol for the function. | 
| call | JSNative | Pointer to the C/C++ implementation of the function. | 
| info | const JSJitInfo * | Pointer to the Jit Info. | 
| nargs | uint16_t | The number of arguments the function expects. | 
| flags | uint16 | The bitwise OR of any number of function flags. | 
| selfHostedName | const char * | The function's name in Self-Hosted JavaScript code. | 
Description
Use these macros to define an array of JSFunctionSpecs to pass to JS_DefineFunctions or JS_InitClass.
JS_FN (whose name pays homage to the old JSNative/JSFastNative split) simply adds the flag JSFUN_STUB_GSOPS. JS_FNINFO allows the simple adding of JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted function. Finally JS_FNSPEC has slots for all the fields.
The _SYM variants allow defining a function with a symbol key rather than a string key. For example, use JS_SYM_FN(iterator, ...) to define an @@iterator method. (In builds without ES6 symbols, it defines a method with the string id "@@iterator".)
See an example in the JSAPI User Guide.
See Also
- MXR ID Search for JS_FS
- MXR ID Search for JS_FN
- MXR ID Search for JS_SYM_FN
- MXR ID Search for JS_FNINFO
- MXR ID Search for JS_SELF_HOSTED_FN
- MXR ID Search for JS_SELF_HOSTED_SYM_FN
- MXR ID Search for JS_SYM_FNSPEC
- MXR ID Search for JS_FNSPEC
- MXR ID Search for JS_FS_END
- JSFunctionSpec
- JS_DefineProperties
- JS_InitClass
- bug 775788 - added JS_FNINFO.
- bug 920433 - added JS_SELF_HOSTED_FNandJS_FNSPEC.
- bug 1082672 - added JS_SYM_FNJS_SELF_HOSTED_SYM_FNJS_SYM_FNSPEC.