Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions | Variables
jsarray.h File Reference
#include "jsprvtd.h"
#include "jspubtd.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ARRAY_INIT_LIMIT   JS_BIT(24)

Typedefs

typedef JSBool(* JSComparator )(void *arg, const void *a, const void *b, int *result)

Functions

JSBool js_IdIsIndex (jsval id, jsuint *indexp)
JSObjectjs_InitArrayClass (JSContext *cx, JSObject *obj)
JSObjectjs_NewArrayObject (JSContext *cx, jsuint length, jsval *vector)
JSBool js_GetLengthProperty (JSContext *cx, JSObject *obj, jsuint *lengthp)
JSBool js_SetLengthProperty (JSContext *cx, JSObject *obj, jsuint length)
JSBool js_HasLengthProperty (JSContext *cx, JSObject *obj, jsuint *lengthp)
JSBool js_IsArrayLike (JSContext *cx, JSObject *obj, JSBool *answerp, jsuint *lengthp)
JSBool js_HeapSort (void *vec, size_t nel, void *pivot, size_t elsize, JSComparator cmp, void *arg)

Variables

JSClass js_ArrayClass

Define Documentation

Definition at line 51 of file jsarray.h.


Typedef Documentation

Definition at line 86 of file jsarray.h.


Function Documentation

JSBool js_GetLengthProperty ( JSContext cx,
JSObject obj,
jsuint lengthp 
)

Definition at line 165 of file jsarray.c.

{
    JSTempValueRooter tvr;
    jsid id;
    JSBool ok;
    jsint i;

    JS_PUSH_SINGLE_TEMP_ROOT(cx, JSVAL_NULL, &tvr);
    id = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
    ok = OBJ_GET_PROPERTY(cx, obj, id, &tvr.u.value);
    if (ok) {
        /*
         * Short-circuit, because js_ValueToECMAUint32 fails when called
         * during init time.
         */
        if (JSVAL_IS_INT(tvr.u.value)) {
            i = JSVAL_TO_INT(tvr.u.value);
            *lengthp = (jsuint)i;       /* jsuint cast does ToUint32 */
        } else {
            ok = js_ValueToECMAUint32(cx, tvr.u.value, (uint32 *)lengthp);
        }
    }
    JS_POP_TEMP_ROOT(cx, &tvr);
    return ok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_HasLengthProperty ( JSContext cx,
JSObject obj,
jsuint lengthp 
)

Definition at line 349 of file jsarray.c.

{
    JSErrorReporter older;
    JSTempValueRooter tvr;
    jsid id;
    JSBool ok;

    older = JS_SetErrorReporter(cx, NULL);
    JS_PUSH_SINGLE_TEMP_ROOT(cx, JSVAL_NULL, &tvr);
    id = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
    ok = OBJ_GET_PROPERTY(cx, obj, id, &tvr.u.value);
    JS_SetErrorReporter(cx, older);
    if (ok)
        ok = ValueIsLength(cx, tvr.u.value, lengthp);
    JS_POP_TEMP_ROOT(cx, &tvr);
    return ok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_HeapSort ( void vec,
size_t  nel,
void pivot,
size_t  elsize,
JSComparator  cmp,
void arg 
)

Definition at line 907 of file jsarray.c.

{
    HSortArgs hsa;
    size_t i;

    hsa.vec = vec;
    hsa.elsize = elsize;
    hsa.pivot = pivot;
    hsa.cmp = cmp;
    hsa.arg = arg;
    hsa.fastcopy = (cmp == sort_compare || cmp == sort_compare_strings);

    for (i = nel/2; i != 0; i--) {
        if (!HeapSortHelper(JS_TRUE, &hsa, i, nel))
            return JS_FALSE;
    }
    while (nel > 2) {
        if (!HeapSortHelper(JS_FALSE, &hsa, 1, --nel))
            return JS_FALSE;
    }

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_IdIsIndex ( jsval  id,
jsuint indexp 
)

Definition at line 84 of file jsarray.c.

{
    JSString *str;
    jschar *cp;

    if (JSVAL_IS_INT(id)) {
        jsint i;
        i = JSVAL_TO_INT(id);
        if (i < 0)
            return JS_FALSE;
        *indexp = (jsuint)i;
        return JS_TRUE;
    }

    /* NB: id should be a string, but jsxml.c may call us with an object id. */
    if (!JSVAL_IS_STRING(id))
        return JS_FALSE;

    str = JSVAL_TO_STRING(id);
    cp = JSSTRING_CHARS(str);
    if (JS7_ISDEC(*cp) && JSSTRING_LENGTH(str) < sizeof(MAXSTR)) {
        jsuint index = JS7_UNDEC(*cp++);
        jsuint oldIndex = 0;
        jsuint c = 0;
        if (index != 0) {
            while (JS7_ISDEC(*cp)) {
                oldIndex = index;
                c = JS7_UNDEC(*cp);
                index = 10*index + c;
                cp++;
            }
        }

        /* Ensure that all characters were consumed and we didn't overflow. */
        if (*cp == 0 &&
             (oldIndex < (MAXINDEX / 10) ||
              (oldIndex == (MAXINDEX / 10) && c < (MAXINDEX % 10))))
        {
            *indexp = index;
            return JS_TRUE;
        }
    }
    return JS_FALSE;
}

Here is the caller graph for this function:

JSObject* js_InitArrayClass ( JSContext cx,
JSObject obj 
)

Definition at line 1833 of file jsarray.c.

{
    JSObject *proto;

    proto = JS_InitClass(cx, obj, NULL, &js_ArrayClass, Array, 1,
                         NULL, array_methods, NULL, NULL);

    /* Initialize the Array prototype object so it gets a length property. */
    if (!proto || !InitArrayObject(cx, proto, 0, NULL))
        return NULL;
    return proto;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_IsArrayLike ( JSContext cx,
JSObject obj,
JSBool answerp,
jsuint lengthp 
)

Definition at line 368 of file jsarray.c.

{
    JSClass *clasp;

    clasp = OBJ_GET_CLASS(cx, obj);
    *answerp = (clasp == &js_ArgumentsClass || clasp == &js_ArrayClass);
    if (!*answerp) {
        *lengthp = 0;
        return JS_TRUE;
    }
    return js_GetLengthProperty(cx, obj, lengthp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSObject* js_NewArrayObject ( JSContext cx,
jsuint  length,
jsval vector 
)

Definition at line 1847 of file jsarray.c.

{
    JSTempValueRooter tvr;
    JSObject *obj;

    obj = js_NewObject(cx, &js_ArrayClass, NULL, NULL);
    if (!obj)
        return NULL;

    JS_PUSH_TEMP_ROOT_OBJECT(cx, obj, &tvr);
    if (!InitArrayObject(cx, obj, length, vector))
        obj = NULL;
    JS_POP_TEMP_ROOT(cx, &tvr);

    /* Set/clear newborn root, in case we lost it.  */
    cx->weakRoots.newborn[GCX_OBJECT] = (JSGCThing *) obj;
    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_SetLengthProperty ( JSContext cx,
JSObject obj,
jsuint  length 
)

Definition at line 337 of file jsarray.c.

{
    jsval v;
    jsid id;

    if (!IndexToValue(cx, length, &v))
        return JS_FALSE;
    id = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
    return OBJ_SET_PROPERTY(cx, obj, id, &v);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 470 of file jsarray.c.