diff --git a/mozilla/dom/public/nsIScriptTimeoutHandler.h b/mozilla/dom/public/nsIScriptTimeoutHandler.h index b02e95072e5..1ac0363b8f4 100644 --- a/mozilla/dom/public/nsIScriptTimeoutHandler.h +++ b/mozilla/dom/public/nsIScriptTimeoutHandler.h @@ -68,6 +68,8 @@ public: 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 diff --git a/mozilla/dom/src/base/nsJSTimeoutHandler.cpp b/mozilla/dom/src/base/nsJSTimeoutHandler.cpp index e1f49c14a2e..b2dd3e89eb7 100644 --- a/mozilla/dom/src/base/nsJSTimeoutHandler.cpp +++ b/mozilla/dom/src/base/nsJSTimeoutHandler.cpp @@ -285,6 +285,12 @@ nsJSScriptTimeoutHandler::Init(nsIScriptContext *aContext, PRBool *aIsInterval, } 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; @@ -301,10 +307,12 @@ nsJSScriptTimeoutHandler::Init(nsIScriptContext *aContext, PRBool *aIsInterval, if (NS_FAILED(rv)) { return NS_ERROR_OUT_OF_MEMORY; } + PRUint32 dummy; jsval *jsargv = nsnull; nsCOMPtr jsarray(do_QueryInterface(array)); jsarray->GetArgs(&dummy, reinterpret_cast(&jsargv)); + // must have worked - we own the impl! :) NS_ASSERTION(jsargv, "No argv!"); for (PRInt32 i = 2; (PRUint32)i < argc; ++i) { @@ -312,17 +320,6 @@ nsJSScriptTimeoutHandler::Init(nsIScriptContext *aContext, PRBool *aIsInterval, } // 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?"); }