Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
jsbool.c File Reference
#include "jsstddef.h"
#include "jstypes.h"
#include "jsutil.h"
#include "jsapi.h"
#include "jsatom.h"
#include "jsbool.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsinterp.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsobj.h"
#include "jsstr.h"
#include "jsprf.h"

Go to the source code of this file.

Functions

static JSBool bool_toSource (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool bool_toString (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool bool_valueOf (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool Boolean (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSObjectjs_InitBooleanClass (JSContext *cx, JSObject *obj)
JSObjectjs_BooleanToObject (JSContext *cx, JSBool b)
JSStringjs_BooleanToString (JSContext *cx, JSBool b)
JSBool js_ValueToBoolean (JSContext *cx, jsval v, JSBool *bp)

Variables

JSClass js_BooleanClass
static JSFunctionSpec boolean_methods []

Function Documentation

static JSBool bool_toSource ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 69 of file jsbool.c.

{
    jsval v;
    char buf[32];
    JSString *str;

    if (JSVAL_IS_BOOLEAN((jsval)obj)) {
        v = (jsval)obj;
    } else {
        if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
            return JS_FALSE;
        v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
        if (!JSVAL_IS_BOOLEAN(v))
            return js_obj_toSource(cx, obj, argc, argv, rval);
    }
    JS_snprintf(buf, sizeof buf, "(new %s(%s))",
                js_BooleanClass.name,
                js_boolean_strs[JSVAL_TO_BOOLEAN(v) ? 1 : 0]);
    str = JS_NewStringCopyZ(cx, buf);
    if (!str)
        return JS_FALSE;
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool bool_toString ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 97 of file jsbool.c.

{
    jsval v;
    JSAtom *atom;
    JSString *str;

    if (JSVAL_IS_BOOLEAN((jsval)obj)) {
        v = (jsval)obj;
    } else {
        if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
            return JS_FALSE;
        v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
        if (!JSVAL_IS_BOOLEAN(v))
            return js_obj_toString(cx, obj, argc, argv, rval);
    }
    atom = cx->runtime->atomState.booleanAtoms[JSVAL_TO_BOOLEAN(v) ? 1 : 0];
    str = ATOM_TO_STRING(atom);
    if (!str)
        return JS_FALSE;
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool bool_valueOf ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 122 of file jsbool.c.

{
    if (JSVAL_IS_BOOLEAN((jsval)obj)) {
        *rval = (jsval)obj;
        return JS_TRUE;
    }
    if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
        return JS_FALSE;
    *rval = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
    return JS_TRUE;
}

Here is the call graph for this function:

static JSBool Boolean ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
) [static]

Definition at line 144 of file jsbool.c.

{
    JSBool b;
    jsval bval;

    if (argc != 0) {
        if (!js_ValueToBoolean(cx, argv[0], &b))
            return JS_FALSE;
        bval = BOOLEAN_TO_JSVAL(b);
    } else {
        bval = JSVAL_FALSE;
    }
    if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {
        *rval = bval;
        return JS_TRUE;
    }
    OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, bval);
    return JS_TRUE;
}

Here is the call graph for this function:

Definition at line 178 of file jsbool.c.

{
    JSObject *obj;

    obj = js_NewObject(cx, &js_BooleanClass, NULL, NULL);
    if (!obj)
        return NULL;
    OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, BOOLEAN_TO_JSVAL(b));
    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 190 of file jsbool.c.

{
    return ATOM_TO_STRING(cx->runtime->atomState.booleanAtoms[b ? 1 : 0]);
}

Definition at line 165 of file jsbool.c.

{
    JSObject *proto;

    proto = JS_InitClass(cx, obj, NULL, &js_BooleanClass, Boolean, 1,
                        NULL, boolean_methods, NULL, NULL);
    if (!proto)
        return NULL;
    OBJ_SET_SLOT(cx, proto, JSSLOT_PRIVATE, JSVAL_FALSE);
    return proto;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_ValueToBoolean ( JSContext cx,
jsval  v,
JSBool bp 
)

Definition at line 196 of file jsbool.c.

{
    JSBool b;
    jsdouble d;

    if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
        b = JS_FALSE;
    } else if (JSVAL_IS_OBJECT(v)) {
        if (!JS_VERSION_IS_ECMA(cx)) {
            if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
                return JS_FALSE;
            if (!JSVAL_IS_BOOLEAN(v))
                v = JSVAL_TRUE;         /* non-null object is true */
            b = JSVAL_TO_BOOLEAN(v);
        } else {
            b = JS_TRUE;
        }
    } else if (JSVAL_IS_STRING(v)) {
        b = JSSTRING_LENGTH(JSVAL_TO_STRING(v)) ? JS_TRUE : JS_FALSE;
    } else if (JSVAL_IS_INT(v)) {
        b = JSVAL_TO_INT(v) ? JS_TRUE : JS_FALSE;
    } else if (JSVAL_IS_DOUBLE(v)) {
        d = *JSVAL_TO_DOUBLE(v);
        b = (!JSDOUBLE_IS_NaN(d) && d != 0) ? JS_TRUE : JS_FALSE;
    } else {
        JS_ASSERT(JSVAL_IS_BOOLEAN(v));
        b = JSVAL_TO_BOOLEAN(v);
    }

    *bp = b;
    return JS_TRUE;
}

Here is the caller graph for this function:


Variable Documentation