Bug 839376 (part 14) - More exact rooting in shell/js.cpp. r=sfink.

--HG--
extra : rebase_source : 5dbacfb158ff5ea3935c0378f1c691006cb013a8
This commit is contained in:
Nicholas Nethercote 2013-02-28 15:03:17 -08:00
parent 43ae09558d
commit ac52e6f319

View File

@ -209,15 +209,14 @@ class ToStringHelper
{
public:
ToStringHelper(JSContext *aCx, jsval v, bool aThrow = false)
: cx(aCx)
: cx(aCx), mStr(cx, JS_ValueToString(cx, v))
{
mStr = JS_ValueToString(cx, v);
if (!aThrow && !mStr)
ReportException(cx);
JS_AddNamedStringRoot(cx, &mStr, "Value ToString helper");
JS_AddNamedStringRoot(cx, mStr.address(), "Value ToString helper");
}
~ToStringHelper() {
JS_RemoveStringRoot(cx, &mStr);
JS_RemoveStringRoot(cx, mStr.address());
}
bool threw() { return !mStr; }
jsval getJSVal() { return STRING_TO_JSVAL(mStr); }
@ -228,7 +227,7 @@ class ToStringHelper
}
private:
JSContext *cx;
JSString *mStr;
RootedString mStr; // Objects of this class are always stack-allocated.
JSAutoByteString mBytes;
};
@ -357,8 +356,8 @@ ShellOperationCallback(JSContext *cx)
bool result;
if (!gTimeoutFunc.isNull()) {
jsval returnedValue;
if (!JS_CallFunctionValue(cx, NULL, gTimeoutFunc, 0, NULL, &returnedValue))
RootedValue returnedValue(cx);
if (!JS_CallFunctionValue(cx, NULL, gTimeoutFunc, 0, NULL, returnedValue.address()))
return false;
if (returnedValue.isBoolean())
result = returnedValue.toBoolean();
@ -1740,8 +1739,8 @@ TryNotes(JSContext *cx, HandleScript script, Sprinter *sp)
}
static bool
DisassembleScript(JSContext *cx, HandleScript script, JSFunction *fun, bool lines, bool recursive,
Sprinter *sp)
DisassembleScript(JSContext *cx, HandleScript script, HandleFunction fun, bool lines,
bool recursive, Sprinter *sp)
{
if (fun) {
Sprint(sp, "flags:");
@ -1910,7 +1909,7 @@ DisassFile(JSContext *cx, unsigned argc, jsval *vp)
Sprinter sprinter(cx);
if (!sprinter.init())
return false;
bool ok = DisassembleScript(cx, script, NULL, p.lines, p.recursive, &sprinter);
bool ok = DisassembleScript(cx, script, NullPtr(), p.lines, p.recursive, &sprinter);
if (ok)
fprintf(stdout, "%s\n", sprinter.string());
if (!ok)