Mozilla.com

  1. MDC
  2. Main Page
  3. SpiderMonkey
  4. JSAPI Reference

The JSAPI is the C API for the SpiderMonkey JavaScript engine. To learn how to use the JSAPI, see the JSAPI User Guide and the JSAPI Phrasebook.


Alphabetical List

Values and types

jsval constants:

Function and macros for checking the type of a jsval:

High-level type-conversion routines for packing and unpacking function arguments.

The following functions convert JS values to various types. They can be safely applied to jsvals of any type. They may return new objects. For example, JS_ValueToObject(cx, s) where s is a string creates a new String wrapper object. These functions may call JavaScript methods. For example, JS_ValueToString(cx, obj) may call obj.toString().

Fast, unchecked type-casting macros. These macros must not be applied to values that are not known to be the right type. Like C casts, they may cause crashes if applied to incorrect values. They never create new objects or call into JavaScript code.

And:

Memory management

These functions act like the Standard C malloc family of functions, except that errors are reported using the SpiderMonkey error APIs rather than errno. These functions also allow SpiderMonkey to account the number of bytes allocated:

JavaScript objects, strings, and floating-point numbers are garbage collected. These functions provide access to the garbage collector:

The rest of these APIs help protect objects from being destroyed by the garbage collector before the application is done using them.

If a variable is a root, then anything it points to will not be freed by the garbage collector. Failure to root objects is a very common cause of mysterious crashes.

Local root scopes are another way of protecting objects from the garbage collector.

New in SpiderMonkey 1.8 (not yet released) If an object contains references to other GC things that are not stored in SpiderMonkey data structures ("slots"), it must implement the JSTraceOp hook to enable the garbage collector to traverse those references. Otherwise the garbage collector will not find all reachable objects and may collect objects that are still reachable, leading to a crash. (In SpiderMonkey 1.7 and earlier, the JSMarkOp hook is used instead. This will be deprecated when SpiderMonkey 1.8 is released.)

The tracing APIs are used by the garbage collector and JSTraceOp hooks. JSAPI applications may also use them to examine the object graph. (For example, these APIs support very smooth integration between the JS garbage collector and other garbage collectors.)

Miscellaneous GC APIs:

Classes

These API features are used to define custom classes—object types that are implemented in C/C++ code but accessible from JavaScript.

Adding native properties and methods to classes:

JSFastNative methods use these macros:

The behavior of a JSClass and its instances can be customized in many ways using callback functions.

JSClass method types:

JSExtendedClass method types:

JSObjectOps method types:

JSXMLObjectOps method types:

These stub functions can be used when creating a custom JSClass:

The behavior of a JSClass can be customized using these flags:

Threading

The following functions support the SpiderMonkey threading model. They are only available in JS_THREADSAFE builds.

The following functions exist in all builds, but in non-JS_THREADSAFE builds, they do nothing:

Time

Preprocessor conditionals

These defines are useful for tuning SpiderMonkey performance:

C++ features

Languages

Page last modified 21:54, 30 Aug 2008 by Jorend

Tags:

Files (0)