Commit a383a5f8 authored by Jeff Walden's avatar Jeff Walden
Browse files

Bug 733602 - Various StringBuffer cleanups, mostly removing unimplemented methods. r=luke

--HG--
extra : rebase_source : 388d94bf9c332896d1b5d95aac53c4ca75e9fc97
parent ac584deb
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -186,13 +186,6 @@ js_BooleanToString(JSContext *cx, JSBool b)
    return cx->runtime->atomState.booleanAtoms[b ? 1 : 0];
}

/* This function implements E-262-3 section 9.8, toString. */
bool
js::BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb)
{
    return b ? sb.append("true") : sb.append("false");
}

namespace js {

bool
+0 −3
Original line number Diff line number Diff line
@@ -54,9 +54,6 @@ js_BooleanToString(JSContext *cx, JSBool b);

namespace js {

extern bool
BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb);

inline bool
BooleanGetPrimitiveValue(JSContext *cx, JSObject &obj, Value *vp);

+0 −20
Original line number Diff line number Diff line
@@ -3265,26 +3265,6 @@ js::ToStringSlow(JSContext *cx, const Value &arg)
    return str;
}

/* This function implements E-262-3 section 9.8, toString. */
bool
js::ValueToStringBufferSlow(JSContext *cx, const Value &arg, StringBuffer &sb)
{
    Value v = arg;
    if (!ToPrimitive(cx, JSTYPE_STRING, &v))
        return false;

    if (v.isString())
        return sb.append(v.toString());
    if (v.isNumber())
        return NumberValueToStringBuffer(cx, v, sb);
    if (v.isBoolean())
        return BooleanToStringBuffer(cx, v.toBoolean(), sb);
    if (v.isNull())
        return sb.append(cx->runtime->atomState.nullAtom);
    JS_ASSERT(v.isUndefined());
    return sb.append(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
}

JS_FRIEND_API(JSString *)
js_ValueToSource(JSContext *cx, const Value &v)
{
+8 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ StringBuffer::appendN(const jschar c, size_t n)
    return cb.appendN(c, n);
}

/* ES5 9.8 ToString, appending the result to the string buffer. */
extern bool
ValueToStringBufferSlow(JSContext *cx, const Value &v, StringBuffer &sb);

@@ -79,6 +80,13 @@ ValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb)
    return ValueToStringBufferSlow(cx, v, sb);
}

/* ES5 9.8 ToString for booleans, appending the result to the string buffer. */
inline bool
BooleanToStringBuffer(JSContext *cx, bool b, StringBuffer &sb)
{
    return b ? sb.append("true") : sb.append("false");
}

}  /* namespace js */

#endif /* StringBuffer_inl_h__ */
+22 −2
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@

#include "vm/StringBuffer.h"

#include "jsobjinlines.h"

#include "vm/String-inl.h"
#include "vm/StringBuffer-inl.h"

@@ -45,8 +47,7 @@ StringBuffer::finishString()
        return cx->runtime->atomState.emptyAtom;

    size_t length = cb.length();
    if (!checkLength(length))
        return NULL;
    JS_ASSERT(checkLength(length));

    JS_STATIC_ASSERT(JSShortString::MAX_SHORT_LENGTH < CharBuffer::InlineLength);
    if (JSShortString::lengthFits(length))
@@ -78,3 +79,22 @@ StringBuffer::finishAtom()
    cb.clear();
    return atom;
}

bool
js::ValueToStringBufferSlow(JSContext *cx, const Value &arg, StringBuffer &sb)
{
    Value v = arg;
    if (!ToPrimitive(cx, JSTYPE_STRING, &v))
        return false;

    if (v.isString())
        return sb.append(v.toString());
    if (v.isNumber())
        return NumberValueToStringBuffer(cx, v, sb);
    if (v.isBoolean())
        return BooleanToStringBuffer(cx, v.toBoolean(), sb);
    if (v.isNull())
        return sb.append(cx->runtime->atomState.nullAtom);
    JS_ASSERT(v.isUndefined());
    return sb.append(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
}
Loading