Back to index

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

Go to the source code of this file.

Classes

struct  JSXDROps
struct  JSXDRState

Defines

#define JSXDR_ALIGN   4
#define JSXDR_MAGIC_SCRIPT_1   0xdead0001
#define JSXDR_MAGIC_SCRIPT_2   0xdead0002
#define JSXDR_MAGIC_SCRIPT_3   0xdead0003
#define JSXDR_MAGIC_SCRIPT_4   0xdead0004
#define JSXDR_MAGIC_SCRIPT_5   0xdead0005
#define JSXDR_MAGIC_SCRIPT_CURRENT   JSXDR_MAGIC_SCRIPT_5
#define JSXDR_BYTECODE_VERSION   (0xb973c0de - 29)

Typedefs

typedef enum JSXDRMode JSXDRMode
typedef enum JSXDRWhence JSXDRWhence
typedef struct JSXDROps JSXDROps

Enumerations

enum  JSXDRMode { JSXDR_ENCODE, JSXDR_DECODE, JSXDR_FREE }
enum  JSXDRWhence { JSXDR_SEEK_SET, JSXDR_SEEK_CUR, JSXDR_SEEK_END }

Functions

 JS_PUBLIC_API (void) JS_XDRInitBase(JSXDRState *xdr
 JS_PUBLIC_API (JSXDRState *) JS_XDRNewMem(JSContext *cx
 JS_PUBLIC_API (void *) JS_XDRMemGetData(JSXDRState *xdr
 JS_PUBLIC_API (uint32) JS_XDRMemDataLeft(JSXDRState *xdr)
 JS_PUBLIC_API (JSBool) JS_XDRUint8(JSXDRState *xdr
 JS_PUBLIC_API (JSClass *) JS_XDRFindClassById(JSXDRState *xdr
JSBool js_XDRAtom (JSXDRState *xdr, JSAtom **atomp)
JSBool js_XDRStringAtom (JSXDRState *xdr, JSAtom **atomp)
JSBool js_XDRCStringAtom (JSXDRState *xdr, JSAtom **atomp)

Variables

JSXDRMode mode
JSXDRMode JSContextcx
uint32lp
voiddata
void uint32 len
uint8b
uint16s
char * bytes
char ** sp
JSString ** strp
jsdouble ** dp
jsvalvp
JSScript ** scriptp
JSClassclasp
const char * name
uint32 id

Class Documentation

struct JSXDRState

Definition at line 109 of file jsxdrapi.h.

Collaboration diagram for JSXDRState:
Class Members
JSContext * cx
uintN maxclasses
JSXDRMode mode
uintN numclasses
JSXDROps * ops
void * reghash
JSClass ** registry
JSScript * script
void * userdata

Define Documentation

Definition at line 84 of file jsxdrapi.h.

#define JSXDR_BYTECODE_VERSION   (0xb973c0de - 29)

Definition at line 203 of file jsxdrapi.h.

#define JSXDR_MAGIC_SCRIPT_1   0xdead0001

Definition at line 187 of file jsxdrapi.h.

#define JSXDR_MAGIC_SCRIPT_2   0xdead0002

Definition at line 188 of file jsxdrapi.h.

#define JSXDR_MAGIC_SCRIPT_3   0xdead0003

Definition at line 189 of file jsxdrapi.h.

#define JSXDR_MAGIC_SCRIPT_4   0xdead0004

Definition at line 190 of file jsxdrapi.h.

#define JSXDR_MAGIC_SCRIPT_5   0xdead0005

Definition at line 191 of file jsxdrapi.h.

Definition at line 192 of file jsxdrapi.h.


Typedef Documentation

typedef enum JSXDRMode JSXDRMode
typedef struct JSXDROps JSXDROps
typedef enum JSXDRWhence JSXDRWhence

Enumeration Type Documentation

enum JSXDRMode
Enumerator:
JSXDR_ENCODE 
JSXDR_DECODE 
JSXDR_FREE 

Definition at line 86 of file jsxdrapi.h.

Enumerator:
JSXDR_SEEK_SET 
JSXDR_SEEK_CUR 
JSXDR_SEEK_END 

Definition at line 92 of file jsxdrapi.h.


Function Documentation

Definition at line 118 of file jslong.c.

{
    JSUint32 n0, n1, n2;
    JSUint32 q0, q1;
    JSUint32 rsh, lsh;

    n0 = a.lo;
    n1 = a.hi;

    if (b.hi == 0) {
        if (b.lo > n1) {
            /* (0 q0) = (n1 n0) / (0 D0) */

            lsh = CountLeadingZeros(b.lo);

            if (lsh) {
                /*
                 * Normalize, i.e. make the most significant bit of the
                 * denominator be set.
                 */
                b.lo = b.lo << lsh;
                n1 = (n1 << lsh) | (n0 >> (32 - lsh));
                n0 = n0 << lsh;
            }

            a.lo = n0, a.hi = n1;
            norm_udivmod32(&q0, &n0, a, b.lo);
            q1 = 0;

            /* remainder is in n0 >> lsh */
        } else {
            /* (q1 q0) = (n1 n0) / (0 d0) */

            if (b.lo == 0)              /* user wants to divide by zero! */
                b.lo = 1 / b.lo;        /* so go ahead and crash */

            lsh = CountLeadingZeros(b.lo);

            if (lsh == 0) {
                /*
                 * From (n1 >= b.lo)
                 *   && (the most significant bit of b.lo is set),
                 * conclude that
                 *      (the most significant bit of n1 is set)
                 *   && (the leading quotient digit q1 = 1).
                 *
                 * This special case is necessary, not an optimization
                 * (Shifts counts of 32 are undefined).
                 */
                n1 -= b.lo;
                q1 = 1;
            } else {
                /*
                 * Normalize.
                 */
                rsh = 32 - lsh;

                b.lo = b.lo << lsh;
                n2 = n1 >> rsh;
                n1 = (n1 << lsh) | (n0 >> rsh);
                n0 = n0 << lsh;

                a.lo = n1, a.hi = n2;
                norm_udivmod32(&q1, &n1, a, b.lo);
            }

            /* n1 != b.lo... */

            a.lo = n0, a.hi = n1;
            norm_udivmod32(&q0, &n0, a, b.lo);

            /* remainder in n0 >> lsh */
        }

        if (rp) {
            rp->lo = n0 >> lsh;
            rp->hi = 0;
        }
    } else {
        if (b.hi > n1) {
            /* (0 0) = (n1 n0) / (D1 d0) */

            q0 = 0;
            q1 = 0;

            /* remainder in (n1 n0) */
            if (rp) {
                rp->lo = n0;
                rp->hi = n1;
            }
        } else {
            /* (0 q0) = (n1 n0) / (d1 d0) */

            lsh = CountLeadingZeros(b.hi);
            if (lsh == 0) {
                /*
                 * From (n1 >= b.hi)
                 *   && (the most significant bit of b.hi is set),
                 * conclude that
                 *      (the most significant bit of n1 is set)
                 *   && (the quotient digit q0 = 0 or 1).
                 *
                 * This special case is necessary, not an optimization.
                 */

                /*
                 * The condition on the next line takes advantage of that
                 * n1 >= b.hi (true due to control flow).
                 */
                if (n1 > b.hi || n0 >= b.lo) {
                    q0 = 1;
                    a.lo = n0, a.hi = n1;
                    JSLL_SUB(a, a, b);
                } else {
                    q0 = 0;
                }
                q1 = 0;

                if (rp) {
                    rp->lo = n0;
                    rp->hi = n1;
                }
            } else {
                JSInt64 m;

                /*
                 * Normalize.
                 */
                rsh = 32 - lsh;

                b.hi = (b.hi << lsh) | (b.lo >> rsh);
                b.lo = b.lo << lsh;
                n2 = n1 >> rsh;
                n1 = (n1 << lsh) | (n0 >> rsh);
                n0 = n0 << lsh;

                a.lo = n1, a.hi = n2;
                norm_udivmod32(&q0, &n1, a, b.hi);
                JSLL_MUL32(m, q0, b.lo);

                if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
                    q0--;
                    JSLL_SUB(m, m, b);
                }

                q1 = 0;

                /* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
                if (rp) {
                    a.lo = n0, a.hi = n1;
                    JSLL_SUB(a, a, m);
                    rp->lo = (a.hi << rsh) | (a.lo >> lsh);
                    rp->hi = a.hi >> lsh;
                }
            }
        }
    }

    if (qp) {
        qp->lo = q0;
        qp->hi = q1;
    }
}

Here is the call graph for this function:

Definition at line 58 of file jslog2.c.

{
    JSIntn log2;

    JS_FLOOR_LOG2(log2, n);
    return log2;
}
JSBool js_XDRAtom ( JSXDRState xdr,
JSAtom **  atomp 
)

Definition at line 609 of file jsxdrapi.c.

{
    jsval v;
    uint32 type;
    jsdouble d;
    JSAtom *atom;

    if (xdr->mode == JSXDR_ENCODE) {
        v = ATOM_KEY(*atomp);
        return JS_XDRValue(xdr, &v);
    }

    /*
     * Inline JS_XDRValue when decoding to avoid ceation of GC things when
     * then corresponding atom already exists. See bug 321985.
     */
    if (!JS_XDRUint32(xdr, &type))
        return JS_FALSE;
    if (type == JSVAL_STRING)
        return js_XDRStringAtom(xdr, atomp);

    if (type == JSVAL_DOUBLE) {
        if (!XDRDoubleValue(xdr, &d))
            return JS_FALSE;
        atom = js_AtomizeDouble(xdr->cx, d, 0);
    } else {
        if (!XDRValueBody(xdr, type, &v))
            return JS_FALSE;
        atom = js_AtomizeValue(xdr->cx, v, 0);
    }

    if (!atom)
        return JS_FALSE;
    *atomp = atom;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_XDRCStringAtom ( JSXDRState xdr,
JSAtom **  atomp 
)

Definition at line 689 of file jsxdrapi.c.

{
    char *bytes;
    uint32 nbytes;
    JSAtom *atom;
    JSContext *cx;
    void *mark;

    if (xdr->mode == JSXDR_ENCODE) {
        JS_ASSERT(ATOM_IS_STRING(*atomp));
        bytes = JS_GetStringBytes(ATOM_TO_STRING(*atomp));
        return JS_XDRCString(xdr, &bytes);
    }

    /*
     * Inline JS_XDRCString when decoding not to malloc temporary buffer
     * just to free it after atomization. See bug 321985.
     */
    if (!JS_XDRUint32(xdr, &nbytes))
        return JS_FALSE;
    atom = NULL;
    cx = xdr->cx;
    mark = JS_ARENA_MARK(&cx->tempPool);
    JS_ARENA_ALLOCATE_CAST(bytes, char *, &cx->tempPool,
                           nbytes * sizeof *bytes);
    if (!bytes)
        JS_ReportOutOfMemory(cx);
    else if (JS_XDRBytes(xdr, bytes, nbytes))
        atom = js_Atomize(cx, bytes, nbytes, 0);
    JS_ARENA_RELEASE(&cx->tempPool, mark);
    if (!atom)
        return JS_FALSE;
    *atomp = atom;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_XDRStringAtom ( JSXDRState xdr,
JSAtom **  atomp 
)

Definition at line 647 of file jsxdrapi.c.

{
    JSString *str;
    uint32 nchars;
    JSAtom *atom;
    JSContext *cx;
    void *mark;
    jschar *chars;

    if (xdr->mode == JSXDR_ENCODE) {
        JS_ASSERT(ATOM_IS_STRING(*atomp));
        str = ATOM_TO_STRING(*atomp);
        return JS_XDRString(xdr, &str);
    }

    /*
     * Inline JS_XDRString when decoding to avoid JSString allocation
     * for already existing atoms. See bug 321985.
     */
    if (!JS_XDRUint32(xdr, &nchars))
        return JS_FALSE;
    atom = NULL;
    cx = xdr->cx;
    mark = JS_ARENA_MARK(&cx->tempPool);
    JS_ARENA_ALLOCATE_CAST(chars, jschar *, &cx->tempPool,
                           nchars * sizeof(jschar));
    if (!chars)
        JS_ReportOutOfMemory(cx);
    else if (XDRChars(xdr, chars, nchars))
        atom = js_AtomizeChars(cx, chars, nchars, 0);
    JS_ARENA_RELEASE(&cx->tempPool, mark);
    if (!atom)
        return JS_FALSE;
    *atomp = atom;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

uint8* b

Definition at line 143 of file jsxdrapi.h.

char* bytes

Definition at line 152 of file jsxdrapi.h.

Definition at line 176 of file jsxdrapi.h.

Definition at line 122 of file jsxdrapi.h.

Definition at line 131 of file jsxdrapi.h.

Definition at line 167 of file jsxdrapi.h.

Definition at line 182 of file jsxdrapi.h.

char uint32 len

Definition at line 131 of file jsxdrapi.h.

Definition at line 128 of file jsxdrapi.h.

Definition at line 122 of file jsxdrapi.h.

const char* name

Definition at line 179 of file jsxdrapi.h.

Definition at line 146 of file jsxdrapi.h.

Definition at line 173 of file jsxdrapi.h.

char ** sp

Definition at line 155 of file jsxdrapi.h.

XPTCursor char ** strp

Definition at line 161 of file jsxdrapi.h.

Definition at line 170 of file jsxdrapi.h.