JS_CompileFunction 编辑
Obsolete since JSAPI 36
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Creates a JavaScript function from a text string.
Syntax
JSFunction *
JS_CompileFunction(JSContext *cx, JSObject *obj,
const char *name, unsigned int nargs, const char **argnames,
const char *body, size_t length, const char *filename,
unsigned int lineno);
JSFunction *
JS_CompileUCFunction(JSContext *cx, JSObject *obj,
const char *name, unsigned int nargs, const char **argnames,
const jschar *body, size_t length, const char *filename,
unsigned int lineno);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to compile the function. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JSObject * | Object with which the function is associated. |
name | const char * | Name to assign the newly compiled function. |
nargs | unsigned int | Number of arguments to pass to the function. |
argnames | const char ** | Names to assign to the arguments passed to the function. |
body | const char * or const jschar * | String containing the body of the function to compile. |
length | size_t | The length, in characters, of body . |
filename | const char * | Name of file or URL containing the function. Used to report filename or URL in error messages. |
lineno | unsigned int | Line number. Used to report the offending line in the file or URL if an error occurs. |
Description
JS_CompileFunction
compiles a function from a text string, bytes
, and optionally associates it with a JS object, obj
. JS_CompileUCFunction
is the Unicode version of the function.
name
is the name to assign to the newly created function. nargs
is the number of arguments the function takes, and argnames
is a pointer to the first element of an array of names to assign each argument. The number of argument names should match the number of arguments specified in nargs
.
body
is a string containing the source code of the function. length
is the length of the source code in characters.
filename
is the name of the file (or URL) containing the function. This information is used in error messages if an error occurs during compilation. Similarly, lineno
is used to report the line number where an error occurred during compilation.
If both obj
and name
are non-null, the new function becomes a method of obj
. (A new property is defined on obj
with the given name
and the new Function
object as its value.)
On success, JS_CompileFunction
and JS_CompileUCFunction
return a pointer to the newly compiled function. On error or exception, they return NULL
.
See Also
- MXR ID Search for
JS_CompileFunction
- MXR ID Search for
JS_CompileUCFunction
JSFUN_BOUND_METHOD
JSFUN_GLOBAL_PARENT
JS_CallFunction
JS_CallFunctionName
JS_CallFunctionValue
JS_DecompileFunction
JS_DecompileFunctionBody
JS_DefineFunction
JS_DefineFunctions
JS_GetFunctionObject
JS_NewFunction
JS_SetBranchCallback
JS_ValueToFunction
- bug 1089026
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论