Specifications
Chapter 21254
typedef enum { JS_FALSE = 0, JS_TRUE = 1 } JSBool
Description
A simple data type that stores a Boolean value.
The C-level API
The C-level extensibility API consists of the following functions.
typedef JSBool (*JSNative)(JSContext *cx, JSObject *obj, unsigned int
argc, jsval *argv, jsval *rval)
Description
This function signature describes C-level implementations of JavaScript functions in the
following situations:
• cx is a pointer to an opaque JSContext structure, which must be passed to some of the
functions in the JavaScript API. This variable holds the interpreter’s execution context.
• obj is a pointer to the object in whose context the script executes. While the script is running,
the
this keyword is equal to this object.
• argc is the number of arguments being passed to the function.
• argv is a pointer to an array of jsvals. The array is argc elements in length.
• rval is a pointer to a single jsval. The function’s return value should be written to *rval.
The function returns
JS_TRUE upon success or JS_FALSE upon failure. If the function returns
JS_FALSE, the current script stops executing and an error message appears.
JSBool JS_DefineFunction()
Description
Registers a C-level function with the JavaScript interpreter in Dreamweaver. After
JS_DefineFunction() registers the C-level function that you specify in the call argument, you
can invoke it in a JavaScript script by referring to it with the name that you specify in the
name
argument. The
name is case-sensitive.
Typically, this function is called from
MM_Init(), which Dreamweaver calls during startup.
Arguments
char *name, JSNative call, unsigned int nargs
• name is the name of the function as it is exposed to JavaScript.
• call is a pointer to a C-level function. The function must accept the same arguments as
readContentsOfFile, and it must return a JSBool, which indicates success or failure.
• nargs is the number of arguments that the function expects to receive.
Returns
A Boolean value that indicates success (JS_TRUE) or failure (JS_FALSE).