Readd bug 548702's changes to jsapi.cpp, jsexn.cpp, jsfun.cpp, jsnum.cpp, and jsstr.cpp.

This commit is contained in:
Jeff Walden 2010-03-28 22:05:50 -07:00
parent 806a75e33e
commit f3cf631e3b
5 changed files with 121 additions and 171 deletions

View file

@ -438,7 +438,7 @@ JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp)
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx, v);
AutoValueRooter tvr(cx, v);
*dp = js_ValueToNumber(cx, tvr.addr());
return !JSVAL_IS_NULL(tvr.value());
}
@ -454,7 +454,7 @@ JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip)
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx, v);
AutoValueRooter tvr(cx, v);
*ip = js_ValueToECMAInt32(cx, tvr.addr());
return !JSVAL_IS_NULL(tvr.value());
}
@ -464,7 +464,7 @@ JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip)
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx, v);
AutoValueRooter tvr(cx, v);
*ip = js_ValueToECMAUint32(cx, tvr.addr());
return !JSVAL_IS_NULL(tvr.value());
}
@ -474,7 +474,7 @@ JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip)
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx, v);
AutoValueRooter tvr(cx, v);
*ip = js_ValueToInt32(cx, tvr.addr());
return !JSVAL_IS_NULL(tvr.value());
}
@ -484,7 +484,7 @@ JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip)
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx, v);
AutoValueRooter tvr(cx, v);
*ip = js_ValueToUint16(cx, tvr.addr());
return !JSVAL_IS_NULL(tvr.value());
}
@ -3083,7 +3083,7 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop,
JSScopeProperty *sprop = (JSScopeProperty *) prop;
if (sprop->isMethod()) {
JSAutoTempValueRooter root(cx, sprop);
AutoScopePropertyRooter root(cx, sprop);
JS_UNLOCK_OBJ(cx, obj2);
*vp = sprop->methodValue();
return OBJ_SCOPE(obj2)->methodReadBarrier(cx, sprop, vp);
@ -3841,7 +3841,6 @@ JS_PUBLIC_API(JSIdArray *)
JS_Enumerate(JSContext *cx, JSObject *obj)
{
jsint i, n;
jsval iter_state, num_properties;
jsid id;
JSIdArray *ida;
jsval *vector;
@ -3849,11 +3848,11 @@ JS_Enumerate(JSContext *cx, JSObject *obj)
CHECK_REQUEST(cx);
ida = NULL;
iter_state = JSVAL_NULL;
JSAutoEnumStateRooter tvr(cx, obj, &iter_state);
AutoEnumStateRooter iterState(cx, obj);
/* Get the number of properties to enumerate. */
if (!obj->enumerate(cx, JSENUMERATE_INIT, &iter_state, &num_properties))
jsval num_properties;
if (!obj->enumerate(cx, JSENUMERATE_INIT, iterState.addr(), &num_properties))
goto error;
if (!JSVAL_IS_INT(num_properties)) {
JS_ASSERT(0);
@ -3873,11 +3872,11 @@ JS_Enumerate(JSContext *cx, JSObject *obj)
i = 0;
vector = &ida->vector[0];
for (;;) {
if (!obj->enumerate(cx, JSENUMERATE_NEXT, &iter_state, &id))
if (!obj->enumerate(cx, JSENUMERATE_NEXT, iterState.addr(), &id))
goto error;
/* No more jsid's to enumerate ? */
if (iter_state == JSVAL_NULL)
if (iterState.state() == JSVAL_NULL)
break;
if (i == ida->length) {
@ -3891,8 +3890,6 @@ JS_Enumerate(JSContext *cx, JSObject *obj)
return SetIdArrayLength(cx, ida, i);
error:
if (!JSVAL_IS_NULL(iter_state))
obj->enumerate(cx, JSENUMERATE_DESTROY, &iter_state, 0);
if (ida)
JS_DestroyIdArray(cx, ida);
return NULL;
@ -3976,7 +3973,7 @@ JS_NewPropertyIterator(JSContext *cx, JSObject *obj)
* Note: we have to make sure that we root obj around the call to
* JS_Enumerate to protect against multiple allocations under it.
*/
JSAutoTempValueRooter tvr(cx, iterobj);
AutoValueRooter tvr(cx, iterobj);
ida = JS_Enumerate(cx, obj);
if (!ida)
return NULL;
@ -4627,7 +4624,6 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
JS_PUBLIC_API(JSObject *)
JS_NewScriptObject(JSContext *cx, JSScript *script)
{
JSTempValueRooter tvr;
JSObject *obj;
CHECK_REQUEST(cx);
@ -4636,16 +4632,19 @@ JS_NewScriptObject(JSContext *cx, JSScript *script)
JS_ASSERT(!script->u.object);
JS_PUSH_TEMP_ROOT_SCRIPT(cx, script, &tvr);
obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL);
if (obj) {
obj->setPrivate(script);
script->u.object = obj;
{
AutoScriptRooter root(cx, script);
obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL);
if (obj) {
obj->setPrivate(script);
script->u.object = obj;
#ifdef CHECK_SCRIPT_OWNER
script->owner = NULL;
script->owner = NULL;
#endif
}
}
JS_POP_TEMP_ROOT(cx, &tvr);
return obj;
}
@ -4723,7 +4722,6 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
const char *filename, uintN lineno)
{
JSFunction *fun;
JSTempValueRooter tvr;
JSAtom *funAtom, *argAtom;
uintN i;
@ -4741,47 +4739,48 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
if (!fun)
goto out2;
MUST_FLOW_THROUGH("out");
JS_PUSH_TEMP_ROOT_OBJECT(cx, FUN_OBJECT(fun), &tvr);
for (i = 0; i < nargs; i++) {
argAtom = js_Atomize(cx, argnames[i], strlen(argnames[i]), 0);
if (!argAtom) {
{
AutoValueRooter tvr(cx, FUN_OBJECT(fun));
MUST_FLOW_THROUGH("out");
for (i = 0; i < nargs; i++) {
argAtom = js_Atomize(cx, argnames[i], strlen(argnames[i]), 0);
if (!argAtom) {
fun = NULL;
goto out;
}
if (!js_AddLocal(cx, fun, argAtom, JSLOCAL_ARG)) {
fun = NULL;
goto out;
}
}
if (!JSCompiler::compileFunctionBody(cx, fun, principals,
chars, length, filename, lineno)) {
fun = NULL;
goto out;
}
if (!js_AddLocal(cx, fun, argAtom, JSLOCAL_ARG)) {
if (obj && funAtom &&
!obj->defineProperty(cx, ATOM_TO_JSID(funAtom), OBJECT_TO_JSVAL(FUN_OBJECT(fun)),
NULL, NULL, JSPROP_ENUMERATE)) {
fun = NULL;
goto out;
}
}
if (!JSCompiler::compileFunctionBody(cx, fun, principals,
chars, length, filename, lineno)) {
fun = NULL;
goto out;
}
if (obj &&
funAtom &&
!obj->defineProperty(cx, ATOM_TO_JSID(funAtom), OBJECT_TO_JSVAL(FUN_OBJECT(fun)),
NULL, NULL, JSPROP_ENUMERATE)) {
fun = NULL;
}
#ifdef JS_SCOPE_DEPTH_METER
if (fun && obj) {
JSObject *pobj = obj;
uintN depth = 1;
if (fun && obj) {
JSObject *pobj = obj;
uintN depth = 1;
while ((pobj = pobj->getParent()) != NULL)
++depth;
JS_BASIC_STATS_ACCUM(&cx->runtime->hostenvScopeDepthStats, depth);
}
while ((pobj = pobj->getParent()) != NULL)
++depth;
JS_BASIC_STATS_ACCUM(&cx->runtime->hostenvScopeDepthStats, depth);
}
#endif
out:
cx->weakRoots.finalizableNewborns[FINALIZE_FUNCTION] = fun;
JS_POP_TEMP_ROOT(cx, &tvr);
out:
cx->weakRoots.finalizableNewborns[FINALIZE_FUNCTION] = fun;
}
out2:
LAST_FRAME_CHECKS(cx, fun);
@ -4939,7 +4938,7 @@ JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
{
CHECK_REQUEST(cx);
JSAutoTempValueRooter tvr(cx);
AutoValueRooter tvr(cx);
JSAtom *atom = js_Atomize(cx, name, strlen(name), 0);
JSBool ok = atom &&
js_GetMethod(cx, obj, ATOM_TO_JSID(atom),

View file

@ -838,41 +838,34 @@ exn_toSource(JSContext *cx, uintN argc, jsval *vp)
return false;
*vp = STRING_TO_JSVAL(name);
JSTempValueRooter tvr;
JSBool ok;
{
MUST_FLOW_THROUGH("out");
JS_PUSH_TEMP_ROOT(cx, 3, localroots, &tvr);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(localroots), localroots);
#ifdef __GNUC__
message = filename = NULL;
#endif
ok = JS_GetProperty(cx, obj, js_message_str, &localroots[0]) &&
(message = js_ValueToSource(cx, localroots[0]));
if (!ok)
goto out;
if (!JS_GetProperty(cx, obj, js_message_str, &localroots[0]) ||
!(message = js_ValueToSource(cx, localroots[0]))) {
return false;
}
localroots[0] = STRING_TO_JSVAL(message);
ok = JS_GetProperty(cx, obj, js_fileName_str, &localroots[1]) &&
(filename = js_ValueToSource(cx, localroots[1]));
if (!ok)
goto out;
if (!JS_GetProperty(cx, obj, js_fileName_str, &localroots[1]) ||
!(filename = js_ValueToSource(cx, localroots[1]))) {
return false;
}
localroots[1] = STRING_TO_JSVAL(filename);
ok = JS_GetProperty(cx, obj, js_lineNumber_str, &localroots[2]);
if (!ok)
goto out;
if (!JS_GetProperty(cx, obj, js_lineNumber_str, &localroots[2]))
return false;
lineno = js_ValueToECMAUint32 (cx, &localroots[2]);
ok = !JSVAL_IS_NULL(localroots[2]);
if (!ok)
goto out;
if (JSVAL_IS_NULL(localroots[2]))
return false;
if (lineno != 0) {
lineno_as_str = js_ValueToString(cx, localroots[2]);
if (!lineno_as_str) {
ok = JS_FALSE;
goto out;
}
if (!lineno_as_str)
return false;
lineno_length = lineno_as_str->length();
} else {
lineno_as_str = NULL;
@ -903,10 +896,8 @@ exn_toSource(JSContext *cx, uintN argc, jsval *vp)
}
cp = chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
if (!chars) {
ok = JS_FALSE;
goto out;
}
if (!chars)
return false;
*cp++ = '('; *cp++ = 'n'; *cp++ = 'e'; *cp++ = 'w'; *cp++ = ' ';
js_strncpy(cp, name->chars(), name_length);
@ -943,16 +934,11 @@ exn_toSource(JSContext *cx, uintN argc, jsval *vp)
result = js_NewString(cx, chars, length);
if (!result) {
cx->free(chars);
ok = JS_FALSE;
goto out;
return false;
}
*vp = STRING_TO_JSVAL(result);
ok = JS_TRUE;
return true;
}
out:
JS_POP_TEMP_ROOT(cx, &tvr);
return JS_TRUE;
}
#endif
@ -1003,7 +989,7 @@ js_InitExceptionClasses(JSContext *cx, JSObject *obj)
return NULL;
PodArrayZero(roots);
JSAutoTempValueRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
#ifdef __GNUC__
error_proto = NULL; /* quell GCC overwarning */
@ -1161,9 +1147,7 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
/* Protect the newly-created strings below from nesting GCs. */
PodArrayZero(tv);
JSTempValueRooter tvr;
JS_PUSH_TEMP_ROOT(cx, JS_ARRAY_LENGTH(tv), tv, &tvr);
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(tv), tv);
/*
* Try to get an appropriate prototype by looking up the corresponding
@ -1207,7 +1191,6 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
reportp->flags |= JSREPORT_EXCEPTION;
out:
JS_POP_TEMP_ROOT(cx, &tvr);
cx->generatingError = JS_FALSE;
return ok;
}
@ -1229,10 +1212,7 @@ js_ReportUncaughtException(JSContext *cx)
return false;
PodArrayZero(roots);
JSBool ok = JS_TRUE;
JSTempValueRooter tvr;
JS_PUSH_TEMP_ROOT(cx, JS_ARRAY_LENGTH(roots), roots, &tvr);
MUST_FLOW_THROUGH("out");
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(roots), roots);
/*
* Because js_ValueToString below could error and an exception object
@ -1257,49 +1237,36 @@ js_ReportUncaughtException(JSContext *cx)
} else {
roots[1] = STRING_TO_JSVAL(str);
bytes = js_GetStringBytes(cx, str);
if (!bytes) {
ok = JS_FALSE;
goto out;
}
if (!bytes)
return false;
}
if (!reportp && exnObject && exnObject->getClass() == &js_ErrorClass) {
const char *filename;
uint32 lineno;
if (!JS_GetProperty(cx, exnObject, js_message_str, &roots[2])) {
ok = JS_FALSE;
goto out;
}
if (!JS_GetProperty(cx, exnObject, js_message_str, &roots[2]))
return false;
if (JSVAL_IS_STRING(roots[2])) {
bytes = js_GetStringBytes(cx, JSVAL_TO_STRING(roots[2]));
if (!bytes) {
ok = JS_FALSE;
goto out;
}
if (!bytes)
return false;
}
ok = JS_GetProperty(cx, exnObject, js_fileName_str, &roots[3]);
if (!ok)
goto out;
if (!JS_GetProperty(cx, exnObject, js_fileName_str, &roots[3]))
return false;
str = js_ValueToString(cx, roots[3]);
if (!str) {
ok = JS_FALSE;
goto out;
}
if (!str)
return false;
filename = StringToFilename(cx, str);
if (!filename) {
ok = JS_FALSE;
goto out;
}
if (!filename)
return false;
ok = JS_GetProperty(cx, exnObject, js_lineNumber_str, &roots[4]);
if (!ok)
goto out;
if (!JS_GetProperty(cx, exnObject, js_lineNumber_str, &roots[4]))
return false;
lineno = js_ValueToECMAUint32 (cx, &roots[4]);
ok = !JSVAL_IS_NULL(roots[4]);
if (!ok)
goto out;
if (JSVAL_IS_NULL(roots[4]))
return false;
reportp = &report;
PodZero(&report);
@ -1320,7 +1287,5 @@ js_ReportUncaughtException(JSContext *cx)
JS_ClearPendingException(cx);
}
out:
JS_POP_TEMP_ROOT(cx, &tvr);
return ok;
return true;
}

View file

@ -351,7 +351,7 @@ WrapEscapingClosure(JSContext *cx, JSStackFrame *fp, JSObject *funobj, JSFunctio
funobj, scopeChain);
if (!wfunobj)
return NULL;
JSAutoTempValueRooter tvr(cx, wfunobj);
AutoValueRooter tvr(cx, wfunobj);
JSFunction *wfun = (JSFunction *) wfunobj;
wfunobj->setPrivate(wfun);
@ -599,7 +599,7 @@ ArgSetter(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
if (!JS_ValueToId(cx, idval, &id))
return false;
JSAutoTempValueRooter tvr(cx);
AutoValueRooter tvr(cx);
return js_DeleteProperty(cx, obj, id, tvr.addr()) &&
js_SetProperty(cx, obj, id, vp);
}
@ -1584,8 +1584,6 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
uintN nargs, nvars, nupvars, n;
uint32 localsword; /* word for argument and variable counts */
uint32 flagsword; /* word for fun->u.i.nupvars and fun->flags */
JSTempValueRooter tvr;
JSBool ok;
cx = xdr->cx;
if (xdr->mode == JSXDR_ENCODE) {
@ -1594,13 +1592,13 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_NOT_SCRIPTED_FUNCTION,
JS_GetFunctionName(fun));
return JS_FALSE;
return false;
}
if (fun->u.i.wrapper) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_XDR_CLOSURE_WRAPPER,
JS_GetFunctionName(fun));
return JS_FALSE;
return false;
}
JS_ASSERT((fun->u.i.wrapper & ~1U) == 0);
firstword = (fun->u.i.skipmin << 2) | (fun->u.i.wrapper << 1) | !!fun->atom;
@ -1612,7 +1610,7 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
} else {
fun = js_NewFunction(cx, NULL, NULL, 0, JSFUN_INTERPRETED, NULL, NULL);
if (!fun)
return JS_FALSE;
return false;
FUN_OBJECT(fun)->clearParent();
FUN_OBJECT(fun)->clearProto();
#ifdef __GNUC__
@ -1620,18 +1618,15 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
#endif
}
/* From here on, control flow must flow through label out. */
MUST_FLOW_THROUGH("out");
JS_PUSH_TEMP_ROOT_OBJECT(cx, FUN_OBJECT(fun), &tvr);
ok = JS_TRUE;
AutoValueRooter tvr(cx, FUN_OBJECT(fun));
if (!JS_XDRUint32(xdr, &firstword))
goto bad;
return false;
if ((firstword & 1U) && !js_XDRStringAtom(xdr, &fun->atom))
goto bad;
return false;
if (!JS_XDRUint32(xdr, &localsword) ||
!JS_XDRUint32(xdr, &flagsword)) {
goto bad;
return false;
}
if (xdr->mode == JSXDR_DECODE) {
@ -1655,6 +1650,7 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
JSAtom *name;
JSLocalKind localKind;
bool ok = true;
mark = JS_ARENA_MARK(&xdr->cx->tempPool);
/*
@ -1673,13 +1669,13 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
bitmapLength * sizeof *bitmap);
if (!bitmap) {
js_ReportOutOfScriptQuota(xdr->cx);
ok = JS_FALSE;
ok = false;
goto release_mark;
}
if (xdr->mode == JSXDR_ENCODE) {
names = js_GetLocalNameArray(xdr->cx, fun, &xdr->cx->tempPool);
if (!names) {
ok = JS_FALSE;
ok = false;
goto release_mark;
}
PodZero(bitmap, bitmapLength);
@ -1734,19 +1730,18 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
goto release_mark;
}
}
ok = JS_TRUE;
release_mark:
JS_ARENA_RELEASE(&xdr->cx->tempPool, mark);
if (!ok)
goto out;
return false;
if (xdr->mode == JSXDR_DECODE)
js_FreezeLocalNames(cx, fun);
}
if (!js_XDRScript(xdr, &fun->u.i.script, false, NULL))
goto bad;
return false;
if (xdr->mode == JSXDR_DECODE) {
*objp = FUN_OBJECT(fun);
@ -1758,13 +1753,7 @@ js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp)
}
}
out:
JS_POP_TEMP_ROOT(cx, &tvr);
return ok;
bad:
ok = JS_FALSE;
goto out;
return true;
}
#else /* !JS_HAS_XDR */
@ -2689,26 +2678,26 @@ js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags)
JSStackFrame *fp;
uintN error;
const char *name, *source;
JSTempValueRooter tvr;
for (fp = js_GetTopStackFrame(cx); fp && !fp->regs; fp = fp->down)
continue;
name = source = NULL;
JS_PUSH_TEMP_ROOT_STRING(cx, NULL, &tvr);
AutoValueRooter tvr(cx);
if (flags & JSV2F_ITERATOR) {
error = JSMSG_BAD_ITERATOR;
name = js_iterator_str;
JSString *src = js_ValueToSource(cx, *vp);
if (!src)
goto out;
tvr.u.value = STRING_TO_JSVAL(src);
return;
tvr.setString(src);
JSString *qsrc = js_QuoteString(cx, src, 0);
if (!qsrc)
goto out;
tvr.u.value = STRING_TO_JSVAL(qsrc);
return;
tvr.setString(qsrc);
source = js_GetStringBytes(cx, qsrc);
if (!source)
goto out;
return;
} else if (flags & JSV2F_CONSTRUCT) {
error = JSMSG_NOT_CONSTRUCTOR;
} else {
@ -2724,9 +2713,6 @@ js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags)
: JSDVG_IGNORE_STACK,
*vp, NULL,
name, source);
out:
JS_POP_TEMP_ROOT(cx, &tvr);
}
/*

View file

@ -994,11 +994,11 @@ js_ValueToNumber(JSContext *cx, jsval *vp)
* vp roots obj so we cannot use it as an extra root for
* obj->defaultValue result when calling the hook.
*/
JSAutoTempValueRooter tvr(cx, v);
if (!obj->defaultValue(cx, JSTYPE_NUMBER, tvr.addr()))
AutoValueRooter gcr(cx, v);
if (!obj->defaultValue(cx, JSTYPE_NUMBER, gcr.addr()))
obj = NULL;
else
v = *vp = tvr.value();
v = *vp = gcr.value();
if (!obj) {
*vp = JSVAL_NULL;
return 0.0;

View file

@ -1636,7 +1636,7 @@ str_match(JSContext *cx, uintN argc, jsval *vp)
if (!g.normalizeRegExp(false, 1, argc, vp))
return false;
JSAutoTempValueRooter array(cx, JSVAL_NULL);
AutoValueRooter array(cx, JSVAL_NULL);
if (!DoMatch(cx, vp, str, g, MatchCallback, array.addr(), MATCH_ARGS))
return false;
@ -3328,7 +3328,7 @@ js_ValueToSource(JSContext *cx, jsval v)
}
JSAtom *atom = cx->runtime->atomState.toSourceAtom;
JSAutoTempValueRooter tvr(cx, JSVAL_NULL);
AutoValueRooter tvr(cx, JSVAL_NULL);
if (!js_TryMethod(cx, JSVAL_TO_OBJECT(v), atom, 0, NULL, tvr.addr()))
return NULL;
return js_ValueToString(cx, tvr.value());