Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
jsxdrapi.c File Reference
#include "jsstddef.h"
#include "jsconfig.h"
#include <string.h>
#include "jstypes.h"
#include "jsutil.h"
#include "jsdhash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsnum.h"
#include "jsobj.h"
#include "jsscript.h"
#include "jsstr.h"
#include "jsxdrapi.h"

Go to the source code of this file.

Classes

struct  JSXDRMemState
struct  JSRegHashEntry

Defines

#define DBG(x)   ((void)0)
#define MEM_BLOCK   8192
#define MEM_PRIV(xdr)   ((JSXDRMemState *)(xdr))
#define MEM_BASE(xdr)   (MEM_PRIV(xdr)->base)
#define MEM_COUNT(xdr)   (MEM_PRIV(xdr)->count)
#define MEM_LIMIT(xdr)   (MEM_PRIV(xdr)->limit)
#define MEM_LEFT(xdr, bytes)
#define MEM_NEED(xdr, bytes)
#define MEM_DATA(xdr)   ((void *)(MEM_BASE(xdr) + MEM_COUNT(xdr)))
#define MEM_INCR(xdr, bytes)   (MEM_COUNT(xdr) += (bytes))
#define JSVAL_XDRNULL   0x8
#define JSVAL_XDRVOID   0xA
#define CLASS_REGISTRY_MIN   8
#define CLASS_INDEX_TO_ID(i)   ((i)+1)
#define CLASS_ID_TO_INDEX(id)   ((id)-1)

Typedefs

typedef struct JSXDRMemState JSXDRMemState
typedef struct JSRegHashEntry JSRegHashEntry

Functions

static JSBool mem_get32 (JSXDRState *xdr, uint32 *lp)
static JSBool mem_set32 (JSXDRState *xdr, uint32 *lp)
static JSBool mem_getbytes (JSXDRState *xdr, char *bytes, uint32 len)
static JSBool mem_setbytes (JSXDRState *xdr, char *bytes, uint32 len)
static voidmem_raw (JSXDRState *xdr, uint32 len)
static JSBool mem_seek (JSXDRState *xdr, int32 offset, JSXDRWhence whence)
static uint32 mem_tell (JSXDRState *xdr)
static void mem_finalize (JSXDRState *xdr)
 JS_XDRInitBase (JSXDRState *xdr, JSXDRMode mode, JSContext *cx)
 JS_XDRNewMem (JSContext *cx, JSXDRMode mode)
 JS_XDRMemGetData (JSXDRState *xdr, uint32 *lp)
 JS_XDRMemSetData (JSXDRState *xdr, void *data, uint32 len)
 JS_XDRMemDataLeft (JSXDRState *xdr)
 JS_XDRMemResetData (JSXDRState *xdr)
 JS_XDRDestroy (JSXDRState *xdr)
 JS_XDRUint8 (JSXDRState *xdr, uint8 *b)
 JS_XDRUint16 (JSXDRState *xdr, uint16 *s)
 JS_XDRUint32 (JSXDRState *xdr, uint32 *lp)
 JS_XDRBytes (JSXDRState *xdr, char *bytes, uint32 len)
 JS_XDRCString (JSXDRState *xdr, char **sp)
 Convert between a C string and the XDR representation: leading 32-bit count, then counted vector of chars, then possibly \0 padding to multiple of 4.
 JS_XDRCStringOrNull (JSXDRState *xdr, char **sp)
static JSBool XDRChars (JSXDRState *xdr, jschar *chars, uint32 nchars)
 JS_XDRString (JSXDRState *xdr, JSString **strp)
 JS_XDRStringOrNull (JSXDRState *xdr, JSString **strp)
static JSBool XDRDoubleValue (JSXDRState *xdr, jsdouble *dp)
 JS_XDRDouble (JSXDRState *xdr, jsdouble **dpp)
static JSBool XDRValueBody (JSXDRState *xdr, uint32 type, jsval *vp)
 JS_XDRValue (JSXDRState *xdr, jsval *vp)
