toolkit/modules/debug.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* vim:set ts=2 sw=2 sts=2 ci et: */
michael@0 2 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 3
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 // This file contains functions that are useful for debugging purposes from
michael@0 9 // within JavaScript code.
michael@0 10
michael@0 11 this.EXPORTED_SYMBOLS = ["NS_ASSERT"];
michael@0 12
michael@0 13 var gTraceOnAssert = true;
michael@0 14
michael@0 15 /**
michael@0 16 * This function provides a simple assertion function for JavaScript.
michael@0 17 * If the condition is true, this function will do nothing. If the
michael@0 18 * condition is false, then the message will be printed to the console
michael@0 19 * and an alert will appear showing a stack trace, so that the (alpha
michael@0 20 * or nightly) user can file a bug containing it. For future enhancements,
michael@0 21 * see bugs 330077 and 330078.
michael@0 22 *
michael@0 23 * To suppress the dialogs, you can run with the environment variable
michael@0 24 * XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
michael@0 25 *
michael@0 26 * @param condition represents the condition that we're asserting to be
michael@0 27 * true when we call this function--should be
michael@0 28 * something that can be evaluated as a boolean.
michael@0 29 * @param message a string to be displayed upon failure of the assertion
michael@0 30 */
michael@0 31
michael@0 32 this.NS_ASSERT = function NS_ASSERT(condition, message) {
michael@0 33 if (condition)
michael@0 34 return;
michael@0 35
michael@0 36 var releaseBuild = true;
michael@0 37 var defB = Components.classes["@mozilla.org/preferences-service;1"]
michael@0 38 .getService(Components.interfaces.nsIPrefService)
michael@0 39 .getDefaultBranch(null);
michael@0 40 try {
michael@0 41 switch (defB.getCharPref("app.update.channel")) {
michael@0 42 case "nightly":
michael@0 43 case "aurora":
michael@0 44 case "alpha":
michael@0 45 case "beta":
michael@0 46 case "default":
michael@0 47 releaseBuild = false;
michael@0 48 }
michael@0 49 } catch(ex) {}
michael@0 50
michael@0 51 var caller = arguments.callee.caller;
michael@0 52 var assertionText = "ASSERT: " + message + "\n";
michael@0 53
michael@0 54 // Report the error to the console
michael@0 55 Components.utils.reportError(assertionText);
michael@0 56
michael@0 57 if (releaseBuild) {
michael@0 58 return;
michael@0 59 }
michael@0 60
michael@0 61 // dump the stack to stdout too in non-release builds
michael@0 62 var stackText = "";
michael@0 63 if (gTraceOnAssert) {
michael@0 64 stackText = "Stack Trace: \n";
michael@0 65 var count = 0;
michael@0 66 while (caller) {
michael@0 67 stackText += count++ + ":" + caller.name + "(";
michael@0 68 for (var i = 0; i < caller.arguments.length; ++i) {
michael@0 69 var arg = caller.arguments[i];
michael@0 70 stackText += arg;
michael@0 71 if (i < caller.arguments.length - 1)
michael@0 72 stackText += ",";
michael@0 73 }
michael@0 74 stackText += ")\n";
michael@0 75 caller = caller.arguments.callee.caller;
michael@0 76 }
michael@0 77 }
michael@0 78
michael@0 79 dump(assertionText + stackText);
michael@0 80 }

mercurial