JavaScript-1.5 Reference

JS_CompileFunction Function

Summary

Creates a JS function from a text string.

Syntax

JSFunction * JS_CompileFunction(JSContext *cx, JSObject *obj,
    const char *name, uintN nargs, const char **argnames,
    const char *bytes, size_t length, const char *filename,
    uintN lineno);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Object with which the function is associated.
nameconst char *Name to assign the newly compiled function.
nargsuintNNumber of arguments to pass to the function.
argnamesconst char **Names to assign to the arguments passed to the function.
bytesconst char *String containing the function to compile.
lengthsize_tSize, in bytes, of the function to compile.
filenameconst char *Name of file or URL containing the function. Used to report filename or URL in error messages.
linenouintNLine 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 associated it with a JS object, obj.

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 an array of names to assign each argument. The number of argument names should match the number of arguments specified in nargs.

bytes is the string containing the text of the function. length indicates the size of the text version of the function in bytes.

filename is the name of the file (or URL) containing the function. This information in messages if an error occurs during compilation. Similarly, lineno is used to report the line number of the function or file where an error occurred during compilation.

If a function compiles successfully, JS_CompileFunction returns a pointer to the function. Otherwise JS_CompileFunction returns NULL.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ 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 ]

This page was generated by APIDOC