diff --git a/js/jsd/idl/jsdIDebuggerService.idl b/js/jsd/idl/jsdIDebuggerService.idl index 0a50b61341a..4c5b2230485 100644 --- a/js/jsd/idl/jsdIDebuggerService.idl +++ b/js/jsd/idl/jsdIDebuggerService.idl @@ -44,8 +44,12 @@ 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. */ @@ -348,6 +352,16 @@ interface jsdIDebuggerService : nsISupports * @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 */ diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index ca1c299b1b0..4c9d8a4b110 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -20,6 +20,7 @@ #include "nsICategoryManager.h" #include "nsIJSRuntimeService.h" #include "nsIThreadInternal.h" +#include "nsIScriptError.h" #include "nsTArray.h" #include "nsThreadUtils.h" #include "nsMemory.h" @@ -2463,11 +2464,30 @@ 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 xpc = do_GetService(nsIXPConnect::GetCID(), &rv); if (NS_FAILED(rv)) return rv; mActivationCallback = activationCallback; - + return xpc->SetDebugModeWhenPossible(true, true); } @@ -3039,6 +3059,13 @@ jsdService::ExitNestedEventLoop (uint32_t *_rval) return NS_OK; } +NS_IMETHODIMP +jsdService::AcknowledgeDeprecation() +{ + mDeprecationAcknowledged = true; + return NS_OK; +} + /* hook attribute get/set functions */ NS_IMETHODIMP diff --git a/js/jsd/jsd_xpc.h b/js/jsd/jsd_xpc.h index 013fd589047..e0639864608 100644 --- a/js/jsd/jsd_xpc.h +++ b/js/jsd/jsd_xpc.h @@ -262,7 +262,9 @@ class jsdService : public jsdIDebuggerService 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) { } @@ -292,6 +294,14 @@ class jsdService : public jsdIDebuggerService nsCOMPtr mTopLevelHook; nsCOMPtr mFunctionHook; nsCOMPtr 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___ */