1 # vim
:set ts
=2 sw
=2 sts
=2 ci et
:
2 # -*- Mode
: Java
; tab
-width
: 2; indent
-tabs
-mode
: nil
; c
-basic
-offset
: 2 -*-
4 # ***** BEGIN LICENSE BLOCK
*****
5 # Version
: MPL
1.1/GPL 2.0/LGPL
2.1
7 # The contents
of this file are subject to the Mozilla Public License Version
8 # 1.1 (the
"License"); you may not
use this file except
in compliance
with
9 # the License
. You may obtain a copy
of the License at
10 # http
://www.mozilla.org/MPL/
12 # Software distributed under the License is distributed on an
"AS IS" basis
,
13 # WITHOUT WARRANTY OF ANY KIND
, either express or implied
. See the License
14 # for the specific language governing rights and limitations under the
17 # The Original Code is the Places Bookmark Properties
.
19 # The Initial Developer
of the Original Code is
21 # Portions created by the Initial Developer are
Copyright (C
) 2006
22 # the Initial Developer
. All Rights Reserved
.
25 # Joe Hughes
<jhughes
@google
.com
>
26 # Ben Goodger
<beng
@google
.com
>
28 # Alternatively
, the contents
of this file may be used under the terms
of
29 # either the GNU General Public License Version
2 or
later (the
"GPL"), or
30 # the GNU Lesser General Public License Version
2.1 or
later (the
"LGPL"),
31 # in which
case the provisions
of the GPL or the LGPL are applicable instead
32 # of those above
. If you wish to allow
use of your version
of this file only
33 # under the terms
of either the GPL or the LGPL
, and not to allow others to
34 # use your version
of this file under the terms
of the MPL
, indicate your
35 # decision by deleting the provisions above and replace them
with the notice
36 # and other provisions required by the GPL or the LGPL
. If you
do not
delete
37 # the provisions above
, a recipient may
use your version
of this file under
38 # the terms
of any one
of the MPL
, the GPL or the LGPL
.
40 # ***** END LICENSE BLOCK
*****
42 # This file contains functions that are useful
for debugging purposes
from
43 # within JavaScript code
.
45 var EXPORTED_SYMBOLS
= ["NS_ASSERT"];
47 var gTraceOnAssert
= true;
50 * This function provides a simple assertion function for JavaScript.
51 * If the condition is true, this function will do nothing. If the
52 * condition is false, then the message will be printed to the console
53 * and an alert will appear showing a stack trace, so that the (alpha
54 * or nightly) user can file a bug containing it. For future enhancements,
55 * see bugs 330077 and 330078.
57 * To suppress the dialogs, you can run with the environment variable
58 * XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
60 * @param condition represents the condition that we're asserting to be
61 * true when we call this function--should be
62 * something that can be evaluated as a boolean.
63 * @param message a string to be displayed upon failure of the assertion
66 function NS_ASSERT(condition
, message
) {
70 var releaseBuild
= true;
71 var defB
= Components
.classes
["@mozilla.org/preferences-service;1"]
72 .getService(Components
.interfaces
.nsIPrefService
)
73 .getDefaultBranch(null);
75 switch (defB
.getCharPref("app.update.channel")) {
83 var caller
= arguments
.callee
.caller
;
84 var assertionText
= "ASSERT: " + message
+ "\n";
87 // Just report the error to the console
88 Components
.utils
.reportError(assertionText
);
92 // Otherwise, dump to stdout and launch an assertion failure dialog
97 stackText
= "Stack Trace: \n";
100 stackText
+= count
++ + ":" + caller
.name
+ "(";
101 for (var i
= 0; i
< caller
.arguments
.length
; ++i
) {
102 var arg
= caller
.arguments
[i
];
104 if (i
< caller
.arguments
.length
- 1)
108 caller
= caller
.arguments
.callee
.caller
;
112 var environment
= Components
.classes
["@mozilla.org/process/environment;1"].
113 getService(Components
.interfaces
.nsIEnvironment
);
114 if (environment
.exists("XUL_ASSERT_PROMPT") &&
115 !parseInt(environment
.get("XUL_ASSERT_PROMPT")))
120 source
= this.window
;
121 var ps
= Components
.classes
["@mozilla.org/embedcomp/prompt-service;1"].
122 getService(Components
.interfaces
.nsIPromptService
);
123 ps
.alert(source
, "Assertion Failed", assertionText
+ stackText
);