JSNative
From MDC
JSNative is the type of many JSAPI callbacks. In particular, APIs such as JS_InitClass and JS_DefineFunctions create custom methods on JavaScript objects that are implemented as JSNative callbacks provided by the application, written in C/C++ code.
The term "native" here refers to C/C++ code as opposed to JavaScript code.
[edit] Syntax
typedef JSBool (*JSNative)(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
Pointer to the JS context in which execution is taking place.
Provides request. (In |
obj |
JSObject * |
Pointer to the this object supplied to the function at execution time. |
argc |
uintN |
The actual number of arguments supplied to the function, as opposed to possibly the number of arguments the function is specified to take in its JSFunctionSpec. |
argv |
jsval * |
The arguments provided to the function, along with a few other values noted below. |
rval |
jsval * |
Out parameter. On success, the callback stores a return value in *rval. Defaults to point to JSVAL_VOID, in case this function does not return a value. |
[edit] Description
JSNative defines the type of native implementations of JS functions.
When a JSNative is invoked by SpiderMonkey, the following locations are available as GC roots:
-
JS_ARGV_CALLEE(argv), which initially roots the JSFunctionobject for the function being executed -
argv[0]throughargv[argc - 1], which hold the arguments provided to the function -
argv[argc]throughargv[minargs - 1], whereminargsisJSFunctionSpec.nargs, if the JSFunctionSpec for the function being invoked specified more arguments than were provided to the function -
argv[minargs]throughargv[minargs + extra - 1], whereextrais(JSFunctionSpec.extra & 0xFFFF)andminargsis as above