diff --git a/dom/base/TimeoutHandler.cpp b/dom/base/TimeoutHandler.cpp index 891e4c8f6a69..0e052966785e 100644 --- a/dom/base/TimeoutHandler.cpp +++ b/dom/base/TimeoutHandler.cpp @@ -29,6 +29,11 @@ void TimeoutHandler::GetLocation(const char** aFileName, uint32_t* aLineNo, *aColumn = mColumn; } +void TimeoutHandler::GetDescription(nsACString& aOutString) { + aOutString.AppendPrintf(" (%s:%d:%d)", mFileName.get(), + mLineNo, mColumn); +} + NS_IMPL_CYCLE_COLLECTION_0(TimeoutHandler) NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeoutHandler) @@ -84,6 +89,19 @@ NS_INTERFACE_MAP_END_INHERITING(TimeoutHandler) NS_IMPL_ADDREF_INHERITED(ScriptTimeoutHandler, TimeoutHandler) NS_IMPL_RELEASE_INHERITED(ScriptTimeoutHandler, TimeoutHandler) +void ScriptTimeoutHandler::GetDescription(nsACString& aOutString) { + if (mExpr.Length() > 15) { + aOutString.AppendPrintf( + " (%s:%d:%d)", + NS_ConvertUTF16toUTF8(Substring(mExpr, 0, 13)).get(), mFileName.get(), + mLineNo, mColumn); + } else { + aOutString.AppendPrintf(" (%s:%d:%d)", + NS_ConvertUTF16toUTF8(mExpr).get(), mFileName.get(), + mLineNo, mColumn); + } +} + //----------------------------------------------------------------------------- // CallbackTimeoutHandler //----------------------------------------------------------------------------- @@ -167,5 +185,9 @@ bool CallbackTimeoutHandler::Call(const char* aExecutionReason) { void CallbackTimeoutHandler::MarkForCC() { mFunction->MarkForCC(); } +void CallbackTimeoutHandler::GetDescription(nsACString& aOutString) { + mFunction->GetDescription(aOutString); +} + } // namespace dom } // namespace mozilla diff --git a/dom/base/TimeoutHandler.h b/dom/base/TimeoutHandler.h index c05bc616a26a..7bcd1914b1fd 100644 --- a/dom/base/TimeoutHandler.h +++ b/dom/base/TimeoutHandler.h @@ -34,6 +34,12 @@ class TimeoutHandler : public nsISupports { // nsITimeoutHandler and should not be freed by the caller. virtual void GetLocation(const char** aFileName, uint32_t* aLineNo, uint32_t* aColumn); + // Append a UTF-8 string to aOutString that describes the callback function, + // for use in logging or profiler markers. + // The string contains the function name and its source location, if + // available, in the following format: + // " (::)" + virtual void GetDescription(nsACString& aOutString); virtual void MarkForCC() {} protected: @@ -65,6 +71,7 @@ class ScriptTimeoutHandler : public TimeoutHandler { MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* /* unused */) override { return false; }; + virtual void GetDescription(nsACString& aOutString) override; protected: virtual ~ScriptTimeoutHandler() {} @@ -87,6 +94,7 @@ class CallbackTimeoutHandler final : public TimeoutHandler { MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* aExecutionReason) override; virtual void MarkForCC() override; + virtual void GetDescription(nsACString& aOutString) override; void ReleaseJSObjects();