@@ -52,88 +52,83 @@ where
5252 f ( )
5353}
5454
55+ fn console_messages ( global : & GlobalScope , messages : & [ DOMString ] , level : LogLevel ) {
56+ console_message ( global, DOMString :: from ( messages. join ( " " ) ) , level)
57+ }
58+
59+ fn console_message ( global : & GlobalScope , message : DOMString , level : LogLevel ) {
60+ with_stderr_lock ( move || {
61+ let prefix = global. current_group_label ( ) . unwrap_or_default ( ) ;
62+ let message = DOMString :: from ( format ! ( "{}{}" , prefix, message) ) ;
63+ println ! ( "{}" , message) ;
64+ Console :: send_to_devtools ( global, level, message) ;
65+ } )
66+ }
67+
5568#[ allow( non_snake_case) ]
5669impl Console {
5770 // https://developer.mozilla.org/en-US/docs/Web/API/Console/log
5871 pub fn Log ( global : & GlobalScope , messages : Vec < DOMString > ) {
59- with_stderr_lock ( move || {
60- for message in messages {
61- println ! ( "{}" , message) ;
62- Self :: send_to_devtools ( global, LogLevel :: Log , message) ;
63- }
64- } )
72+ console_messages ( global, & messages, LogLevel :: Log )
6573 }
6674
6775 // https://developer.mozilla.org/en-US/docs/Web/API/Console
6876 pub fn Debug ( global : & GlobalScope , messages : Vec < DOMString > ) {
69- with_stderr_lock ( move || {
70- for message in messages {
71- println ! ( "{}" , message) ;
72- Self :: send_to_devtools ( global, LogLevel :: Debug , message) ;
73- }
74- } )
77+ console_messages ( global, & messages, LogLevel :: Debug )
7578 }
7679
7780 // https://developer.mozilla.org/en-US/docs/Web/API/Console/info
7881 pub fn Info ( global : & GlobalScope , messages : Vec < DOMString > ) {
79- with_stderr_lock ( move || {
80- for message in messages {
81- println ! ( "{}" , message) ;
82- Self :: send_to_devtools ( global, LogLevel :: Info , message) ;
83- }
84- } )
82+ console_messages ( global, & messages, LogLevel :: Info )
8583 }
8684
8785 // https://developer.mozilla.org/en-US/docs/Web/API/Console/warn
8886 pub fn Warn ( global : & GlobalScope , messages : Vec < DOMString > ) {
89- with_stderr_lock ( move || {
90- for message in messages {
91- println ! ( "{}" , message) ;
92- Self :: send_to_devtools ( global, LogLevel :: Warn , message) ;
93- }
94- } )
87+ console_messages ( global, & messages, LogLevel :: Warn )
9588 }
9689
9790 // https://developer.mozilla.org/en-US/docs/Web/API/Console/error
9891 pub fn Error ( global : & GlobalScope , messages : Vec < DOMString > ) {
99- with_stderr_lock ( move || {
100- for message in messages {
101- println ! ( "{}" , message) ;
102- Self :: send_to_devtools ( global, LogLevel :: Error , message) ;
103- }
104- } )
92+ console_messages ( global, & messages, LogLevel :: Error )
10593 }
10694
10795 // https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
10896 pub fn Assert ( global : & GlobalScope , condition : bool , message : Option < DOMString > ) {
109- with_stderr_lock ( move || {
110- if !condition {
111- let message = message. unwrap_or_else ( || DOMString :: from ( "no message" ) ) ;
112- println ! ( "Assertion failed: {}" , message) ;
113- Self :: send_to_devtools ( global, LogLevel :: Error , message) ;
114- }
115- } )
97+ if !condition {
98+ let message = message. unwrap_or_else ( || DOMString :: from ( "no message" ) ) ;
99+ let message = DOMString :: from ( format ! ( "Assertion failed: {}" , message) ) ;
100+ console_message ( global, message, LogLevel :: Error )
101+ } ;
116102 }
117103
118104 // https://developer.mozilla.org/en-US/docs/Web/API/Console/time
119105 pub fn Time ( global : & GlobalScope , label : DOMString ) {
120- with_stderr_lock ( move || {
121- if let Ok ( ( ) ) = global. time ( label. clone ( ) ) {
122- let message = DOMString :: from ( format ! ( "{}: timer started" , label) ) ;
123- println ! ( "{}" , message) ;
124- Self :: send_to_devtools ( global, LogLevel :: Log , message) ;
125- }
126- } )
106+ if let Ok ( ( ) ) = global. time ( label. clone ( ) ) {
107+ let message = DOMString :: from ( format ! ( "{}: timer started" , label) ) ;
108+ console_message ( global, message, LogLevel :: Log ) ;
109+ }
127110 }
128111
129112 // https://developer.mozilla.org/en-US/docs/Web/API/Console/timeEnd
130113 pub fn TimeEnd ( global : & GlobalScope , label : DOMString ) {
131- with_stderr_lock ( move || {
132- if let Ok ( delta) = global. time_end ( & label) {
133- let message = DOMString :: from ( format ! ( "{}: {}ms" , label, delta) ) ;
134- println ! ( "{}" , message) ;
135- Self :: send_to_devtools ( global, LogLevel :: Log , message) ;
136- } ;
137- } )
114+ if let Ok ( delta) = global. time_end ( & label) {
115+ let message = DOMString :: from ( format ! ( "{}: {}ms" , label, delta) ) ;
116+ console_message ( global, message, LogLevel :: Log ) ;
117+ }
118+ }
119+
120+ // https://console.spec.whatwg.org/#group
121+ pub fn Group ( global : & GlobalScope , messages : Vec < DOMString > ) {
122+ global. push_console_group ( DOMString :: from ( messages. join ( " " ) ) ) ;
123+ }
124+
125+ // https://console.spec.whatwg.org/#groupcollapsed
126+ pub fn GroupCollapsed ( global : & GlobalScope , messages : Vec < DOMString > ) {
127+ global. push_console_group ( DOMString :: from ( messages. join ( " " ) ) ) ;
128+ }
129+
130+ // https://console.spec.whatwg.org/#groupend
131+ pub fn GroupEnd ( global : & GlobalScope ) {
132+ global. pop_console_group ( ) ;
138133 }
139134}
0 commit comments