Bug 325202: XDR uses lossless encoding for all string. r=brendan

This commit is contained in:
igor@mir2.org 2007-08-21 14:22:26 -07:00
parent 87ce0a4099
commit 7a9bf4d227
4 changed files with 5 additions and 61 deletions

View File

@ -1368,7 +1368,7 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
propAtom = JSID_TO_ATOM(JSID_UNHIDE_NAME(sprop->id));
if (!JS_XDRUint32(xdr, &type) ||
!JS_XDRUint32(xdr, &userid) ||
!js_XDRCStringAtom(xdr, &propAtom)) {
!js_XDRStringAtom(xdr, &propAtom)) {
if (mark)
JS_ARENA_RELEASE(&cx->tempPool, mark);
goto bad;
@ -1384,7 +1384,7 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
if (!JS_XDRUint32(xdr, &type) ||
!JS_XDRUint32(xdr, &userid) ||
!js_XDRCStringAtom(xdr, &propAtom)) {
!js_XDRStringAtom(xdr, &propAtom)) {
goto bad;
}
JS_ASSERT(type == JSXDR_FUNARG || type == JSXDR_FUNVAR ||

View File

@ -4648,7 +4648,7 @@ js_XDRObject(JSXDRState *xdr, JSObject **objp)
*/
if (!JS_XDRUint32(xdr, &classDef))
return JS_FALSE;
if (classDef == 1 && !js_XDRCStringAtom(xdr, &atom))
if (classDef == 1 && !js_XDRStringAtom(xdr, &atom))
return JS_FALSE;
if (!JS_XDRUint32(xdr, &classId))

View File

@ -675,56 +675,6 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp)
return JS_TRUE;
}
/*
* FIXME: This performs lossy conversion and we need to switch to
* js_XDRStringAtom while allowing to read older XDR files. See bug 325202.
*/
JSBool
js_XDRCStringAtom(JSXDRState *xdr, JSAtom **atomp)
{
JSString *str;
char *bytes;
JSBool ok;
uint32 nbytes;
JSAtom *atom;
JSContext *cx;
void *mark;
if (xdr->mode == JSXDR_ENCODE) {
JS_ASSERT(ATOM_IS_STRING(*atomp));
str = ATOM_TO_STRING(*atomp);
bytes = js_DeflateString(xdr->cx,
JSSTRING_CHARS(str),
JSSTRING_LENGTH(str));
if (!bytes)
return JS_FALSE;
ok = JS_XDRCString(xdr, &bytes);
JS_free(xdr->cx, bytes);
return ok;
}
/*
* Inline JS_XDRCString when decoding not to malloc temporary buffer
* just to free it after atomization. See bug 321985.
*/
if (!JS_XDRUint32(xdr, &nbytes))
return JS_FALSE;
atom = NULL;
cx = xdr->cx;
mark = JS_ARENA_MARK(&cx->tempPool);
JS_ARENA_ALLOCATE_CAST(bytes, char *, &cx->tempPool,
nbytes * sizeof *bytes);
if (!bytes)
JS_ReportOutOfMemory(cx);
else if (JS_XDRBytes(xdr, bytes, nbytes))
atom = js_Atomize(cx, bytes, nbytes, 0);
JS_ARENA_RELEASE(&cx->tempPool, mark);
if (!atom)
return JS_FALSE;
*atomp = atom;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
{

View File

@ -190,7 +190,8 @@ JS_XDRFindClassById(JSXDRState *xdr, uint32 id);
#define JSXDR_MAGIC_SCRIPT_4 0xdead0004
#define JSXDR_MAGIC_SCRIPT_5 0xdead0005
#define JSXDR_MAGIC_SCRIPT_6 0xdead0006
#define JSXDR_MAGIC_SCRIPT_CURRENT JSXDR_MAGIC_SCRIPT_6
#define JSXDR_MAGIC_SCRIPT_7 0xdead0007
#define JSXDR_MAGIC_SCRIPT_CURRENT JSXDR_MAGIC_SCRIPT_7
/*
* Bytecode version number. Decrement the second term whenever JS bytecode
@ -212,13 +213,6 @@ js_XDRAtom(JSXDRState *xdr, JSAtom **atomp);
extern JSBool
js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp);
/*
* FIXME: This is non-unicode version of js_XDRStringAtom that performs lossy
* conversion. Do not use it in the new code! See bug 325202.
*/
extern JSBool
js_XDRCStringAtom(JSXDRState *xdr, JSAtom **atomp);
JS_END_EXTERN_C
#endif /* ! jsxdrapi_h___ */