gecko-dev/toolkit/modules/debug.js
Ekanan Ketunuti 61572eda35 Bug 828116 - Move modules in toolkit/content and toolkit/mozapps/shared to toolkit/modules. r=Mossop
--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
2013-05-14 14:37:18 -07:00

91 lines
3.0 KiB
JavaScript

/* vim:set ts=2 sw=2 sts=2 ci et: */
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
// This file contains functions that are useful for debugging purposes from
// within JavaScript code.
this.EXPORTED_SYMBOLS = ["NS_ASSERT"];
var gTraceOnAssert = true;
/**
* This function provides a simple assertion function for JavaScript.
* If the condition is true, this function will do nothing. If the
* condition is false, then the message will be printed to the console
* and an alert will appear showing a stack trace, so that the (alpha
* or nightly) user can file a bug containing it. For future enhancements,
* see bugs 330077 and 330078.
*
* To suppress the dialogs, you can run with the environment variable
* XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
*
* @param condition represents the condition that we're asserting to be
* true when we call this function--should be
* something that can be evaluated as a boolean.
* @param message a string to be displayed upon failure of the assertion
*/
this.NS_ASSERT = function NS_ASSERT(condition, message) {
if (condition)
return;
var releaseBuild = true;
var defB = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getDefaultBranch(null);
try {
switch (defB.getCharPref("app.update.channel")) {
case "nightly":
case "beta":
case "default":
releaseBuild = false;
}
} catch(ex) {}
var caller = arguments.callee.caller;
var assertionText = "ASSERT: " + message + "\n";
if (releaseBuild) {
// Just report the error to the console
Components.utils.reportError(assertionText);
return;
}
// Otherwise, dump to stdout and launch an assertion failure dialog
dump(assertionText);
var stackText = "";
if (gTraceOnAssert) {
stackText = "Stack Trace: \n";
var count = 0;
while (caller) {
stackText += count++ + ":" + caller.name + "(";
for (var i = 0; i < caller.arguments.length; ++i) {
var arg = caller.arguments[i];
stackText += arg;
if (i < caller.arguments.length - 1)
stackText += ",";
}
stackText += ")\n";
caller = caller.arguments.callee.caller;
}
}
var environment = Components.classes["@mozilla.org/process/environment;1"].
getService(Components.interfaces.nsIEnvironment);
if (environment.exists("XUL_ASSERT_PROMPT") &&
!parseInt(environment.get("XUL_ASSERT_PROMPT")))
return;
var source = null;
if (this.window)
source = this.window;
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
ps.alert(source, "Assertion Failed", assertionText + stackText);
}