Bug 800200: Print a deprecation warning to the console when JSD is first used. r=bholley a=sledru
authorJim Blandy <jimb@mozilla.com>
Fri, 14 Mar 2014 17:18:50 -0700
changeset 183375 9550ceef07ff7e02bd3073d3b77ca8fef83d1f85
parent 183374 e7f941c91aaa708e081cf2aa49ec9ab87cb1fe8c
child 183376 aaf8ce9166a5a0c26e9f4e129ae92f823e9e2a55
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, sledru
bugs800200
milestone29.0a2
Bug 800200: Print a deprecation warning to the console when JSD is first used. r=bholley a=sledru
js/jsd/idl/jsdIDebuggerService.idl
js/jsd/jsd_xpc.cpp
js/jsd/jsd_xpc.h
--- a/js/jsd/idl/jsdIDebuggerService.idl
+++ b/js/jsd/idl/jsdIDebuggerService.idl
@@ -39,18 +39,22 @@ interface jsdIScript;
 interface jsdIValue;
 interface jsdIObject;
 interface jsdIProperty;
 interface jsdIActivationCallback;
 
 /**
  * Debugger service. It is not a good idea to have more than one active client
  * of the debugger service.
+ *
+ * Note that all the APIs in this file are deprecated. All consumers of
+ * these interfaces should switch to using the new Debugger API, documented
+ * here: https://wiki.mozilla.org/Debugger
  */
-[scriptable, uuid(029b8f0a-aa84-47eb-a60f-1a4752b7ad06)]
+[scriptable, uuid(39609752-2d73-4019-a324-a374dee16d3c)]
 interface jsdIDebuggerService : nsISupports
 {
     /** Internal use only. */
     [noscript] readonly attribute JSDContext        JSDContext;
 
     /**
      * Called when an error or warning occurs.
      */
@@ -343,16 +347,26 @@ interface jsdIDebuggerService : nsISuppo
     unsigned long exitNestedEventLoop();
 
     /**
      * Output dump of JS heap.
      *
      * @param fileName Filename to dump the heap into.
      */
     void dumpHeap(in AUTF8String fileName);
+
+    /**
+     * Suppress console warnings about using JSD, which is a deprecated API.
+     *
+     * This applies only to the next call to asyncOn; any subsequent calls
+     * will elicit the warning, unless you call 'acknowledgeDeprecation'
+     * before each of them, too. This arrangement ensures that one add-on's
+     * acknowledgement doesn't suppress warnings for other add-ons.
+     */
+    void acknowledgeDeprecation();
 };
 
 /* callback interfaces */
 
 /**
  * Object representing a pattern of global object and/or url the debugger should
  * ignore. The debugger service itself will not modify properties of these
  * objects.
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -15,16 +15,17 @@
 #include "mozilla/ModuleUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsICategoryManager.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIThreadInternal.h"
+#include "nsIScriptError.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "nsMemory.h"
 #include "jsdebug.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
@@ -2458,21 +2459,40 @@ jsdService::On (void)
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 jsdService::AsyncOn (jsdIActivationCallback *activationCallback)
 {
     nsresult  rv;
 
+    // Warn that JSD is deprecated, unless the caller has told us
+    // that they know already.
+    if (mDeprecationAcknowledged) {
+        mDeprecationAcknowledged = false;
+    } else if (!mWarnedAboutDeprecation) {
+        // In any case, warn only once.
+        mWarnedAboutDeprecation = true;
+
+        // Ignore errors: simply being unable to print the message
+        // shouldn't (effectively) disable JSD.
+        nsContentUtils::ReportToConsoleNonLocalized(
+            NS_LITERAL_STRING("\
+The jsdIDebuggerService and its associated interfaces are deprecated. \
+Please use Debugger, via IJSDebugger, instead."),
+            nsIScriptError::warningFlag,
+            NS_LITERAL_CSTRING("JSD"),
+            nullptr);
+    }
+
     nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
     if (NS_FAILED(rv)) return rv;
 
     mActivationCallback = activationCallback;
-    
+
     return xpc->SetDebugModeWhenPossible(true, true);
 }
 
 NS_IMETHODIMP
 jsdService::RecompileForDebugMode (JSContext *cx, JSCompartment *comp, bool mode) {
   NS_ASSERTION(NS_IsMainThread(), "wrong thread");
   /* XPConnect now does this work itself, so this IDL entry point is no longer used. */
   return NS_ERROR_NOT_IMPLEMENTED;
@@ -3034,16 +3054,23 @@ jsdService::ExitNestedEventLoop (uint32_
         --mNestedLoopLevel;
     else
         return NS_ERROR_FAILURE;
 
     *_rval = mNestedLoopLevel;    
     return NS_OK;
 }    
 
+NS_IMETHODIMP
+jsdService::AcknowledgeDeprecation()
+{
+    mDeprecationAcknowledged = true;
+    return NS_OK;
+}
+
 /* hook attribute get/set functions */
 
 NS_IMETHODIMP
 jsdService::SetErrorHook (jsdIErrorHook *aHook)
 {
     mErrorHook = aHook;
 
     /* if the debugger isn't initialized, that's all we can do for now.  The
--- a/js/jsd/jsd_xpc.h
+++ b/js/jsd/jsd_xpc.h
@@ -257,17 +257,19 @@ class jsdService : public jsdIDebuggerSe
     NS_DECL_JSDIDEBUGGERSERVICE
 
     NS_DECL_CYCLE_COLLECTION_CLASS(jsdService)
 
     jsdService() : mOn(false), mPauseLevel(0),
                    mNestedLoopLevel(0), mCx(0), mRuntime(0), mErrorHook(0),
                    mBreakpointHook(0), mDebugHook(0), mDebuggerHook(0),
                    mInterruptHook(0), mScriptHook(0), mThrowHook(0),
-                   mTopLevelHook(0), mFunctionHook(0)
+                   mTopLevelHook(0), mFunctionHook(0),
+                   mWarnedAboutDeprecation(false),
+                   mDeprecationAcknowledged(false)
     {
     }
 
     virtual ~jsdService();
     
     static jsdService *GetService ();
 
     bool CheckInterruptHook() { return !!mInterruptHook; }
@@ -287,16 +289,24 @@ class jsdService : public jsdIDebuggerSe
     nsCOMPtr<jsdIExecutionHook> mDebugHook;
     nsCOMPtr<jsdIExecutionHook> mDebuggerHook;
     nsCOMPtr<jsdIExecutionHook> mInterruptHook;
     nsCOMPtr<jsdIScriptHook>    mScriptHook;
     nsCOMPtr<jsdIExecutionHook> mThrowHook;
     nsCOMPtr<jsdICallHook>      mTopLevelHook;
     nsCOMPtr<jsdICallHook>      mFunctionHook;
     nsCOMPtr<jsdIActivationCallback> mActivationCallback;
+
+    // True if we have ever printed a warning about JSD being deprecated.
+    // We only ever print the warning once.
+    bool mWarnedAboutDeprecation;
+
+    // True if the next call to asyncOn should not produce a warning,
+    // because the consumer called jsdIDebuggerService::acknowledgeDeprecation.
+    bool mDeprecationAcknowledged;
 };
 
 #endif /* JSDSERVICE_H___ */
 
 
 /* graveyard */
 
 #if 0