Backout changeset 501c5ca70faa. a=bustage

This commit is contained in:
Robert Sayre 2010-12-08 20:01:30 -05:00
parent 801bd7e494
commit 50d341c9ea
9 changed files with 50 additions and 44 deletions

View File

@ -10,7 +10,11 @@
static JSBool
stringToId(JSContext *cx, const char *s, jsid *idp)
{
JSString *str = JS_NewStringCopyZ(cx, s);
char *buf = JS_strdup(cx, s);
if (!buf)
return false;
JSString *str = JS_NewString(cx, buf, strlen(s));
if (!str)
return false;

View File

@ -5118,12 +5118,8 @@ JS_NewString(JSContext *cx, char *bytes, size_t nbytes)
/* Free chars (but not bytes, which caller frees on error) if we fail. */
str = js_NewString(cx, chars, length);
if (!str) {
if (!str)
cx->free(chars);
return NULL;
}
js_free(bytes);
return str;
}

View File

@ -2955,12 +2955,6 @@ class JSAutoByteString {
js_free(mBytes);
}
/* Take ownership of the given byte array. */
void initBytes(char *bytes) {
JS_ASSERT(!mBytes);
mBytes = bytes;
}
char *encode(JSContext *cx, JSString *str) {
JS_ASSERT(!mBytes);
JS_ASSERT(cx);

View File

@ -2355,10 +2355,11 @@ date_toSource(JSContext *cx, uintN argc, Value *vp)
return JS_FALSE;
}
str = JS_NewStringCopyZ(cx, bytes);
js_free(bytes);
if (!str)
str = JS_NewString(cx, bytes, strlen(bytes));
if (!str) {
js_free(bytes);
return JS_FALSE;
}
vp->setString(str);
return JS_TRUE;
}

View File

@ -812,10 +812,11 @@ num_toLocaleString(JSContext *cx, uintN argc, Value *vp)
if (cx->localeCallbacks && cx->localeCallbacks->localeToUnicode)
return cx->localeCallbacks->localeToUnicode(cx, buf, Jsvalify(vp));
str = js_NewStringCopyN(cx, buf, size);
cx->free(buf);
if (!str)
str = JS_NewString(cx, buf, size);
if (!str) {
cx->free(buf);
return JS_FALSE;
}
vp->setString(str);
return JS_TRUE;

View File

@ -296,43 +296,42 @@ ToDisassemblySource(JSContext *cx, jsval v, JSAutoByteString *bytes)
if (clasp == &js_BlockClass) {
char *source = JS_sprintf_append(NULL, "depth %d {", OBJ_BLOCK_DEPTH(cx, obj));
if (!source)
return false;
Shape::Range r = obj->lastProperty()->all();
while (!r.empty()) {
const Shape &shape = r.front();
JSAutoByteString bytes;
if (!js_AtomToPrintableString(cx, JSID_TO_ATOM(shape.id), &bytes))
return false;
return NULL;
r.popFront();
source = JS_sprintf_append(source, "%s: %d%s",
bytes.ptr(), shape.shortid,
!r.empty() ? ", " : "");
if (!source)
return false;
}
source = JS_sprintf_append(source, "}");
if (!source)
return false;
bytes->setBytes(source);
return true;
return NULL;
JSString *str = JS_NewString(cx, source, strlen(source));
if (!str)
return NULL;
return bytes->encode(cx, str);
}
if (clasp == &js_FunctionClass) {
JSFunction *fun = GET_FUNCTION_PRIVATE(cx, obj);
JSString *str = JS_DecompileFunction(cx, fun, JS_DONT_PRETTY_PRINT);
if (!str)
return false;
return NULL;
return bytes->encode(cx, str);
}
if (clasp == &js_RegExpClass) {
AutoValueRooter tvr(cx);
if (!js_regexp_toString(cx, obj, tvr.addr()))
return false;
return NULL;
return bytes->encode(cx, JSVAL_TO_STRING(Jsvalify(tvr.value())));
}
}

View File

@ -1014,10 +1014,11 @@ Options(JSContext *cx, uintN argc, jsval *vp)
JS_ReportOutOfMemory(cx);
return JS_FALSE;
}
str = JS_NewStringCopyZ(cx, names);
free(names);
if (!str)
str = JS_NewString(cx, names, strlen(names));
if (!str) {
free(names);
return JS_FALSE;
}
*vp = STRING_TO_JSVAL(str);
return JS_TRUE;
}
@ -1136,10 +1137,11 @@ ReadLine(JSContext *cx, uintN argc, jsval *vp)
* Turn buf into a JSString. Note that buflength includes the trailing null
* character.
*/
str = JS_NewStringCopyN(cx, buf, sawNewline ? buflength - 1 : buflength);
JS_free(cx, buf);
if (!str)
str = JS_NewString(cx, buf, sawNewline ? buflength - 1 : buflength);
if (!str) {
JS_free(cx, buf);
return JS_FALSE;
}
*vp = STRING_TO_JSVAL(str);
return JS_TRUE;
@ -4142,10 +4144,12 @@ Snarf(JSContext *cx, uintN argc, jsval *vp)
return ok;
}
str = JS_NewStringCopyN(cx, buf, len);
JS_free(cx, buf);
if (!str)
buf[len] = '\0';
str = JS_NewString(cx, buf, len);
if (!str) {
JS_free(cx, buf);
return JS_FALSE;
}
*vp = STRING_TO_JSVAL(str);
return JS_TRUE;
}

View File

@ -824,10 +824,11 @@ Options(JSContext *cx, uintN argc, jsval *vp)
JS_ReportOutOfMemory(cx);
return JS_FALSE;
}
str = JS_NewStringCopyZ(cx, names);
free(names);
if (!str)
str = JS_NewString(cx, names, strlen(names));
if (!str) {
free(names);
return JS_FALSE;
}
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
return JS_TRUE;
}

View File

@ -91,10 +91,13 @@ ToStringGuts(XPCCallContext& ccx)
return JS_FALSE;
}
JSString* str = JS_NewStringCopyZ(ccx, sz);
JS_smprintf_free(sz);
JSString* str = JS_NewString(ccx, sz, strlen(sz));
if(!str)
{
JS_smprintf_free(sz);
// JS_ReportOutOfMemory already reported by failed JS_NewString
return JS_FALSE;
}
ccx.SetRetVal(STRING_TO_JSVAL(str));
return JS_TRUE;
@ -126,10 +129,13 @@ XPC_WN_Shared_ToString(JSContext *cx, uintN argc, jsval *vp)
if(!sz)
return JS_FALSE;
JSString* str = JS_NewStringCopyZ(cx, sz);
JS_smprintf_free(sz);
JSString* str = JS_NewString(cx, sz, strlen(sz));
if(!str)
{
JS_smprintf_free(sz);
return JS_FALSE;
}
*vp = STRING_TO_JSVAL(str);