Esempio n. 1
0
JSString *
js_ObjectToString(JSContext *cx, JSObject *obj)
{
    jsval v, *mark, *argv;
    JSString *str;

    if (!obj)
	return ATOM_TO_STRING(cx->runtime->atomState.nullAtom);
    v = JSVAL_VOID;
    if (!obj->map->clasp->convert(cx, obj, JSTYPE_STRING, &v))
	return NULL;
    if (JSVAL_IS_STRING(v))
	return JSVAL_TO_STRING(v);

    /* Try the toString method if it's defined. */
    js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, NULL, &v);
    if (JSVAL_IS_STRING(v))
	return JSVAL_TO_STRING(v);
#if JS_BUG_EAGER_TOSTRING
    js_TryValueOf(cx, obj, JSTYPE_STRING, &v);
    if (JSVAL_IS_STRING(v))
	return JSVAL_TO_STRING(v);
#endif
    mark = PR_ARENA_MARK(&cx->stackPool);
    PR_ARENA_ALLOCATE(argv, &cx->stackPool, OBJ_TOSTRING_NARGS * sizeof(jsval));
    if (!argv || !js_obj_toString(cx, obj, OBJ_TOSTRING_NARGS, argv, &v))
	str = NULL;
    else
	str = JSVAL_TO_STRING(v);
    PR_ARENA_RELEASE(&cx->stackPool, mark);
    return str;
}
Esempio n. 2
0
void *
PORT_ArenaMark(PRArenaPool *arena)
{
    return PR_ARENA_MARK(arena);
}