Bug 739694 - Fix script filename saving in exception traces (r=luke)
authorBill McCloskey <wmccloskey@mozilla.com>
Tue, 27 Mar 2012 14:41:50 -0700
changeset 90442 967263f4d02053b8a475a94141a95a8c59611738
parent 90441 add087add91aa8a02999eb6789a56ac492eb42d7
child 90443 2989466dba9e55b2c45a9a6130089617a6d5b085
push id7668
push userwmccloskey@mozilla.com
push dateTue, 27 Mar 2012 21:48:55 +0000
treeherdermozilla-inbound@967263f4d020 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs739694
milestone14.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 739694 - Fix script filename saving in exception traces (r=luke)
js/src/jit-test/tests/basic/bug739694-1.js
js/src/jit-test/tests/basic/bug739694-2.js
js/src/jsexn.cpp
js/src/jsscript.cpp
js/src/jsscript.h
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug739694-1.js
@@ -0,0 +1,12 @@
+function newFunc(x) { new Function(x)(); }; try { newFunc("\
+var g = newGlobal('new-compartment');\
+g.h = function () {\
+    names = foo.blaaaaaaaaaaaaah().environment.names();\
+};\
+g.eval('var obj = {a: 1};' + \"with ({a: 1, '0xcafe': 2, ' ': 3, '': 4, '0': 5}) h();\");\
+");
+} catch(exc1) {}
+function newFunc(x) { new Function(x)(); }; newFunc("\
+gczeal(2);\
+  a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this);\
+");
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug739694-2.js
@@ -0,0 +1,8 @@
+try {
+    ({
+        f: evalcx("evalcx(\"e\",newGlobal('new-compartment'))",
+                  newGlobal('new-compartment'))
+    })
+} catch (e) {}
+gc()
+gc()
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -369,17 +369,19 @@ InitExnPrivate(JSContext *cx, JSObject *
                 frame.argc = fp->numActualArgs();
                 if (!fp->forEachCanonicalActualArg(AppendWrappedArg(cx, values)))
                     return false;
             } else {
                 frame.funName = NULL;
                 frame.argc = 0;
             }
             if (fp->isScriptFrame()) {
-                frame.filename = fp->script()->filename;
+                frame.filename = SaveScriptFilename(cx, fp->script()->filename);
+                if (!frame.filename)
+                    return false;
                 frame.ulineno = PCToLineNumber(fp->script(), i.pc());
             } else {
                 frame.ulineno = 0;
                 frame.filename = NULL;
             }
         }
     }
 
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -384,19 +384,16 @@ XDRScriptConst(XDRState<mode> *xdr, Heap
       case SCRIPT_VOID:
         if (mode == XDR_DECODE)
             vp->init(UndefinedValue());
         break;
     }
     return true;
 }
 
-static const char *
-SaveScriptFilename(JSContext *cx, const char *filename);
-
 template<XDRMode mode>
 bool
 js::XDRScript(XDRState<mode> *xdr, JSScript **scriptp, JSScript *parentScript)
 {
     enum ScriptBits {
         NoScriptRval,
         SavedCallerFun,
         StrictModeCode,
@@ -831,18 +828,18 @@ JSScript::destroyCounts(JSContext *cx)
         pcCounters.counts = NULL;
     }
 }
 
 /*
  * Shared script filename management.
  */
 
-static const char *
-SaveScriptFilename(JSContext *cx, const char *filename)
+const char *
+js::SaveScriptFilename(JSContext *cx, const char *filename)
 {
     JSCompartment *comp = cx->compartment;
 
     ScriptFilenameTable::AddPtr p = comp->scriptFilenameTable.lookupForAdd(filename);
     if (!p) {
         size_t size = offsetof(ScriptFilenameEntry, filename) + strlen(filename) + 1;
         ScriptFilenameEntry *entry = (ScriptFilenameEntry *) cx->malloc_(size);
         if (!entry)
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -796,16 +796,19 @@ StackDepth(JSScript *script)
 extern JS_FRIEND_API(void)
 js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
 
 extern void
 js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
 
 namespace js {
 
+extern const char *
+SaveScriptFilename(JSContext *cx, const char *filename);
+
 extern void
 MarkScriptFilename(const char *filename);
 
 extern void
 SweepScriptFilenames(JSCompartment *comp);
 
 extern void
 FreeScriptFilenames(JSCompartment *comp);