JS_FS 编辑

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 ...
NameTypeDescription
nameconst char *The JavaScript name for the function. (or index, if JSPROP_INDEX is present in flags)
symbola member name of JS::SymbolCodeThe JavaScript symbol for the function.
callJSNativePointer to the C/C++ implementation of the function.
infoconst JSJitInfo *Pointer to the Jit Info.
nargsuint16_tThe number of arguments the function expects.
flagsuint16The bitwise OR of any number of function flags.
selfHostedNameconst 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:72 次

字数:8100

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文