JSBool js_XDRAtom (JSXDRState *xdr, JSAtom **atomp)
JSBool js_XDRStringAtom (JSXDRState *xdr, JSAtom **atomp)
JSBool js_XDRCStringAtom (JSXDRState *xdr, JSAtom **atomp)
 JS_XDRScript (JSXDRState *xdr, JSScript **scriptp)
 JS_XDRRegisterClass (JSXDRState *xdr, JSClass *clasp, uint32 *idp)
 JS_XDRFindClassIdByName (JSXDRState *xdr, const char *name)
 JS_XDRFindClassById (JSXDRState *xdr, uint32 id)

Variables

static JSXDROps xdrmem_ops

Class Documentation

struct JSXDRMemState

Definition at line 63 of file jsxdrapi.c.

Class Members
char * base
uint32 count
uint32 limit
JSXDRState state
struct JSRegHashEntry

Definition at line 739 of file jsxdrapi.c.

Class Members
JSDHashEntryHdr hdr
uint32 index
const char * name

Define Documentation

#define CLASS_ID_TO_INDEX (   id)    ((id)-1)

Definition at line 737 of file jsxdrapi.c.

#define CLASS_INDEX_TO_ID (   i)    ((i)+1)

Definition at line 736 of file jsxdrapi.c.

Definition at line 735 of file jsxdrapi.c.

#define DBG (   x)    ((void)0)

Definition at line 60 of file jsxdrapi.c.

#define JSVAL_XDRNULL   0x8

Definition at line 523 of file jsxdrapi.c.

#define JSVAL_XDRVOID   0xA

Definition at line 524 of file jsxdrapi.c.

#define MEM_BASE (   xdr)    (MEM_PRIV(xdr)->base)

Definition at line 73 of file jsxdrapi.c.

#define MEM_BLOCK   8192

Definition at line 70 of file jsxdrapi.c.

#define MEM_COUNT (   xdr)    (MEM_PRIV(xdr)->count)

Definition at line 74 of file jsxdrapi.c.

#define MEM_DATA (   xdr)    ((void *)(MEM_BASE(xdr) + MEM_COUNT(xdr)))

Definition at line 104 of file jsxdrapi.c.

#define MEM_INCR (   xdr,
  bytes 
)    (MEM_COUNT(xdr) += (bytes))

Definition at line 105 of file jsxdrapi.c.

#define MEM_LEFT (   xdr,
  bytes 
)
Value:
JS_BEGIN_MACRO                                                            \
        if ((xdr)->mode == JSXDR_DECODE &&                                    \
            MEM_COUNT(xdr) + bytes > MEM_LIMIT(xdr)) {                        \
            JS_ReportErrorNumber((xdr)->cx, js_GetErrorMessage, NULL,         \
                                 JSMSG_END_OF_DATA);                          \
            return 0;                                                         \
        }                                                                     \
    JS_END_MACRO

Definition at line 77 of file jsxdrapi.c.

#define MEM_LIMIT (   xdr)    (MEM_PRIV(xdr)->limit)

Definition at line 75 of file jsxdrapi.c.

#define MEM_NEED (   xdr,
  bytes 
)
Value:
JS_BEGIN_MACRO                                                            \
        if ((xdr)->mode == JSXDR_ENCODE) {                                    \
            if (MEM_LIMIT(xdr) &&                                             \
                MEM_COUNT(xdr) + bytes > MEM_LIMIT(xdr)) {                    \
                uint32 limit_ = JS_ROUNDUP(MEM_COUNT(xdr) + bytes, MEM_BLOCK);\
                void *data_ = JS_realloc((xdr)->cx, MEM_BASE(xdr), limit_);   \
                if (!data_)                                                   \
                    return 0;                                                 \
                MEM_BASE(xdr) = data_;                                        \
                MEM_LIMIT(xdr) = limit_;                                      \
            }                                                                 \
        } else {                                                              \
            MEM_LEFT(xdr, bytes);                                             \
        }                                                                     \
    JS_END_MACRO

Definition at line 87 of file jsxdrapi.c.

#define MEM_PRIV (   xdr)    ((JSXDRMemState *)(xdr))

Definition at line 71 of file jsxdrapi.c.


Typedef Documentation

typedef struct JSXDRMemState JSXDRMemState

Function Documentation

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:

JS_XDRBytes ( JSXDRState xdr,
char *  bytes,
uint32  len 
)

