зеркало из https://github.com/mozilla/gecko-dev.git
Bug 503952 - Use JSTempVector in jsstr.cpp (r=waldo)
--HG-- extra : rebase_source : ac955b5d784ca8fc9a61129e580c2751beb4109f
This commit is contained in:
Родитель
111cd95dd8
Коммит
c39582637e
|
@ -5487,7 +5487,7 @@ JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
|
|||
JSONWriteCallback callback, void *data)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
if (!js_Stringify(cx, vp, replacer, space, cb))
|
||||
return false;
|
||||
return callback(cb.begin(), cb.size(), data);
|
||||
|
|
|
@ -1331,9 +1331,9 @@ js_MakeArraySlow(JSContext *cx, JSObject *obj)
|
|||
|
||||
/* Transfer ownership of buffer to returned string. */
|
||||
static inline JSBool
|
||||
BufferToString(JSContext *cx, JSCharVector &buf, jsval *rval)
|
||||
BufferToString(JSContext *cx, JSCharBuffer &cb, jsval *rval)
|
||||
{
|
||||
JSString *str = js_NewStringFromCharBuffer(cx, buf);
|
||||
JSString *str = js_NewStringFromCharBuffer(cx, cb);
|
||||
if (!str)
|
||||
return false;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
|
@ -1368,28 +1368,28 @@ array_toSource(JSContext *cx, uintN argc, jsval *vp)
|
|||
* This object will take responsibility for the jschar buffer until the
|
||||
* buffer is transferred to the returned JSString.
|
||||
*/
|
||||
JSCharVector buf(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
|
||||
/* Cycles/joins are indicated by sharp objects. */
|
||||
#if JS_HAS_SHARP_VARS
|
||||
if (IS_SHARP(he)) {
|
||||
JS_ASSERT(sharpchars != 0);
|
||||
buf.replaceRawBuffer(sharpchars, js_strlen(sharpchars));
|
||||
cb.replaceRawBuffer(sharpchars, js_strlen(sharpchars));
|
||||
goto make_string;
|
||||
} else if (sharpchars) {
|
||||
MAKE_SHARP(he);
|
||||
buf.replaceRawBuffer(sharpchars, js_strlen(sharpchars));
|
||||
cb.replaceRawBuffer(sharpchars, js_strlen(sharpchars));
|
||||
}
|
||||
#else
|
||||
if (IS_SHARP(he)) {
|
||||
if (!js_AppendLiteral(buf, "[]"))
|
||||
if (!js_AppendLiteral(cb, "[]"))
|
||||
goto out;
|
||||
cx->free(sharpchars);
|
||||
goto make_string;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!buf.append('['))
|
||||
if (!cb.append('['))
|
||||
goto out;
|
||||
|
||||
jsuint length;
|
||||
|
@ -1419,23 +1419,23 @@ array_toSource(JSContext *cx, uintN argc, jsval *vp)
|
|||
str->getCharsAndLength(chars, charlen);
|
||||
|
||||
/* Append element to buffer. */
|
||||
if (!buf.append(chars, charlen))
|
||||
if (!cb.append(chars, charlen))
|
||||
goto out;
|
||||
if (index + 1 != length) {
|
||||
if (!js_AppendLiteral(buf, ", "))
|
||||
if (!js_AppendLiteral(cb, ", "))
|
||||
goto out;
|
||||
} else if (hole) {
|
||||
if (!buf.append(','))
|
||||
if (!cb.append(','))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finalize the buffer. */
|
||||
if (!buf.append(']'))
|
||||
if (!cb.append(']'))
|
||||
goto out;
|
||||
|
||||
make_string:
|
||||
if (!BufferToString(cx, buf, vp))
|
||||
if (!BufferToString(cx, cb, vp))
|
||||
goto out;
|
||||
|
||||
ok = true;
|
||||
|
@ -1514,7 +1514,7 @@ array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
|
|||
* This object will take responsibility for the jschar buffer until the
|
||||
* buffer is transferred to the returned JSString.
|
||||
*/
|
||||
JSCharVector buf(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
|
||||
jsuint length;
|
||||
if (!js_GetLengthProperty(cx, obj, &length))
|
||||
|
@ -1542,19 +1542,19 @@ array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (!js_ValueToCharBuffer(cx, *rval, buf))
|
||||
if (!js_ValueToCharBuffer(cx, *rval, cb))
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Append the separator. */
|
||||
if (index + 1 != length) {
|
||||
if (!buf.append(sep, seplen))
|
||||
if (!cb.append(sep, seplen))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finalize the buffer. */
|
||||
if (!BufferToString(cx, buf, rval))
|
||||
if (!BufferToString(cx, cb, rval))
|
||||
goto out;
|
||||
|
||||
ok = true;
|
||||
|
|
|
@ -164,9 +164,9 @@ js_BooleanToString(JSContext *cx, JSBool b)
|
|||
|
||||
/* This function implements E-262-3 section 9.8, toString. */
|
||||
JSBool
|
||||
js_BooleanToCharBuffer(JSContext *cx, JSBool b, JSCharVector &buf)
|
||||
js_BooleanToCharBuffer(JSContext *cx, JSBool b, JSCharBuffer &cb)
|
||||
{
|
||||
return b ? js_AppendLiteral(buf, "true") : js_AppendLiteral(buf, "false");
|
||||
return b ? js_AppendLiteral(cb, "true") : js_AppendLiteral(cb, "false");
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
|
|
@ -74,7 +74,7 @@ extern JSString *
|
|||
js_BooleanToString(JSContext *cx, JSBool b);
|
||||
|
||||
extern JSBool
|
||||
js_BooleanToCharBuffer(JSContext *cx, JSBool b, JSCharVector &buf);
|
||||
js_BooleanToCharBuffer(JSContext *cx, JSBool b, JSCharBuffer &cb);
|
||||
|
||||
extern JSBool
|
||||
js_ValueToBoolean(jsval v);
|
||||
|
|
|
@ -866,7 +866,7 @@ js_NumberToString(JSContext *cx, jsdouble d)
|
|||
}
|
||||
|
||||
JSBool JS_FASTCALL
|
||||
js_NumberValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &buf)
|
||||
js_NumberValueToCharBuffer(JSContext *cx, jsval v, JSCharBuffer &cb)
|
||||
{
|
||||
/* Convert to C-string. */
|
||||
static const size_t arrSize = DTOSTR_STANDARD_BUFFER_SIZE;
|
||||
|
@ -887,10 +887,10 @@ js_NumberValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &buf)
|
|||
*/
|
||||
size_t cstrlen = strlen(cstr);
|
||||
JS_ASSERT(cstrlen < arrSize);
|
||||
size_t sizeBefore = buf.size();
|
||||
if (!buf.growBy(cstrlen))
|
||||
size_t sizeBefore = cb.size();
|
||||
if (!cb.growBy(cstrlen))
|
||||
return JS_FALSE;
|
||||
jschar *appendBegin = buf.begin() + sizeBefore;
|
||||
jschar *appendBegin = cb.begin() + sizeBefore;
|
||||
#ifdef DEBUG
|
||||
size_t oldcstrlen = cstrlen;
|
||||
JSBool ok =
|
||||
|
|
|
@ -194,7 +194,7 @@ js_NumberToString(JSContext *cx, jsdouble d);
|
|||
* append to the given buffer.
|
||||
*/
|
||||
extern JSBool JS_FASTCALL
|
||||
js_NumberValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &cb);
|
||||
js_NumberValueToCharBuffer(JSContext *cx, jsval v, JSCharBuffer &cb);
|
||||
|
||||
/*
|
||||
* Convert a value to a number. On exit JSVAL_IS_NULL(*vp) iff there was an
|
||||
|
|
|
@ -140,7 +140,7 @@ js_json_stringify(JSContext *cx, uintN argc, jsval *vp)
|
|||
if (!JS_ConvertArguments(cx, argc, argv, "v / o v", vp, &replacer, &space))
|
||||
return JS_FALSE;
|
||||
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
|
||||
if (!js_Stringify(cx, vp, replacer, space, cb))
|
||||
return JS_FALSE;
|
||||
|
@ -180,7 +180,7 @@ static const char backslash = '\\';
|
|||
static const char unicodeEscape[] = "\\u00";
|
||||
|
||||
static JSBool
|
||||
write_string(JSContext *cx, JSCharVector &cb, const jschar *buf, uint32 len)
|
||||
write_string(JSContext *cx, JSCharBuffer &cb, const jschar *buf, uint32 len)
|
||||
{
|
||||
if (!cb.append(quote))
|
||||
return JS_FALSE;
|
||||
|
@ -221,12 +221,12 @@ write_string(JSContext *cx, JSCharVector &cb, const jschar *buf, uint32 len)
|
|||
class StringifyContext
|
||||
{
|
||||
public:
|
||||
StringifyContext(JSContext *cx, JSCharVector &cb, JSObject *replacer)
|
||||
StringifyContext(JSContext *cx, JSCharBuffer &cb, JSObject *replacer)
|
||||
: cb(cb), gap(cx), replacer(replacer), depth(0)
|
||||
{}
|
||||
|
||||
JSCharVector &cb;
|
||||
JSCharVector gap;
|
||||
JSCharBuffer &cb;
|
||||
JSCharBuffer gap;
|
||||
JSObject *replacer;
|
||||
uint32 depth;
|
||||
};
|
||||
|
@ -529,7 +529,7 @@ Str(JSContext *cx, jsid id, JSObject *holder, StringifyContext *scx, jsval *vp,
|
|||
}
|
||||
|
||||
static JSBool
|
||||
InitializeGap(JSContext *cx, jsval space, JSCharVector &cb)
|
||||
InitializeGap(JSContext *cx, jsval space, JSCharBuffer &cb)
|
||||
{
|
||||
if (!JSVAL_IS_PRIMITIVE(space)) {
|
||||
JSClass *clasp = OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(space));
|
||||
|
@ -554,7 +554,8 @@ InitializeGap(JSContext *cx, jsval space, JSCharVector &cb)
|
|||
|
||||
JSBool
|
||||
js_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
|
||||
JSCharVector &cb) {
|
||||
JSCharBuffer &cb)
|
||||
{
|
||||
// XXX stack
|
||||
JSObject *stack = JS_NewArrayObject(cx, 0, NULL);
|
||||
if (!stack)
|
||||
|
|
|
@ -54,7 +54,7 @@ js_InitJSONClass(JSContext *cx, JSObject *obj);
|
|||
|
||||
extern JSBool
|
||||
js_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
|
||||
JSCharVector &cb);
|
||||
JSCharBuffer &cb);
|
||||
|
||||
extern JSBool js_TryJSON(JSContext *cx, jsval *vp);
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ extern "C++" {
|
|||
template <class T, size_t MinInlineCapacity = 0> class JSTempVector;
|
||||
|
||||
/* Common JSTempVector instantiations: */
|
||||
typedef JSTempVector<jschar, 32> JSCharVector;
|
||||
typedef JSTempVector<jschar, 32> JSCharBuffer;
|
||||
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
126
js/src/jsstr.cpp
126
js/src/jsstr.cpp
|
@ -1487,7 +1487,7 @@ struct ReplaceData {
|
|||
jsint leftIndex; /* left context index in base.str->chars */
|
||||
JSSubString dollarStr; /* for "$$" interpret_dollar result */
|
||||
bool globCalled; /* record whether replace_glob has been called */
|
||||
JSCharVector cb; /* buffer built during match_or_replace */
|
||||
JSCharBuffer cb; /* buffer built during match_or_replace */
|
||||
};
|
||||
|
||||
static JSSubString *
|
||||
|
@ -2730,7 +2730,7 @@ js_NewString(JSContext *cx, jschar *chars, size_t length)
|
|||
static const size_t sMinWasteSize = 16;
|
||||
|
||||
JSString *
|
||||
js_NewStringFromCharBuffer(JSContext *cx, JSCharVector &cb)
|
||||
js_NewStringFromCharBuffer(JSContext *cx, JSCharBuffer &cb)
|
||||
{
|
||||
if (cb.empty())
|
||||
return ATOM_TO_STRING(cx->runtime->atomState.emptyAtom);
|
||||
|
@ -2921,18 +2921,18 @@ js_ValueToString(JSContext *cx, jsval v)
|
|||
}
|
||||
|
||||
static inline JSBool
|
||||
pushAtom(JSAtom *atom, JSCharVector &buf)
|
||||
pushAtom(JSAtom *atom, JSCharBuffer &cb)
|
||||
{
|
||||
JSString *str = ATOM_TO_STRING(atom);
|
||||
const jschar *chars;
|
||||
size_t length;
|
||||
str->getCharsAndLength(chars, length);
|
||||
return buf.append(chars, length);
|
||||
return cb.append(chars, length);
|
||||
}
|
||||
|
||||
/* This function implements E-262-3 section 9.8, toString. */
|
||||
JS_FRIEND_API(JSBool)
|
||||
js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &buf)
|
||||
js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharBuffer &cb)
|
||||
{
|
||||
if (!JSVAL_IS_PRIMITIVE(v) && !JSVAL_TO_OBJECT(v)->defaultValue(cx, JSTYPE_STRING, &v))
|
||||
return JS_FALSE;
|
||||
|
@ -2942,16 +2942,16 @@ js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &buf)
|
|||
const jschar *chars;
|
||||
size_t length;
|
||||
str->getCharsAndLength(chars, length);
|
||||
return buf.append(chars, length);
|
||||
return cb.append(chars, length);
|
||||
}
|
||||
if (JSVAL_IS_NUMBER(v))
|
||||
return js_NumberValueToCharBuffer(cx, v, buf);
|
||||
return js_NumberValueToCharBuffer(cx, v, cb);
|
||||
if (JSVAL_IS_BOOLEAN(v))
|
||||
return js_BooleanToCharBuffer(cx, JSVAL_TO_BOOLEAN(v), buf);
|
||||
return js_BooleanToCharBuffer(cx, JSVAL_TO_BOOLEAN(v), cb);
|
||||
if (JSVAL_IS_NULL(v))
|
||||
return pushAtom(cx->runtime->atomState.nullAtom, buf);
|
||||
return pushAtom(cx->runtime->atomState.nullAtom, cb);
|
||||
JS_ASSERT(JSVAL_IS_VOID(v));
|
||||
return pushAtom(cx->runtime->atomState.typeAtoms[JSTYPE_VOID], buf);
|
||||
return pushAtom(cx->runtime->atomState.typeAtoms[JSTYPE_VOID], cb);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSString *)
|
||||
|
@ -4820,56 +4820,14 @@ const bool js_alnum[] = {
|
|||
|
||||
#define URI_CHUNK 64U
|
||||
|
||||
/* Concatenate jschars onto the buffer */
|
||||
static JSBool
|
||||
AddCharsToURI(JSContext *cx, JSCharBuffer *buf,
|
||||
const jschar *chars, size_t length)
|
||||
static inline bool
|
||||
TransferBufferToString(JSContext *cx, JSCharBuffer &cb, jsval *rval)
|
||||
{
|
||||
size_t total;
|
||||
jschar *newchars;
|
||||
|
||||
total = buf->length + length + 1;
|
||||
if (!buf->chars ||
|
||||
JS_HOWMANY(total, URI_CHUNK) > JS_HOWMANY(buf->length + 1, URI_CHUNK)) {
|
||||
total = JS_ROUNDUP(total, URI_CHUNK);
|
||||
newchars = (jschar *) cx->realloc(buf->chars,
|
||||
total * sizeof(jschar));
|
||||
if (!newchars)
|
||||
return JS_FALSE;
|
||||
buf->chars = newchars;
|
||||
}
|
||||
js_strncpy(buf->chars + buf->length, chars, length);
|
||||
buf->length += length;
|
||||
buf->chars[buf->length] = 0;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
TransferBufferToString(JSContext *cx, JSCharBuffer *cb, jsval *rval)
|
||||
{
|
||||
jschar *chars;
|
||||
size_t n;
|
||||
JSString *str;
|
||||
|
||||
/*
|
||||
* Shrinking realloc can fail (e.g., with a BSD-style allocator), but we
|
||||
* don't worry about that case here.
|
||||
*/
|
||||
n = cb->length;
|
||||
chars = (jschar *) cx->realloc(cb->chars, (n + 1) * sizeof(jschar));
|
||||
if (!chars)
|
||||
chars = cb->chars;
|
||||
str = js_NewString(cx, chars, n);
|
||||
JSString *str = js_NewStringFromCharBuffer(cx, cb);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
|
||||
/* Successful allocation transfer ownership of cb->chars to the string. */
|
||||
#ifdef DEBUG
|
||||
memset(cb, JS_FREE_PATTERN, sizeof *cb);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
return true;;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4884,7 +4842,7 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
|||
const jschar *unescapedSet2, jsval *rval)
|
||||
{
|
||||
size_t length, j, k, L;
|
||||
JSCharBuffer cb;
|
||||
JSCharBuffer cb(cx);
|
||||
const jschar *chars;
|
||||
jschar c, c2;
|
||||
uint32 v;
|
||||
|
@ -4898,9 +4856,6 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
cb.length = 0;
|
||||
cb.chars = NULL;
|
||||
|
||||
/* From this point the control must goto bad on failures. */
|
||||
hexBuf[0] = '%';
|
||||
hexBuf[3] = 0;
|
||||
|
@ -4908,13 +4863,13 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
|||
c = chars[k];
|
||||
if (js_strchr(unescapedSet, c) ||
|
||||
(unescapedSet2 && js_strchr(unescapedSet2, c))) {
|
||||
if (!AddCharsToURI(cx, &cb, &c, 1))
|
||||
goto bad;
|
||||
if (!cb.append(c))
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
if ((c >= 0xDC00) && (c <= 0xDFFF)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_URI, NULL);
|
||||
goto bad;
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (c < 0xD800 || c > 0xDBFF) {
|
||||
v = c;
|
||||
|
@ -4923,13 +4878,13 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
|||
if (k == length) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_URI, NULL);
|
||||
goto bad;
|
||||
return JS_FALSE;
|
||||
}
|
||||
c2 = chars[k];
|
||||
if ((c2 < 0xDC00) || (c2 > 0xDFFF)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_URI, NULL);
|
||||
goto bad;
|
||||
return JS_FALSE;
|
||||
}
|
||||
v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
|
||||
}
|
||||
|
@ -4937,27 +4892,20 @@ Encode(JSContext *cx, JSString *str, const jschar *unescapedSet,
|
|||
for (j = 0; j < L; j++) {
|
||||
hexBuf[1] = HexDigits[utf8buf[j] >> 4];
|
||||
hexBuf[2] = HexDigits[utf8buf[j] & 0xf];
|
||||
if (!AddCharsToURI(cx, &cb, hexBuf, 3))
|
||||
goto bad;
|
||||
if (!cb.append(hexBuf, 3))
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!TransferBufferToString(cx, &cb, rval))
|
||||
goto bad;
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
bad:
|
||||
cx->free(cb.chars);
|
||||
return JS_FALSE;
|
||||
return TransferBufferToString(cx, cb, rval);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
Decode(JSContext *cx, JSString *str, const jschar *reservedSet, jsval *rval)
|
||||
{
|
||||
size_t length, start, k;
|
||||
JSCharBuffer cb;
|
||||
JSCharBuffer cb(cx);
|
||||
const jschar *chars;
|
||||
jschar c, H;
|
||||
uint32 v;
|
||||
|
@ -4971,9 +4919,6 @@ Decode(JSContext *cx, JSString *str, const jschar *reservedSet, jsval *rval)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
cb.length = 0;
|
||||
cb.chars = NULL;
|
||||
|
||||
/* From this point the control must goto bad on failures. */
|
||||
for (k = 0; k < length; k++) {
|
||||
c = chars[k];
|
||||
|
@ -5015,36 +4960,31 @@ Decode(JSContext *cx, JSString *str, const jschar *reservedSet, jsval *rval)
|
|||
goto report_bad_uri;
|
||||
c = (jschar)((v & 0x3FF) + 0xDC00);
|
||||
H = (jschar)((v >> 10) + 0xD800);
|
||||
if (!AddCharsToURI(cx, &cb, &H, 1))
|
||||
goto bad;
|
||||
if (!cb.append(H))
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
c = (jschar)v;
|
||||
}
|
||||
}
|
||||
if (js_strchr(reservedSet, c)) {
|
||||
if (!AddCharsToURI(cx, &cb, &chars[start], (k - start + 1)))
|
||||
goto bad;
|
||||
if (!cb.append(chars + start, k - start + 1))
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
if (!AddCharsToURI(cx, &cb, &c, 1))
|
||||
goto bad;
|
||||
if (!cb.append(c))
|
||||
return JS_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!AddCharsToURI(cx, &cb, &c, 1))
|
||||
if (!cb.append(c))
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!TransferBufferToString(cx, &cb, rval))
|
||||
goto bad;
|
||||
|
||||
return JS_TRUE;
|
||||
return TransferBufferToString(cx, cb, rval);
|
||||
|
||||
report_bad_uri:
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_URI);
|
||||
/* FALL THROUGH */
|
||||
|
||||
bad:
|
||||
cx->free(cb.chars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -384,11 +384,6 @@ js_toLowerCase(JSContext *cx, JSString *str);
|
|||
extern JSString * JS_FASTCALL
|
||||
js_toUpperCase(JSContext *cx, JSString *str);
|
||||
|
||||
typedef struct JSCharBuffer {
|
||||
size_t length;
|
||||
jschar *chars;
|
||||
} JSCharBuffer;
|
||||
|
||||
struct JSSubString {
|
||||
size_t length;
|
||||
const jschar *chars;
|
||||
|
@ -593,7 +588,7 @@ js_NewString(JSContext *cx, jschar *chars, size_t length);
|
|||
* by js_NewString.
|
||||
*/
|
||||
extern JSString *
|
||||
js_NewStringFromCharBuffer(JSContext *cx, JSCharVector &cb);
|
||||
js_NewStringFromCharBuffer(JSContext *cx, JSCharBuffer &cb);
|
||||
|
||||
extern JSString *
|
||||
js_NewDependentString(JSContext *cx, JSString *base, size_t start,
|
||||
|
@ -634,7 +629,7 @@ js_ValueToString(JSContext *cx, jsval v);
|
|||
* passed buffer may have partial results appended.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharVector &cb);
|
||||
js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharBuffer &cb);
|
||||
|
||||
/*
|
||||
* Convert a value to its source expression, returning null after reporting
|
||||
|
|
|
@ -202,7 +202,7 @@ xml_isXMLName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
}
|
||||
|
||||
static inline bool
|
||||
AppendString(JSCharVector &cb, JSString *str)
|
||||
AppendString(JSCharBuffer &cb, JSString *str)
|
||||
{
|
||||
const jschar *chars, *end;
|
||||
str->getCharsAndEnd(chars, end);
|
||||
|
@ -2130,7 +2130,7 @@ bad:
|
|||
* These functions mutate cb, leaving it empty.
|
||||
*/
|
||||
static JSString *
|
||||
MakeXMLSpecialString(JSContext *cx, JSCharVector &cb,
|
||||
MakeXMLSpecialString(JSContext *cx, JSCharBuffer &cb,
|
||||
JSString *str, JSString *str2,
|
||||
const jschar *prefix, size_t prefixlength,
|
||||
const jschar *suffix, size_t suffixlength)
|
||||
|
@ -2148,7 +2148,7 @@ MakeXMLSpecialString(JSContext *cx, JSCharVector &cb,
|
|||
}
|
||||
|
||||
static JSString *
|
||||
MakeXMLCDATAString(JSContext *cx, JSCharVector &cb, JSString *str)
|
||||
MakeXMLCDATAString(JSContext *cx, JSCharBuffer &cb, JSString *str)
|
||||
{
|
||||
static const jschar cdata_prefix_ucNstr[] = {'<', '!', '[',
|
||||
'C', 'D', 'A', 'T', 'A',
|
||||
|
@ -2161,7 +2161,7 @@ MakeXMLCDATAString(JSContext *cx, JSCharVector &cb, JSString *str)
|
|||
}
|
||||
|
||||
static JSString *
|
||||
MakeXMLCommentString(JSContext *cx, JSCharVector &cb, JSString *str)
|
||||
MakeXMLCommentString(JSContext *cx, JSCharBuffer &cb, JSString *str)
|
||||
{
|
||||
static const jschar comment_prefix_ucNstr[] = {'<', '!', '-', '-'};
|
||||
static const jschar comment_suffix_ucNstr[] = {'-', '-', '>'};
|
||||
|
@ -2172,7 +2172,7 @@ MakeXMLCommentString(JSContext *cx, JSCharVector &cb, JSString *str)
|
|||
}
|
||||
|
||||
static JSString *
|
||||
MakeXMLPIString(JSContext *cx, JSCharVector &cb, JSString *name,
|
||||
MakeXMLPIString(JSContext *cx, JSCharBuffer &cb, JSString *name,
|
||||
JSString *value)
|
||||
{
|
||||
static const jschar pi_prefix_ucNstr[] = {'<', '?'};
|
||||
|
@ -2188,7 +2188,7 @@ MakeXMLPIString(JSContext *cx, JSCharVector &cb, JSString *name,
|
|||
* equals, a double quote, an attribute value, and a closing double quote.
|
||||
*/
|
||||
static bool
|
||||
AppendAttributeValue(JSContext *cx, JSCharVector &cb, JSString *valstr)
|
||||
AppendAttributeValue(JSContext *cx, JSCharBuffer &cb, JSString *valstr)
|
||||
{
|
||||
if (!cb.append('='))
|
||||
return false;
|
||||
|
@ -2202,7 +2202,7 @@ AppendAttributeValue(JSContext *cx, JSCharVector &cb, JSString *valstr)
|
|||
* These functions mutate cb, leaving it empty.
|
||||
*/
|
||||
static JSString *
|
||||
EscapeElementValue(JSContext *cx, JSCharVector &cb, JSString *str)
|
||||
EscapeElementValue(JSContext *cx, JSCharBuffer &cb, JSString *str)
|
||||
{
|
||||
size_t length;
|
||||
const jschar *start;
|
||||
|
@ -2237,7 +2237,7 @@ EscapeElementValue(JSContext *cx, JSCharVector &cb, JSString *str)
|
|||
* These functions mutate cb, leaving it empty.
|
||||
*/
|
||||
static JSString *
|
||||
EscapeAttributeValue(JSContext *cx, JSCharVector &cb, JSString *str,
|
||||
EscapeAttributeValue(JSContext *cx, JSCharBuffer &cb, JSString *str,
|
||||
JSBool quote)
|
||||
{
|
||||
size_t length;
|
||||
|
@ -2506,7 +2506,7 @@ XMLToXMLString(JSContext *cx, JSXML *xml, const JSXMLArray *ancestorNSes,
|
|||
uint32 indentLevel)
|
||||
{
|
||||
JSBool pretty, indentKids;
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
JSString *str, *prefix, *nsuri;
|
||||
uint32 i, n, nextIndentLevel;
|
||||
JSXMLArray empty, decls, ancdecls;
|
||||
|
@ -2878,7 +2878,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
|||
return js_ValueToString(cx, v);
|
||||
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, JSVAL_TO_STRING(v));
|
||||
}
|
||||
|
||||
|
@ -2889,7 +2889,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
|||
str = js_ValueToString(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, str);
|
||||
}
|
||||
|
||||
|
@ -7655,7 +7655,7 @@ js_ToAttributeName(JSContext *cx, jsval *vp)
|
|||
JSString *
|
||||
js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote)
|
||||
{
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeAttributeValue(cx, cb, str, quote);
|
||||
}
|
||||
|
||||
|
@ -7706,7 +7706,7 @@ js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, JSString *str2)
|
|||
JSString *
|
||||
js_EscapeElementValue(JSContext *cx, JSString *str)
|
||||
{
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, str);
|
||||
}
|
||||
|
||||
|
@ -8186,21 +8186,21 @@ js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
|
|||
JSString *
|
||||
js_MakeXMLCDATAString(JSContext *cx, JSString *str)
|
||||
{
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return MakeXMLCDATAString(cx, cb, str);
|
||||
}
|
||||
|
||||
JSString *
|
||||
js_MakeXMLCommentString(JSContext *cx, JSString *str)
|
||||
{
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return MakeXMLCommentString(cx, cb, str);
|
||||
}
|
||||
|
||||
JSString *
|
||||
js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str)
|
||||
{
|
||||
JSCharVector cb(cx);
|
||||
JSCharBuffer cb(cx);
|
||||
return MakeXMLPIString(cx, cb, name, str);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче