1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var EXPORTED_SYMBOLS = ["Deprecated"];
9 const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings";
11 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
13 // A flag that indicates whether deprecation warnings should be logged.
14 var logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
16 Services.prefs.addObserver(PREF_DEPRECATION_WARNINGS, function(
21 logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
25 * Build a callstack log message.
27 * @param nsIStackFrame aStack
28 * A callstack to be converted into a string log message.
30 function stringifyCallstack(aStack) {
31 // If aStack is invalid, use Components.stack (ignoring the last frame).
32 if (!aStack || !(aStack instanceof Ci.nsIStackFrame)) {
33 aStack = Components.stack.caller;
36 let frame = aStack.caller;
38 // Get every frame in the callstack.
40 msg += frame.filename + " " + frame.lineNumber + " " + frame.name + "\n";
48 * Log a deprecation warning.
51 * Deprecation warning text.
53 * A URL pointing to documentation describing deprecation
54 * and the way to address it.
55 * @param nsIStackFrame aStack
56 * An optional callstack. If it is not provided a
57 * snapshot of the current JavaScript callstack will be
60 warning(aText, aUrl, aStack) {
65 // If URL is not provided, report an error.
68 "Error in Deprecated.warning: warnings must " +
69 "provide a URL documenting this deprecation."
75 "DEPRECATION WARNING: " +
77 "\nYou may find more details about this deprecation at: " +
80 // Append a callstack part to the deprecation message.
81 stringifyCallstack(aStack);
83 // Report deprecation warning.
84 Cu.reportError(textMessage);