1/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * For more information on this interface, please see
8 * https://console.spec.whatwg.org/#console-namespace
9 */
10
11[Exposed=(Window,Worker,WorkerDebugger,Worklet),
12 ClassString="Console",
13 ProtoObjectHack]
14namespace console {
15
16  // NOTE: if you touch this namespace, remember to update the ConsoleInstance
17  // interface as well!
18
19  // Logging
20  [UseCounter]
21  void assert(optional boolean condition = false, any... data);
22  [UseCounter]
23  void clear();
24  [UseCounter]
25  void count(optional DOMString label = "default");
26  [UseCounter]
27  void countReset(optional DOMString label = "default");
28  [UseCounter]
29  void debug(any... data);
30  [UseCounter]
31  void error(any... data);
32  [UseCounter]
33  void info(any... data);
34  [UseCounter]
35  void log(any... data);
36  [UseCounter]
37  void table(any... data); // FIXME: The spec is still unclear about this.
38  [UseCounter]
39  void trace(any... data);
40  [UseCounter]
41  void warn(any... data);
42  [UseCounter]
43  void dir(any... data); // FIXME: This doesn't follow the spec yet.
44  [UseCounter]
45  void dirxml(any... data);
46
47  // Grouping
48  [UseCounter]
49  void group(any... data);
50  [UseCounter]
51  void groupCollapsed(any... data);
52  [UseCounter]
53  void groupEnd();
54
55  // Timing
56  [UseCounter]
57  void time(optional DOMString label = "default");
58  [UseCounter]
59  void timeLog(optional DOMString label = "default", any... data);
60  [UseCounter]
61  void timeEnd(optional DOMString label = "default");
62
63  // Mozilla only or Webcompat methods
64
65  [UseCounter]
66  void _exception(any... data);
67  [UseCounter]
68  void timeStamp(optional any data);
69
70  [UseCounter]
71  void profile(any... data);
72  [UseCounter]
73  void profileEnd(any... data);
74
75  [ChromeOnly]
76  const boolean IS_NATIVE_CONSOLE = true;
77
78  [ChromeOnly, NewObject]
79  ConsoleInstance createInstance(optional ConsoleInstanceOptions options = {});
80};
81
82// This is used to propagate console events to the observers.
83[GenerateConversionToJS]
84dictionary ConsoleEvent {
85  (unsigned long long or DOMString) ID;
86  (unsigned long long or DOMString) innerID;
87  DOMString consoleID = "";
88  DOMString addonId = "";
89  DOMString level = "";
90  DOMString filename = "";
91  // Unique identifier within the process for the script source this event is
92  // associated with, or zero.
93  unsigned long sourceId = 0;
94  unsigned long lineNumber = 0;
95  unsigned long columnNumber = 0;
96  DOMString functionName = "";
97  double timeStamp = 0;
98  sequence<any> arguments;
99  sequence<DOMString?> styles;
100  boolean private = false;
101  // stacktrace is handled via a getter in some cases so we can construct it
102  // lazily.  Note that we're not making this whole thing an interface because
103  // consumers expect to see own properties on it, which would mean making the
104  // props unforgeable, which means lots of JSFunction allocations.  Maybe we
105  // should fix those consumers, of course....
106  // sequence<ConsoleStackEntry> stacktrace;
107  DOMString groupName = "";
108  any timer = null;
109  any counter = null;
110  DOMString prefix = "";
111  boolean chromeContext = false;
112};
113
114// Event for profile operations
115[GenerateConversionToJS]
116dictionary ConsoleProfileEvent {
117  DOMString action = "";
118  sequence<any> arguments;
119  boolean chromeContext = false;
120};
121
122// This dictionary is used to manage stack trace data.
123[GenerateConversionToJS]
124dictionary ConsoleStackEntry {
125  DOMString filename = "";
126  // Unique identifier within the process for the script source this entry is
127  // associated with, or zero.
128  unsigned long sourceId = 0;
129  unsigned long lineNumber = 0;
130  unsigned long columnNumber = 0;
131  DOMString functionName = "";
132  DOMString? asyncCause;
133};
134
135[GenerateConversionToJS]
136dictionary ConsoleTimerStart {
137  DOMString name = "";
138};
139
140[GenerateConversionToJS]
141dictionary ConsoleTimerLogOrEnd {
142  DOMString name = "";
143  double duration = 0;
144};
145
146[GenerateConversionToJS]
147dictionary ConsoleTimerError {
148  DOMString error = "";
149  DOMString name = "";
150};
151
152[GenerateConversionToJS]
153dictionary ConsoleCounter {
154  DOMString label = "";
155  unsigned long count = 0;
156};
157
158[GenerateConversionToJS]
159dictionary ConsoleCounterError {
160  DOMString label = "";
161  DOMString error = "";
162};
163
164[ChromeOnly,
165 Exposed=(Window,Worker,WorkerDebugger,Worklet)]
166// This is basically a copy of the console namespace.
167interface ConsoleInstance {
168  // Logging
169  void assert(optional boolean condition = false, any... data);
170  void clear();
171  void count(optional DOMString label = "default");
172  void countReset(optional DOMString label = "default");
173  void debug(any... data);
174  void error(any... data);
175  void info(any... data);
176  void log(any... data);
177  void table(any... data); // FIXME: The spec is still unclear about this.
178  void trace(any... data);
179  void warn(any... data);
180  void dir(any... data); // FIXME: This doesn't follow the spec yet.
181  void dirxml(any... data);
182
183  // Grouping
184  void group(any... data);
185  void groupCollapsed(any... data);
186  void groupEnd();
187
188  // Timing
189  void time(optional DOMString label = "default");
190  void timeLog(optional DOMString label = "default", any... data);
191  void timeEnd(optional DOMString label = "default");
192
193  // Mozilla only or Webcompat methods
194
195  void _exception(any... data);
196  void timeStamp(optional any data);
197
198  void profile(any... data);
199  void profileEnd(any... data);
200};
201
202callback ConsoleInstanceDumpCallback = void (DOMString message);
203
204enum ConsoleLogLevel {
205  "All", "Debug", "Log", "Info", "Clear", "Trace", "TimeLog", "TimeEnd", "Time",
206  "Group", "GroupEnd", "Profile", "ProfileEnd", "Dir", "Dirxml", "Warn", "Error",
207  "Off"
208};
209
210dictionary ConsoleInstanceOptions {
211  // An optional function to intercept all strings written to stdout.
212  ConsoleInstanceDumpCallback dump;
213
214  // An optional prefix string to be printed before the actual logged message.
215  DOMString prefix = "";
216
217  // An ID representing the source of the message. Normally the inner ID of a
218  // DOM window.
219  DOMString innerID = "";
220
221  // String identified for the console, this will be passed through the console
222  // notifications.
223  DOMString consoleID = "";
224
225  // Identifier that allows to filter which messages are logged based on their
226  // log level.
227  ConsoleLogLevel maxLogLevel;
228
229  // String pref name which contains the level to use for maxLogLevel. If the
230  // pref doesn't exist, gets removed or it is used in workers, the maxLogLevel
231  // will default to the value passed to this constructor (or "all" if it wasn't
232  // specified).
233  DOMString maxLogLevelPref = "";
234};
235
236enum ConsoleLevel { "log", "warning", "error" };
237
238// this interface is just for testing
239partial interface ConsoleInstance {
240  [ChromeOnly]
241  void reportForServiceWorkerScope(DOMString scope, DOMString message,
242                                   DOMString filename, unsigned long lineNumber,
243                                   unsigned long columnNumber,
244                                   ConsoleLevel level);
245};
246