Set the script's filename correctly and don't treat the lack of a filename as a failure. bug 391470, r+sr=bzbarsky
authormrbkap@gmail.com
Sat, 15 Sep 2007 09:51:12 -0700
changeset 5898 3bf9731919704fd256be98aa463ac5e2ce4ed07a
parent 5897 01eef49a1401f5b771dfec3f630ffc6e17451211
child 5899 c4a1de4a1ab27b51714b25af3aaa00e97c630707
push idunknown
push userunknown
push dateunknown
bugs391470
milestone1.9a8pre
Set the script's filename correctly and don't treat the lack of a filename as a failure. bug 391470, r+sr=bzbarsky
dom/public/nsIScriptTimeoutHandler.h
dom/src/base/nsJSTimeoutHandler.cpp
--- a/dom/public/nsIScriptTimeoutHandler.h
+++ b/dom/public/nsIScriptTimeoutHandler.h
@@ -63,16 +63,18 @@ public:
   // the language's context as an event handler.  If this returns nsnull,
   // GetHandlerText() will be called to get the string.
   virtual void *GetScriptObject() = 0;
 
   // Get the handler text of not a compiled object.
   virtual const PRUnichar *GetHandlerText() = 0;
 
   // Get the location of the script.
+  // Note: The memory pointed to by aFileName is owned by the
+  // nsIScriptTimeoutHandler and should not be freed by the caller.
   virtual void GetLocation(const char **aFileName, PRUint32 *aLineNo) = 0;
 
   // If a script object, get the argv suitable for passing back to the
   // script context.
   virtual nsIArray *GetArgv() = 0;
 
   // Get the language version for this timeout.
   virtual PRUint32 GetScriptVersion() = 0;
--- a/dom/src/base/nsJSTimeoutHandler.cpp
+++ b/dom/src/base/nsJSTimeoutHandler.cpp
@@ -280,54 +280,51 @@ nsJSScriptTimeoutHandler::Init(nsIScript
   }
 
   if (expr) {
     if (!::JS_AddNamedRoot(cx, &mExpr, "timeout.mExpr")) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     mExpr = expr;
+
+    // Get the calling location.
+    const char *filename;
+    if (nsJSUtils::GetCallingLocation(cx, &filename, &mLineNo)) {
+      mFileName.Assign(filename);
+    }
   } else if (funobj) {
     if (!::JS_AddNamedRoot(cx, &mFunObj, "timeout.mFunObj")) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     mFunObj = funobj;
 
     // Create our arg array - leave an extra slot for a secret final argument
     // that indicates to the called function how "late" the timeout is.  We
     // will fill that in when SetLateness is called.
     nsCOMPtr<nsIArray> array;
     rv = NS_CreateJSArgv(cx, (argc > 1) ? argc - 1 : argc, nsnull,
                          getter_AddRefs(array));
     if (NS_FAILED(rv)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
+
     PRUint32 dummy;
     jsval *jsargv = nsnull;
     nsCOMPtr<nsIJSArgArray> jsarray(do_QueryInterface(array));
     jsarray->GetArgs(&dummy, reinterpret_cast<void **>(&jsargv));
+
     // must have worked - we own the impl! :)
     NS_ASSERTION(jsargv, "No argv!");
     for (PRInt32 i = 2; (PRUint32)i < argc; ++i) {
       jsargv[i - 2] = argv[i];
     }
     // final arg slot remains null, array has rooted vals.
     mArgv = array;
-
-    // Get the calling location.
-    const char *filename;
-    if (nsJSUtils::GetCallingLocation(cx, &filename, &mLineNo)) {
-      mFileName.Assign(filename);
-
-      if (mFileName.IsEmpty()) {
-        return NS_ERROR_OUT_OF_MEMORY;
-      }
-    }
-
   } else {
     NS_WARNING("No func and no expr - why are we here?");
   }
   *aInterval = interval;
   return NS_OK;
 }
 
 void nsJSScriptTimeoutHandler::SetLateness(PRIntervalTime aHowLate)