Very soon, the "fatval" branch (bug 549143) will be merging with TM.
This post is about the changes to the JS API. I would have liked to
have posted this information earlier, but the exact details have been in
flux until recently. (There is also a new API for values (js::Value)
which is SM-internal and described in more detail at the top of jsvalue.h.)
In a nutshell, the major changes are:
- jsval is no longer word-sized
- jsval can holds a full int32
- doubles are stored in the jsval; JSVAL_TO_DOUBLE returns double
- jsval and jsid no longer share the same representation
- JSClass method signatures have been modified to take jsids for id
arguments and pass jsval arguments by const jsval*.
In more detail:
JSVAL_* operations cannot be used on jsids, a new (more precise) set of
jsid operations/constants are provided:
JSID_IS_INT / JSID_TO_INT / INT_TO_JSID / JSID_INT_MIN / JSID_INT_MAX
JSID_IS_OBJECT / JSID_TO_OBJECT / OBJECT_TO_JSID
JSID_IS_STRING / JSID_TO_STRING / INTERNED_STRING_TO_JSID
JSID_IS_VOID / JSID_VOID
JSID_IS_DEFAULT_XML_NAMESPACE / JS_DEFAULT_XML_NAMESPACE_ID
which are straightforward replacements for their JSVAL_* counterparts.
When DEBUG is not defined, jsval and jsid are (different) integral
builtin types. To avoid implicit conversions between the two (which,
previously, was mostly valid but now is totally wrong), in debug builds
jsval and jsid are given different struct types. Default struct
assignment and (in C++) operator== allows must code not observe the
difference. This feature can be disabled by defining
JS_NO_JSVAL_JSID_STRUCT_TYPES when building SM.
JSVAL_IS_SPECIAL/JSVAL_TO_SPECIAL has been removed. While this is in
jsapi.h, it is an implementation detail; embeddings should only be using
JSVAL_IS_BOOLEAN/JSVAL_TO_BOOLEAN/BOOLEAN_TO_JSVAL.
JS_MarkGCThing was changed to take a jsval, not a void*. Embeddings
using this API should consider using the new (unfortunately named)
"tracing" GC API.
JSGCRootMapFun, the callback type for JS_MapGCRoots, is changed to take
an additional parameter which tells whether the given void* is a jsval*
or void** (GC-thing), since it is no longer possible to tell the
difference by looking at the bits.
JS_NewDoubleValue, which was deprecated, has been removed. In its
place, DOUBLE_TO_JSVAL or JS_NewNumberValue can be used, depending on
whether the caller wants doubles to be tested for whether they fit in an
int.
The particular signatures used in JSClass that have been changed are:
JSPropertyOp
JSResolveOp
JSNewResolveOp
JSCheckAccessOp
The only change made is switching "jsval id" parameters to "jsid id" and
switching "jsval v" parameters to "const jsval *v". The latter was done
due to the measured performance benefit of passing 64-bit values by
pointer on 32-bit systems. The struct types should catch type errors
involving these. However, beware function-pointer casts (viz. from a
JSNewResolveOp to a JSResolveOp), since these thwart the type system.
If you have any questions, feel free to reply here or ping me on #jsapi
(handle: luke).