Bug 795104 - Load source if needed in JS_DecompileScript. r=jorendorff

This commit is contained in:
Benjamin Peterson 2012-11-20 11:29:53 -06:00
parent 6194cd565d
commit 151faf7a36

View File

@ -5478,16 +5478,20 @@ JS_CompileFunction(JSContext *cx, JSObject *objArg, const char *name,
}
JS_PUBLIC_API(JSString *)
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent)
JS_DecompileScript(JSContext *cx, JSScript *scriptArg, const char *name, unsigned indent)
{
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
RootedScript script(cx, scriptArg);
RootedFunction fun(cx, script->function());
if (fun)
return JS_DecompileFunction(cx, fun, indent);
return script->sourceData(cx);
bool haveSource = script->scriptSource()->hasSourceData();
if (!haveSource && !JSScript::loadSource(cx, script, &haveSource))
return NULL;
return haveSource ? script->sourceData(cx) : js_NewStringCopyZ(cx, "[no source]");
}
JS_PUBLIC_API(JSString *)