Definition at line 344 of file jsxdrapi.c.

{
    uint32 padlen;
    static char padbuf[JSXDR_ALIGN-1];

    if (xdr->mode == JSXDR_ENCODE) {
        if (!xdr->ops->setbytes(xdr, bytes, len))
            return JS_FALSE;
    } else {
        if (!xdr->ops->getbytes(xdr, bytes, len))
            return JS_FALSE;
    }
    len = xdr->ops->tell(xdr);
    if (len % JSXDR_ALIGN) {
        padlen = JSXDR_ALIGN - (len % JSXDR_ALIGN);
        if (xdr->mode == JSXDR_ENCODE) {
            if (!xdr->ops->setbytes(xdr, padbuf, padlen))
                return JS_FALSE;
        } else {
            if (!xdr->ops->seek(xdr, padlen, JSXDR_SEEK_CUR))
                return JS_FALSE;
        }
    }
    return JS_TRUE;
}

Here is the caller graph for this function:

JS_XDRCString ( JSXDRState xdr,
char **  sp 
)

Convert between a C string and the XDR representation: leading 32-bit count, then counted vector of chars, then possibly \0 padding to multiple of 4.

Definition at line 376 of file jsxdrapi.c.

{
    uint32 len;

    if (xdr->mode == JSXDR_ENCODE)
        len = strlen(*sp);
    JS_XDRUint32(xdr, &len);
    if (xdr->mode == JSXDR_DECODE) {
        if (!(*sp = (char *) JS_malloc(xdr->cx, len + 1)))
            return JS_FALSE;
    }
    if (!JS_XDRBytes(xdr, *sp, len)) {
        if (xdr->mode == JSXDR_DECODE)
            JS_free(xdr->cx, *sp);
        return JS_FALSE;
    }
    if (xdr->mode == JSXDR_DECODE) {
        (*sp)[len] = '\0';
    } else if (xdr->mode == JSXDR_FREE) {
        JS_free(xdr->cx, *sp);
        *sp = NULL;
    }
    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:

JS_XDRCStringOrNull ( JSXDRState xdr,
char **  sp 
)

Definition at line 402 of file jsxdrapi.c.

{
    uint32 null = (*sp == NULL);
    if (!JS_XDRUint32(xdr, &null))
        return JS_FALSE;
    if (null) {
        *sp = NULL;
        return JS_TRUE;
    }
    return JS_XDRCString(xdr, sp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 297 of file jsxdrapi.c.

{
    JSContext *cx = xdr->cx;
    xdr->ops->finalize(xdr);
    if (xdr->registry) {
        JS_free(cx, xdr->registry);
        if (xdr->reghash)
            JS_DHashTableDestroy(xdr->reghash);
    }
    JS_free(cx, xdr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRDouble ( JSXDRState xdr,
jsdouble **  dpp 
)

Definition at line 506 of file jsxdrapi.c.

{
    jsdouble d;

    if (xdr->mode == JSXDR_ENCODE)
        d = **dpp;
    if (!XDRDoubleValue(xdr, &d))
        return JS_FALSE;
    if (xdr->mode == JSXDR_DECODE) {
        *dpp = JS_NewDouble(xdr->cx, d);
        if (!*dpp)
            return JS_FALSE;
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRFindClassById ( JSXDRState xdr,
uint32  id 
)

Definition at line 826 of file jsxdrapi.c.

{
    uintN i = CLASS_ID_TO_INDEX(id);

    if (i >= xdr->numclasses)
        return NULL;
    return xdr->registry[i];
}

Here is the caller graph for this function:

JS_XDRFindClassIdByName ( JSXDRState xdr,
const char *  name 
)

Definition at line 783 of file jsxdrapi.c.

{
    uintN i, numclasses;

    numclasses = xdr->numclasses;
    if (numclasses >= 10) {
        JSRegHashEntry *entry;

        /* Bootstrap reghash from registry on first overpopulated Find. */
        if (!xdr->reghash) {
            xdr->reghash = JS_NewDHashTable(JS_DHashGetStubOps(), NULL,
                                            sizeof(JSRegHashEntry),
                                            numclasses);
            if (xdr->reghash) {
                for (i = 0; i < numclasses; i++) {
                    JSClass *clasp = xdr->registry[i];
                    entry = (JSRegHashEntry *)
                        JS_DHashTableOperate(xdr->reghash, clasp->name,
                                             JS_DHASH_ADD);
                    entry->name = clasp->name;
                    entry->index = i;
                }
            }
        }

        /* If we managed to create reghash, use it for O(1) Find. */
        if (xdr->reghash) {
            entry = (JSRegHashEntry *)
                JS_DHashTableOperate(xdr->reghash, name, JS_DHASH_LOOKUP);
            if (JS_DHASH_ENTRY_IS_BUSY(&entry->hdr))
                return CLASS_INDEX_TO_ID(entry->index);
        }
    }

    /* Only a few classes, or we couldn't malloc reghash: use linear search. */
    for (i = 0; i < numclasses; i++) {
        if (!strcmp(name, xdr->registry[i]->name))
            return CLASS_INDEX_TO_ID(i);
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRInitBase ( JSXDRState xdr,
JSXDRMode  mode,
JSContext cx 
)

Definition at line 228 of file jsxdrapi.c.

{
    xdr->mode = mode;
    xdr->cx = cx;
    xdr->registry = NULL;
    xdr->numclasses = xdr->maxclasses = 0;
    xdr->reghash = NULL;
    xdr->userdata = NULL;
    xdr->script = NULL;
}

Here is the caller graph for this function:

Definition at line 281 of file jsxdrapi.c.

{
    if (xdr->ops != &xdrmem_ops)
        return 0;
    return MEM_LIMIT(xdr) - MEM_COUNT(xdr);
}

Here is the caller graph for this function:

JS_XDRMemGetData ( JSXDRState xdr,
uint32 lp 
)

Definition at line 262 of file jsxdrapi.c.

{
    if (xdr->ops != &xdrmem_ops)
        return NULL;
    *lp = MEM_COUNT(xdr);
    return MEM_BASE(xdr);
}

Here is the caller graph for this function:

Definition at line 289 of file jsxdrapi.c.

{
    if (xdr->ops != &xdrmem_ops)
        return;
    MEM_COUNT(xdr) = 0;
}

Here is the caller graph for this function:

JS_XDRMemSetData ( JSXDRState xdr,
void data,
uint32  len 
)

Definition at line 271 of file jsxdrapi.c.

{
    if (xdr->ops != &xdrmem_ops)
        return;
    MEM_LIMIT(xdr) = len;
    MEM_BASE(xdr) = data;
    MEM_COUNT(xdr) = 0;
}

Here is the caller graph for this function:

JS_XDRNewMem ( JSContext cx,
JSXDRMode  mode 
)

Definition at line 240 of file jsxdrapi.c.

{
    JSXDRState *xdr = (JSXDRState *) JS_malloc(cx, sizeof(JSXDRMemState));
    if (!xdr)
        return NULL;
    JS_XDRInitBase(xdr, mode, cx);
    if (mode == JSXDR_ENCODE) {
        if (!(MEM_BASE(xdr) = JS_malloc(cx, MEM_BLOCK))) {
            JS_free(cx, xdr);
            return NULL;
        }
    } else {
        /* XXXbe ok, so better not deref MEM_BASE(xdr) if not ENCODE */
        MEM_BASE(xdr) = NULL;
    }
    xdr->ops = &xdrmem_ops;
    MEM_COUNT(xdr) = 0;
    MEM_LIMIT(xdr) = MEM_BLOCK;
    return xdr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRRegisterClass ( JSXDRState xdr,
JSClass clasp,
uint32 idp 
)

Definition at line 746 of file jsxdrapi.c.

{
    uintN numclasses, maxclasses;
    JSClass **registry;

    numclasses = xdr->numclasses;
    maxclasses = xdr->maxclasses;
    if (numclasses == maxclasses) {
        maxclasses = (maxclasses == 0) ? CLASS_REGISTRY_MIN : maxclasses << 1;
        registry = (JSClass **)
            JS_realloc(xdr->cx, xdr->registry, maxclasses * sizeof(JSClass *));
        if (!registry)
            return JS_FALSE;
        xdr->registry = registry;
        xdr->maxclasses = maxclasses;
    } else {
        JS_ASSERT(numclasses && numclasses < maxclasses);
        registry = xdr->registry;
    }

    registry[numclasses] = clasp;
    if (xdr->reghash) {
        JSRegHashEntry *entry = (JSRegHashEntry *)
            JS_DHashTableOperate(xdr->reghash, clasp->name, JS_DHASH_ADD);
        if (!entry) {
            JS_ReportOutOfMemory(xdr->cx);
            return JS_FALSE;
        }
        entry->name = clasp->name;
        entry->index = numclasses;
    }
    *idp = CLASS_INDEX_TO_ID(numclasses);
    xdr->numclasses = ++numclasses;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRScript ( JSXDRState xdr,
JSScript **  scriptp 
)

Definition at line 726 of file jsxdrapi.c.

{
    if (!js_XDRScript(xdr, scriptp, NULL))
        return JS_FALSE;
    if (xdr->mode == JSXDR_DECODE)
        js_CallNewScriptHook(xdr->cx, *scriptp, NULL);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRString ( JSXDRState xdr,
JSString **  strp 
)

Definition at line 444 of file jsxdrapi.c.

{
    uint32 nchars;
    jschar *chars;

    if (xdr->mode == JSXDR_ENCODE)
        nchars = JSSTRING_LENGTH(*strp);
    if (!JS_XDRUint32(xdr, &nchars))
        return JS_FALSE;

    if (xdr->mode == JSXDR_DECODE) {
        chars = (jschar *) JS_malloc(xdr->cx, (nchars + 1) * sizeof(jschar));
        if (!chars)
            return JS_FALSE;
    } else {
        chars = JSSTRING_CHARS(*strp);
    }

    if (!XDRChars(xdr, chars, nchars))
        goto bad;
    if (xdr->mode == JSXDR_DECODE) {
        chars[nchars] = 0;
        *strp = JS_NewUCString(xdr->cx, chars, nchars);
        if (!*strp)
            goto bad;
    }
    return JS_TRUE;

bad:
    if (xdr->mode == JSXDR_DECODE)
        JS_free(xdr->cx, chars);
    return JS_FALSE;
}

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:

JS_XDRStringOrNull ( JSXDRState xdr,
JSString **  strp 
)

Definition at line 479 of file jsxdrapi.c.

{
    uint32 null = (*strp == NULL);
    if (!JS_XDRUint32(xdr, &null))
        return JS_FALSE;
    if (null) {
        *strp = NULL;
        return JS_TRUE;
    }
    return JS_XDRString(xdr, strp);
}

Here is the call graph for this function:

JS_XDRUint16 ( JSXDRState xdr,
uint16 s 
)

Definition at line 320 of file jsxdrapi.c.

{
    uint32 l = *s;
    if (!JS_XDRUint32(xdr, &l))
        return JS_FALSE;
    *s = (uint16) l;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_XDRUint32 ( JSXDRState xdr,
uint32 lp 
)

Definition at line 330 of file jsxdrapi.c.

{
    JSBool ok = JS_TRUE;
    if (xdr->mode == JSXDR_ENCODE) {
        uint32 xl = JSXDR_SWAB32(*lp);
        ok = xdr->ops->set32(xdr, &xl);
    } else if (xdr->mode == JSXDR_DECODE) {
        ok = xdr->ops->get32(xdr, lp);
        *lp = JSXDR_SWAB32(*lp);
    }
    return ok;
}

Here is the caller graph for this function:

JS_XDRUint8 ( JSXDRState xdr,
uint8 b 
)

Definition at line 310 of file jsxdrapi.c.

{
    uint32 l = *b;
    if (!JS_XDRUint32(xdr, &l))
        return JS_FALSE;
    *b = (uint8) l;
    return JS_TRUE;
}

Here is the call graph for this function:

JS_XDRValue ( JSXDRState xdr,
jsval vp 
)

Definition at line 593 of file jsxdrapi.c.

{
    uint32 type;

    if (xdr->mode == JSXDR_ENCODE) {
        if (JSVAL_IS_NULL(*vp))
            type = JSVAL_XDRNULL;
        else if (JSVAL_IS_VOID(*vp))
            type = JSVAL_XDRVOID;
        else
            type = JSVAL_TAG(*vp);
    }
    return JS_XDRUint32(xdr, &type) && XDRValueBody(xdr, type, vp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void mem_finalize ( JSXDRState xdr) [static]

Definition at line 217 of file jsxdrapi.c.

{
    JS_free(xdr->cx, MEM_BASE(xdr));
}

Here is the call graph for this function:

static JSBool mem_get32 ( JSXDRState xdr,
uint32 lp 
) [static]

Definition at line 108 of file jsxdrapi.c.

{
    MEM_LEFT(xdr, 4);
    *lp = *(uint32 *)MEM_DATA(xdr);
    MEM_INCR(xdr, 4);
    return JS_TRUE;
}
static JSBool mem_getbytes ( JSXDRState xdr,
char *  bytes,
uint32  len 
) [static]

Definition at line 126 of file jsxdrapi.c.

{
    MEM_LEFT(xdr, len);
    memcpy(bytes, MEM_DATA(xdr), len);
    MEM_INCR(xdr, len);
    return JS_TRUE;
}

Here is the call graph for this function:

static void* mem_raw ( JSXDRState xdr,
uint32  len 
) [static]

Definition at line 144 of file jsxdrapi.c.

{
    void *data;
    if (xdr->mode == JSXDR_ENCODE) {
        MEM_NEED(xdr, len);
    } else if (xdr->mode == JSXDR_DECODE) {
        MEM_LEFT(xdr, len);
    }
    data = MEM_DATA(xdr);
    MEM_INCR(xdr, len);
    return data;
}
static JSBool mem_seek ( JSXDRState xdr,
int32  offset,
JSXDRWhence  whence 
) [static]

Definition at line 158 of file jsxdrapi.c.

{
    switch (whence) {
      case JSXDR_SEEK_CUR:
        if ((int32)MEM_COUNT(xdr) + offset < 0) {
            JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
                                 JSMSG_SEEK_BEYOND_START);
            return JS_FALSE;
        }
        if (offset > 0)
            MEM_NEED(xdr, offset);
        MEM_COUNT(xdr) += offset;
        return JS_TRUE;
      case JSXDR_SEEK_SET:
        if (offset < 0) {
            JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
                                 JSMSG_SEEK_BEYOND_START);
            return JS_FALSE;
        }
        if (xdr->mode == JSXDR_ENCODE) {
            if ((uint32)offset > MEM_COUNT(xdr))
                MEM_NEED(xdr, offset - MEM_COUNT(xdr));
            MEM_COUNT(xdr) = offset;
        } else {
            if ((uint32)offset > MEM_LIMIT(xdr)) {
                JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
                                     JSMSG_SEEK_BEYOND_END);
                return JS_FALSE;
            }
            MEM_COUNT(xdr) = offset;
        }
        return JS_TRUE;
      case JSXDR_SEEK_END:
        if (offset >= 0 ||
            xdr->mode == JSXDR_ENCODE ||
            (int32)MEM_LIMIT(xdr) + offset < 0) {
            JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
                                 JSMSG_END_SEEK);
            return JS_FALSE;
        }
        MEM_COUNT(xdr) = MEM_LIMIT(xdr) + offset;
        return JS_TRUE;
      default: {
        char numBuf[12];
        JS_snprintf(numBuf, sizeof numBuf, "%d", whence);
        JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
                             JSMSG_WHITHER_WHENCE, numBuf);
        return JS_FALSE;
      }
    }
}

Here is the call graph for this function:

static JSBool mem_set32 ( JSXDRState xdr,
uint32 lp 
) [static]

Definition at line 117 of file jsxdrapi.c.

{
    MEM_NEED(xdr, 4);
    *(uint32 *)MEM_DATA(xdr) = *lp;
    MEM_INCR(xdr, 4);
    return JS_TRUE;
}
static JSBool mem_setbytes ( JSXDRState xdr,
char *  bytes,
uint32  len 
) [static]

Definition at line 135 of file jsxdrapi.c.

{
    MEM_NEED(xdr, len);
    memcpy(MEM_DATA(xdr), bytes, len);
    MEM_INCR(xdr, len);
    return JS_TRUE;
}

Here is the call graph for this function:

static uint32 mem_tell ( JSXDRState xdr) [static]

Definition at line 211 of file jsxdrapi.c.

{
    return MEM_COUNT(xdr);
}
static JSBool XDRChars ( JSXDRState xdr,
jschar chars,
uint32  nchars 
) [static]

Definition at line 415 of file jsxdrapi.c.

{
    uint32 i, padlen, nbytes;
    jschar *raw;

    nbytes = nchars * sizeof(jschar);
    padlen = nbytes % JSXDR_ALIGN;
    if (padlen) {
        padlen = JSXDR_ALIGN - padlen;
        nbytes += padlen;
    }
    if (!(raw = (jschar *) xdr->ops->raw(xdr, nbytes)))
        return JS_FALSE;
    if (xdr->mode == JSXDR_ENCODE) {
        for (i = 0; i != nchars; i++)
            raw[i] = JSXDR_SWAB16(chars[i]);
        if (padlen)
            memset((char *)raw + nbytes - padlen, 0, padlen);
    } else if (xdr->mode == JSXDR_DECODE) {
        for (i = 0; i != nchars; i++)
            chars[i] = JSXDR_SWAB16(raw[i]);
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool XDRDoubleValue ( JSXDRState xdr,
jsdouble dp 
) [static]

Definition at line 492 of file jsxdrapi.c.

{
    jsdpun u;

    if (xdr->mode == JSXDR_ENCODE)
        u.d = *dp;
    if (!JS_XDRUint32(xdr, &u.s.lo) || !JS_XDRUint32(xdr, &u.s.hi))
        return JS_FALSE;
    if (xdr->mode == JSXDR_DECODE)
        *dp = u.d;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool XDRValueBody ( JSXDRState xdr,
uint32  type,
jsval vp 
) [static]

Definition at line 527 of file jsxdrapi.c.

{
    switch (type) {
      case JSVAL_XDRNULL:
        *vp = JSVAL_NULL;
        break;
      case JSVAL_XDRVOID:
        *vp = JSVAL_VOID;
        break;
      case JSVAL_STRING: {
        JSString *str;
        if (xdr->mode == JSXDR_ENCODE)
            str = JSVAL_TO_STRING(*vp);
        if (!JS_XDRString(xdr, &str))
            return JS_FALSE;
        if (xdr->mode == JSXDR_DECODE)
            *vp = STRING_TO_JSVAL(str);
        break;
      }
      case JSVAL_DOUBLE: {
        jsdouble *dp;
        if (xdr->mode == JSXDR_ENCODE)
            dp = JSVAL_TO_DOUBLE(*vp);
        if (!JS_XDRDouble(xdr, &dp))
            return JS_FALSE;
        if (xdr->mode == JSXDR_DECODE)
            *vp = DOUBLE_TO_JSVAL(dp);
        break;
      }
      case JSVAL_OBJECT: {
        JSObject *obj;
        if (xdr->mode == JSXDR_ENCODE)
            obj = JSVAL_TO_OBJECT(*vp);
        if (!js_XDRObject(xdr, &obj))
            return JS_FALSE;
        if (xdr->mode == JSXDR_DECODE)
            *vp = OBJECT_TO_JSVAL(obj);
        break;
      }
      case JSVAL_BOOLEAN: {
        uint32 b;
        if (xdr->mode == JSXDR_ENCODE)
            b = (uint32) JSVAL_TO_BOOLEAN(*vp);
        if (!JS_XDRUint32(xdr, &b))
            return JS_FALSE;
        if (xdr->mode == JSXDR_DECODE)
            *vp = BOOLEAN_TO_JSVAL((JSBool) b);
        break;
      }
      default: {
        uint32 i;

        JS_ASSERT(type & JSVAL_INT);
        if (xdr->mode == JSXDR_ENCODE)
            i = (uint32) JSVAL_TO_INT(*vp);
        if (!JS_XDRUint32(xdr, &i))
            return JS_FALSE;
        if (xdr->mode == JSXDR_DECODE)
            *vp = INT_TO_JSVAL((int32) i);
        break;
      }
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

JSXDROps xdrmem_ops [static]
Initial value:

Definition at line 222 of file jsxdrapi.c.