1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * nsIConsoleMessage subclass for representing JavaScript errors and warnings.
11 #include
"nsISupports.idl"
12 #include
"nsIArray.idl"
13 #include
"nsIConsoleMessage.idl"
17 #include
"nsString.h" // for nsDependentCString
20 [scriptable
, uuid(e8933fc9
-c302
-4e12
-a55b
-4f88611d9c6c
)]
21 interface nsIScriptErrorNote
: nsISupports
23 readonly attribute AString errorMessage
;
24 readonly attribute ACString sourceName
;
27 * Unique identifier within the process for the script source this note is
28 * associated with, or zero.
30 readonly attribute uint32_t sourceId
;
32 readonly attribute uint32_t lineNumber
;
33 readonly attribute uint32_t columnNumber
;
35 AUTF8String toString
();
38 [scriptable
, uuid(63eb4d3e
-7d99
-4150-b4f3
-11314f9d82a9
)]
39 interface nsIScriptError
: nsIConsoleMessage
41 /** pseudo-flag for default case */
42 const unsigned long errorFlag
= 0x0;
44 /** message is warning */
45 const unsigned long warningFlag
= 0x1;
47 /** just a log message */
48 const unsigned long infoFlag
= 0x8;
51 * The error message without any context/line number information.
53 * @note nsIConsoleMessage.message will return the error formatted
54 * with file/line information.
56 readonly attribute AString errorMessage
;
58 readonly attribute ACString sourceName
;
61 * Unique identifier within the process for the script source this error is
62 * associated with, or zero.
64 readonly attribute uint32_t sourceId
;
66 readonly attribute uint32_t lineNumber
;
67 readonly attribute uint32_t columnNumber
;
68 readonly attribute uint32_t flags
;
71 * Categories I know about -
73 * content javascript (both of these from nsDocShell, currently)
74 * system javascript (errors in JS components and other system JS)
76 readonly attribute
string category
;
78 /* Get the window id this was initialized with. Zero will be
79 returned if init() was used instead of initWithWindowID(). */
80 readonly attribute
unsigned long long outerWindowID
;
82 /* Get the inner window id this was initialized with. Zero will be
83 returned if init() was used instead of initWithWindowID(). */
84 readonly attribute
unsigned long long innerWindowID
;
86 readonly attribute
boolean isFromPrivateWindow
;
88 readonly attribute
boolean isFromChromeContext
;
90 // Error created from a Promise rejection.
91 readonly attribute
boolean isPromiseRejection
;
93 [noscript
] void initIsPromiseRejection
(in boolean isPromiseRejection
);
95 // The "exception" value generated when an uncaught exception is thrown
96 // by JavaScript. This can be any value, e.g.
97 // - an Error object (`throw new Error("foobar"`)
98 // - some primitive (`throw "hello"`)
99 attribute jsval exception
;
101 // The hasException attribute is used to differentiate between no thrown
102 // exception and `throw undefined`.
103 readonly attribute
boolean hasException
;
105 attribute jsval stack
;
108 * If |stack| is an object, then stackGlobal must be a global object that's
109 * same-compartment with |stack|. This can be used to enter the correct
110 * realm when working with the stack object. We can't use the object itself
111 * because it might be a cross-compartment wrapper and CCWs are not
112 * associated with a single realm/global.
114 [noscript
] readonly attribute jsval stackGlobal
;
117 * The name of a template string associated with the error message. See
118 * js/public/friend/ErrorNumbers.msg.
120 attribute AString errorMessageName
;
122 readonly attribute nsIArray notes
;
125 * If the ScriptError is a CSS parser error, this value will contain the
126 * CSS selectors of the CSS ruleset where the error occured.
128 attribute AString cssSelectors
;
130 void init
(in AString
message,
131 in ACString sourceName
,
132 in uint32_t lineNumber
,
133 in uint32_t columnNumber
,
135 in ACString category
,
136 [optional] in boolean fromPrivateWindow
,
137 [optional] in boolean fromChromeContext
);
139 /* This should be called instead of nsIScriptError.init to
140 * initialize with a window id. The window id should be for the
141 * inner window associated with this error.
143 * This function will check whether sourceName is a uri and sanitize it if
144 * needed. If you know the source name is sanitized already, use
145 * initWithSanitizedSource.
146 * A "sanitized" source name means that passwords are not shown. It will
147 * use the sensitiveInfoHiddenSpec function of nsIURI interface, that is
148 * replacing paswords with ***
149 * (e.g. https://USERNAME:****@example.com/some/path).
151 void initWithWindowID
(in AString
message,
152 in ACString sourceName
,
153 in uint32_t lineNumber
,
154 in uint32_t columnNumber
,
156 in ACString category
,
157 in unsigned long long innerWindowID
,
158 [optional] in boolean fromChromeContext
);
160 /* This is the same function as initWithWindowID, but it expects an already
161 * sanitized sourceName.
162 * Please use it only if sourceName string is already sanitized.
164 void initWithSanitizedSource
(in AString
message,
165 in ACString sourceName
,
166 in uint32_t lineNumber
,
167 in uint32_t columnNumber
,
169 in ACString category
,
170 in unsigned long long innerWindowID
,
171 [optional] in boolean fromChromeContext
);
173 /* This is the same function as initWithWindowID with an uri as a source parameter.
175 void initWithSourceURI
(in AString
message,
177 in uint32_t lineNumber
,
178 in uint32_t columnNumber
,
180 in ACString category
,
181 in unsigned long long innerWindowID
,
182 [optional] in boolean fromChromeContext
);
184 /* Initialize the script source ID in a new error. */
185 void initSourceId
(in uint32_t sourceId
);
188 nsresult InitWithWindowID
(const nsAString
& message,
189 const nsACString
& sourceName
,
191 uint32_t columnNumber
,
193 const nsACString
& category
,
194 uint64_t aInnerWindowID
)
196 return InitWithWindowID
(message, sourceName
, lineNumber
,
197 columnNumber
, flags
, category
, aInnerWindowID
,
200 // These overloads allow passing a literal string for category.
202 nsresult InitWithWindowID
(const nsAString
& message,
203 const nsACString
& sourceName
,
205 uint32_t columnNumber
,
208 uint64_t aInnerWindowID
,
209 bool aFromChromeContext
= false
)
211 nsDependentCString category
(c
, N
- 1);
212 return InitWithWindowID
(message, sourceName
, lineNumber
,
213 columnNumber
, flags
, category
, aInnerWindowID
,
217 nsresult InitWithSanitizedSource
(const nsAString
& message,
218 const nsACString
& sourceName
,
220 uint32_t columnNumber
,
222 const nsACString
& category
,
223 uint64_t aInnerWindowID
)
225 return InitWithSanitizedSource
(message, sourceName
,
226 lineNumber
, columnNumber
, flags
,
227 category
, aInnerWindowID
,
232 nsresult InitWithSanitizedSource
(const nsAString
& message,
233 const nsACString
& sourceName
,
235 uint32_t columnNumber
,
238 uint64_t aInnerWindowID
,
239 bool aFromChromeContext
= false
)
241 nsDependentCString category
(c
, N
- 1);
242 return InitWithSanitizedSource
(message, sourceName
,
243 lineNumber
, columnNumber
, flags
,
244 category
, aInnerWindowID
,
248 nsresult InitWithSourceURI
(const nsAString
& message,
251 uint32_t columnNumber
,
253 const nsACString
& category
,
254 uint64_t aInnerWindowID
)
256 return InitWithSourceURI
(message, sourceURI
,
257 lineNumber
, columnNumber
, flags
,
258 category
, aInnerWindowID
, false
);
262 nsresult InitWithSourceURI
(const nsAString
& message,
265 uint32_t columnNumber
,
268 uint64_t aInnerWindowID
,
269 bool aFromChromeContext
= false
)
271 nsDependentCString category
(c
, N
- 1);
272 return InitWithSourceURI
(message, sourceURI
,
273 lineNumber
, columnNumber
, flags
,
274 category
, aInnerWindowID
, aFromChromeContext
);
281 #define NS_SCRIPTERROR_CID \
282 { 0x1950539a, 0x90f0, 0x4d22, { 0xb5, 0xaf, 0x71, 0x32, 0x9c, 0x68, 0xfa, 0x35 }}
284 #define NS_SCRIPTERROR_CONTRACTID
"@mozilla.org/scripterror;1"