mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
61572eda35
--HG-- rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm rename : toolkit/content/debug.js => toolkit/modules/debug.js rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
this.EXPORTED_SYMBOLS = [ "Deprecated" ];
|
|
|
|
const Cu = Components.utils;
|
|
const Ci = Components.interfaces;
|
|
const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings";
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
// A flag that indicates whether deprecation warnings should be logged.
|
|
let logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
|
|
|
|
Services.prefs.addObserver(PREF_DEPRECATION_WARNINGS,
|
|
function (aSubject, aTopic, aData) {
|
|
logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
|
|
}, false);
|
|
|
|
/**
|
|
* Build a callstack log message.
|
|
*
|
|
* @param nsIStackFrame aStack
|
|
* A callstack to be converted into a string log message.
|
|
*/
|
|
function stringifyCallstack (aStack) {
|
|
// If aStack is invalid, use Components.stack (ignoring the last frame).
|
|
if (!aStack || !(aStack instanceof Ci.nsIStackFrame)) {
|
|
aStack = Components.stack.caller;
|
|
}
|
|
|
|
let frame = aStack.caller;
|
|
let msg = "";
|
|
// Get every frame in the callstack.
|
|
while (frame) {
|
|
msg += frame.filename + " " + frame.lineNumber +
|
|
" " + frame.name + "\n";
|
|
frame = frame.caller;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
const Deprecated = {
|
|
/**
|
|
* Log a deprecation warning.
|
|
*
|
|
* @param string aText
|
|
* Deprecation warning text.
|
|
* @param string aUrl
|
|
* A URL pointing to documentation describing deprecation
|
|
* and the way to address it.
|
|
* @param nsIStackFrame aStack
|
|
* An optional callstack. If it is not provided a
|
|
* snapshot of the current JavaScript callstack will be
|
|
* logged.
|
|
*/
|
|
warning: function (aText, aUrl, aStack) {
|
|
if (!logWarnings) {
|
|
return;
|
|
}
|
|
|
|
// If URL is not provided, report an error.
|
|
if (!aUrl) {
|
|
Cu.reportError("Error in Deprecated.warning: warnings must " +
|
|
"provide a URL documenting this deprecation.");
|
|
return;
|
|
}
|
|
|
|
let textMessage = "DEPRECATION WARNING: " + aText +
|
|
"\nYou may find more details about this deprecation at: " +
|
|
aUrl + "\n" +
|
|
// Append a callstack part to the deprecation message.
|
|
stringifyCallstack(aStack);
|
|
|
|
// Report deprecation warning.
|
|
Cu.reportError(textMessage);
|
|
}
|
|
}; |