Bug 795104 - Load source if needed in JS_DecompileScript. r=jorendorff
authorBenjamin Peterson <benjamin@python.org>
Tue, 20 Nov 2012 11:29:53 -0600
changeset 113795 19c1fef93710c212064f8dc0ae1a96151561b4c5
parent 113794 b1cb8ff6e836e1bb684910da15f220eeb887f52d
child 113796 75821787b3439313b43547d8016b68e2e3f299ff
push id23890
push userryanvm@gmail.com
push dateWed, 21 Nov 2012 02:43:32 +0000
treeherdermozilla-central@4f19e7fd8bea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs795104
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 795104 - Load source if needed in JS_DecompileScript. r=jorendorff
js/src/jsapi.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5473,26 +5473,30 @@ JS_CompileFunction(JSContext *cx, JSObje
     RootedObject obj(cx, objArg);
     CompileOptions options(cx);
     options.setFileAndLine(filename, lineno);
 
     return CompileFunction(cx, obj, options, name, nargs, argnames, ascii, length);
 }
 
 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 *)
 JS_DecompileFunction(JSContext *cx, JSFunction *funArg, unsigned indent)
 {
     JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);