Bug 800200: Print a deprecation warning to the console when JSD is first used. r=bholley

This commit is contained in:
Jim Blandy 2014-03-04 20:09:15 -08:00
parent 008bca7069
commit b789a57871
3 changed files with 54 additions and 3 deletions

View File

@ -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 */

View File

@ -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<nsIXPConnect> 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

View File

@ -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<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___ */