зеркало из https://github.com/mozilla/pjs.git
Bug 749617 - rm XDRState::codeString (r=njn,a=not-libxul)
--HG-- extra : rebase_source : de4e8eba904cd44a7b3d99edd85d841a359b83d5
This commit is contained in:
Родитель
a5abc32e37
Коммит
661470ec2b
|
@ -544,7 +544,7 @@ class GCConstList {
|
|||
Vector<Value> list;
|
||||
public:
|
||||
GCConstList(JSContext *cx) : list(cx) {}
|
||||
bool append(Value v) { return list.append(v); }
|
||||
bool append(Value v) { JS_ASSERT_IF(v.isString(), v.toString()->isAtom()); return list.append(v); }
|
||||
size_t length() const { return list.length(); }
|
||||
void finish(JSConstArray *array);
|
||||
};
|
||||
|
|
|
@ -665,14 +665,18 @@ bool
|
|||
js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
|
||||
{
|
||||
if (mode == XDR_ENCODE) {
|
||||
JSString *str = *atomp;
|
||||
return xdr->codeString(&str);
|
||||
uint32_t nchars = (*atomp)->length();
|
||||
if (!xdr->codeUint32(&nchars))
|
||||
return false;
|
||||
|
||||
jschar *chars = const_cast<jschar *>((*atomp)->getChars(xdr->cx()));
|
||||
if (!chars)
|
||||
return false;
|
||||
|
||||
return xdr->codeChars(chars, nchars);
|
||||
}
|
||||
|
||||
/*
|
||||
* Inline XDRState::codeString when decoding to avoid JSString allocation
|
||||
* for already existing atoms. See bug 321985.
|
||||
*/
|
||||
/* Avoid JSString allocation for already existing atoms. See bug 321985. */
|
||||
uint32_t nchars;
|
||||
if (!xdr->codeUint32(&nchars))
|
||||
return false;
|
||||
|
|
|
@ -308,7 +308,7 @@ XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
|
|||
enum ConstTag {
|
||||
SCRIPT_INT = 0,
|
||||
SCRIPT_DOUBLE = 1,
|
||||
SCRIPT_STRING = 2,
|
||||
SCRIPT_ATOM = 2,
|
||||
SCRIPT_TRUE = 3,
|
||||
SCRIPT_FALSE = 4,
|
||||
SCRIPT_NULL = 5,
|
||||
|
@ -322,7 +322,7 @@ XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
|
|||
} else if (vp->isDouble()) {
|
||||
tag = SCRIPT_DOUBLE;
|
||||
} else if (vp->isString()) {
|
||||
tag = SCRIPT_STRING;
|
||||
tag = SCRIPT_ATOM;
|
||||
} else if (vp->isTrue()) {
|
||||
tag = SCRIPT_TRUE;
|
||||
} else if (vp->isFalse()) {
|
||||
|
@ -359,14 +359,14 @@ XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
|
|||
vp->init(DoubleValue(d));
|
||||
break;
|
||||
}
|
||||
case SCRIPT_STRING: {
|
||||
JSString *str;
|
||||
case SCRIPT_ATOM: {
|
||||
JSAtom *atom;
|
||||
if (mode == XDR_ENCODE)
|
||||
str = vp->toString();
|
||||
if (!xdr->codeString(&str))
|
||||
atom = &vp->toString()->asAtom();
|
||||
if (!XDRAtom(xdr, &atom))
|
||||
return false;
|
||||
if (mode == XDR_DECODE)
|
||||
vp->init(StringValue(str));
|
||||
vp->init(StringValue(atom));
|
||||
break;
|
||||
}
|
||||
case SCRIPT_TRUE:
|
||||
|
|
|
@ -129,44 +129,6 @@ XDRState<mode>::codeChars(jschar *chars, size_t nchars)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert between a JS (Unicode) string and the XDR representation.
|
||||
*/
|
||||
template<XDRMode mode>
|
||||
bool
|
||||
XDRState<mode>::codeString(JSString **strp)
|
||||
{
|
||||
uint32_t nchars;
|
||||
jschar *chars;
|
||||
|
||||
if (mode == XDR_ENCODE)
|
||||
nchars = (*strp)->length();
|
||||
if (!codeUint32(&nchars))
|
||||
return false;
|
||||
|
||||
if (mode == XDR_DECODE)
|
||||
chars = (jschar *) cx()->malloc_((nchars + 1) * sizeof(jschar));
|
||||
else
|
||||
chars = const_cast<jschar *>((*strp)->getChars(cx()));
|
||||
if (!chars)
|
||||
return false;
|
||||
|
||||
if (!codeChars(chars, nchars))
|
||||
goto bad;
|
||||
if (mode == XDR_DECODE) {
|
||||
chars[nchars] = 0;
|
||||
*strp = JS_NewUCString(cx(), chars, nchars);
|
||||
if (!*strp)
|
||||
goto bad;
|
||||
}
|
||||
return true;
|
||||
|
||||
bad:
|
||||
if (mode == XDR_DECODE)
|
||||
Foreground::free_(chars);
|
||||
return false;
|
||||
}
|
||||
|
||||
template<XDRMode mode>
|
||||
static bool
|
||||
VersionCheck(XDRState<mode> *xdr)
|
||||
|
|
|
@ -287,7 +287,6 @@ class XDRState {
|
|||
}
|
||||
|
||||
bool codeChars(jschar *chars, size_t nchars);
|
||||
bool codeString(JSString **strp);
|
||||
|
||||
bool codeFunction(JSObject **objp);
|
||||
bool codeScript(JSScript **scriptp);
|
||||
|
|
Загрузка…
Ссылка в новой задаче