Bug 1515214 - Add TimeoutHandler::GetDescription which just calls through to CallbackObject::GetDescription for CallbackTimeoutHandlers. r=smaug
authorMarkus Stange <mstange@themasta.com>
Wed, 10 Jul 2019 20:48:14 +0000
changeset 482262 835a18c6213d447af34dfa1fa19bcb8ae6dade86
parent 482261 a6ad66ea6ddd7dd14eafc95f5128ee15c40cae18
child 482263 442fa46b63e92bd597002f267ee4ec951dd86059
push id36272
push usercsabou@mozilla.com
push dateThu, 11 Jul 2019 04:03:34 +0000
treeherdermozilla-central@925e5936677c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1515214
milestone70.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 1515214 - Add TimeoutHandler::GetDescription which just calls through to CallbackObject::GetDescription for CallbackTimeoutHandlers. r=smaug Depends on D19192 Differential Revision: https://phabricator.services.mozilla.com/D37470
dom/base/TimeoutHandler.cpp
dom/base/TimeoutHandler.h
--- a/dom/base/TimeoutHandler.cpp
+++ b/dom/base/TimeoutHandler.cpp
@@ -24,16 +24,21 @@ bool TimeoutHandler::Call(const char* /*
 
 void TimeoutHandler::GetLocation(const char** aFileName, uint32_t* aLineNo,
                                  uint32_t* aColumn) {
   *aFileName = mFileName.get();
   *aLineNo = mLineNo;
   *aColumn = mColumn;
 }
 
+void TimeoutHandler::GetDescription(nsACString& aOutString) {
+  aOutString.AppendPrintf("<generic handler> (%s:%d:%d)", mFileName.get(),
+                          mLineNo, mColumn);
+}
+
 NS_IMPL_CYCLE_COLLECTION_0(TimeoutHandler)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeoutHandler)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(TimeoutHandler)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TimeoutHandler)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
@@ -79,16 +84,29 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptTimeoutHandler)
 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(
+        "<string handler (truncated): \"%s...\"> (%s:%d:%d)",
+        NS_ConvertUTF16toUTF8(Substring(mExpr, 0, 13)).get(), mFileName.get(),
+        mLineNo, mColumn);
+  } else {
+    aOutString.AppendPrintf("<string handler: \"%s\"> (%s:%d:%d)",
+                            NS_ConvertUTF16toUTF8(mExpr).get(), mFileName.get(),
+                            mLineNo, mColumn);
+  }
+}
+
 //-----------------------------------------------------------------------------
 // CallbackTimeoutHandler
 //-----------------------------------------------------------------------------
 
 CallbackTimeoutHandler::CallbackTimeoutHandler(
     JSContext* aCx, nsIGlobalObject* aGlobal, Function* aFunction,
     nsTArray<JS::Heap<JS::Value>>&& aArguments)
     : TimeoutHandler(aCx), mGlobal(aGlobal), mFunction(aFunction) {
@@ -162,10 +180,14 @@ bool CallbackTimeoutHandler::Call(const 
   JS::Rooted<JS::Value> ignoredVal(RootingCx());
   MOZ_KnownLive(mFunction)->Call(MOZ_KnownLive(mGlobal), mArgs, &ignoredVal, rv,
                                  aExecutionReason);
   return !rv.IsUncatchableException();
 }
 
 void CallbackTimeoutHandler::MarkForCC() { mFunction->MarkForCC(); }
 
+void CallbackTimeoutHandler::GetDescription(nsACString& aOutString) {
+  mFunction->GetDescription(aOutString);
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/base/TimeoutHandler.h
+++ b/dom/base/TimeoutHandler.h
@@ -29,16 +29,22 @@ class TimeoutHandler : public nsISupport
   NS_DECL_CYCLE_COLLECTION_CLASS(TimeoutHandler)
 
   MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* /* unused */);
   // Get the location of the script.
   // Note: The memory pointed to by aFileName is owned by the
   // 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:
+  // "<functionName> (<sourceURL>:<lineNumber>:<columnNumber>)"
+  virtual void GetDescription(nsACString& aOutString);
   virtual void MarkForCC() {}
 
  protected:
   TimeoutHandler() : mFileName(""), mLineNo(0), mColumn(0) {}
   explicit TimeoutHandler(JSContext* aCx);
 
   virtual ~TimeoutHandler() {}
 
@@ -60,16 +66,17 @@ class ScriptTimeoutHandler : public Time
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ScriptTimeoutHandler, TimeoutHandler)
 
   ScriptTimeoutHandler(JSContext* aCx, nsIGlobalObject* aGlobal,
                        const nsAString& aExpression);
 
   MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* /* unused */) override {
     return false;
   };
+  virtual void GetDescription(nsACString& aOutString) override;
 
  protected:
   virtual ~ScriptTimeoutHandler() {}
 
   nsCOMPtr<nsIGlobalObject> mGlobal;
   // The expression to evaluate or function to call. If mFunction is non-null
   // it should be used, else use mExpr.
   nsString mExpr;
@@ -82,16 +89,17 @@ class CallbackTimeoutHandler final : pub
                                                          TimeoutHandler)
 
   CallbackTimeoutHandler(JSContext* aCx, nsIGlobalObject* aGlobal,
                          Function* aFunction,
                          nsTArray<JS::Heap<JS::Value>>&& aArguments);
 
   MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* aExecutionReason) override;
   virtual void MarkForCC() override;
+  virtual void GetDescription(nsACString& aOutString) override;
 
   void ReleaseJSObjects();
 
  private:
   virtual ~CallbackTimeoutHandler() { ReleaseJSObjects(); }
 
   nsCOMPtr<nsIGlobalObject> mGlobal;
   RefPtr<Function> mFunction;