diff --git a/CHANGELOG.md b/CHANGELOG.md index 38312442e87..3ebc4799933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,10 @@ This change will only affect code using sound null-safety. See issue [#41653][] for more details. +* Methods in `Console` have been updated to better reflect the modern Console + specification. Particularly of interest are `dir` and `table` which take in + extra optional arguments. + [#41653]: https://github.com/dart-lang/sdk/issues/41653 ### Tools diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 04dcc3d96ea..a3bcc029cc3 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -39846,72 +39846,96 @@ class Console { MemoryInfo? get memory => _isConsoleDefined ? JS('MemoryInfo', 'window.console.memory') : null; - void assertCondition(bool condition, Object arg) => _isConsoleDefined - ? JS('void', 'window.console.assertCondition(#, #)', condition, arg) + // Even though many of the following JS methods can take in multiple + // arguments, we historically and currently limit the number of variable + // arguments to 1. Depending on the need, these methods may be updated to + // allow for more. + + // We rename assert to assertCondition here. + void assertCondition([bool? condition, Object? arg]) => _isConsoleDefined + ? JS('void', 'window.console.assert(#, #)', condition, arg) : null; - void clear(Object arg) => + // clear no longer takes in an argument, but we keep this as optional to + // maintain backwards compatibility. + void clear([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.clear(#)', arg) : null; - void count(Object arg) => + // count takes in a String instead, but we keep this as an Object for + // backwards compatibility. + void count([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.count(#)', arg) : null; - void debug(Object arg) => + void countReset([String? arg]) => _isConsoleDefined + ? JS('void', 'window.console.countReset(#)', arg) + : null; + + void debug(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.debug(#)', arg) : null; - void dir(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.dir(#)', arg) : null; + void dir([Object? item, Object? options]) => _isConsoleDefined + ? JS('void', 'window.console.dir(#, #)', item, options) + : null; - void dirxml(Object arg) => + void dirxml(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.dirxml(#)', arg) : null; - void error(Object arg) => + void error(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.error(#)', arg) : null; - void group(Object arg) => + void group(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.group(#)', arg) : null; - void groupCollapsed(Object arg) => _isConsoleDefined + void groupCollapsed(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.groupCollapsed(#)', arg) : null; void groupEnd() => _isConsoleDefined ? JS('void', 'window.console.groupEnd()') : null; - void info(Object arg) => + void info(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.info(#)', arg) : null; - void log(Object arg) => + void log(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.log(#)', arg) : null; - void markTimeline(Object arg) => _isConsoleDefined - ? JS('void', 'window.console.markTimeline(#)', arg) + void table([Object? tabularData, List? properties]) => + _isConsoleDefined + ? JS('void', 'window.console.table(#, #)', tabularData, properties) + : null; + + void time([String? label]) => + _isConsoleDefined ? JS('void', 'window.console.time(#)', label) : null; + + void timeEnd([String? label]) => + _isConsoleDefined ? JS('void', 'window.console.timeEnd(#)', label) : null; + + void timeLog([String? label, Object? arg]) => _isConsoleDefined + ? JS('void', 'window.console.timeLog(#, #)', label, arg) : null; - void profile(String title) => + void trace(Object? arg) => + _isConsoleDefined ? JS('void', 'window.console.trace(#)', arg) : null; + + void warn(Object? arg) => + _isConsoleDefined ? JS('void', 'window.console.warn(#)', arg) : null; + + // The following are non-standard methods. + void profile([String? title]) => _isConsoleDefined ? JS('void', 'window.console.profile(#)', title) : null; - void profileEnd(String title) => _isConsoleDefined + void profileEnd([String? title]) => _isConsoleDefined ? JS('void', 'window.console.profileEnd(#)', title) : null; - void table(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.table(#)', arg) : null; - - void time(String title) => - _isConsoleDefined ? JS('void', 'window.console.time(#)', title) : null; - - void timeEnd(String title) => - _isConsoleDefined ? JS('void', 'window.console.timeEnd(#)', title) : null; - - void timeStamp(Object arg) => + void timeStamp([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.timeStamp(#)', arg) : null; - void trace(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.trace(#)', arg) : null; - - void warn(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.warn(#)', arg) : null; + // The following is deprecated and should be removed once we drop support for + // older Safari browsers. + void markTimeline(Object? arg) => _isConsoleDefined + ? JS('void', 'window.console.markTimeline(#)', arg) + : null; } // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py index 2cf97d7877c..5948de39711 100644 --- a/tools/dom/scripts/systemhtml.py +++ b/tools/dom/scripts/systemhtml.py @@ -39,6 +39,7 @@ _js_custom_members = monitored.Set( 'ConsoleBase.assertCondition', 'ConsoleBase.clear', 'ConsoleBase.count', + 'ConsoleBase.countReset', 'ConsoleBase.debug', 'ConsoleBase.dir', 'ConsoleBase.dirxml', diff --git a/tools/dom/src/dart2js_Console.dart b/tools/dom/src/dart2js_Console.dart index b3297d29b46..a7a40b6dffd 100644 --- a/tools/dom/src/dart2js_Console.dart +++ b/tools/dom/src/dart2js_Console.dart @@ -13,70 +13,94 @@ class Console { MemoryInfo? get memory => _isConsoleDefined ? JS('MemoryInfo', 'window.console.memory') : null; - void assertCondition(bool condition, Object arg) => _isConsoleDefined - ? JS('void', 'window.console.assertCondition(#, #)', condition, arg) + // Even though many of the following JS methods can take in multiple + // arguments, we historically and currently limit the number of variable + // arguments to 1. Depending on the need, these methods may be updated to + // allow for more. + + // We rename assert to assertCondition here. + void assertCondition([bool? condition, Object? arg]) => _isConsoleDefined + ? JS('void', 'window.console.assert(#, #)', condition, arg) : null; - void clear(Object arg) => + // clear no longer takes in an argument, but we keep this as optional to + // maintain backwards compatibility. + void clear([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.clear(#)', arg) : null; - void count(Object arg) => + // count takes in a String instead, but we keep this as an Object for + // backwards compatibility. + void count([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.count(#)', arg) : null; - void debug(Object arg) => + void countReset([String? arg]) => _isConsoleDefined + ? JS('void', 'window.console.countReset(#)', arg) + : null; + + void debug(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.debug(#)', arg) : null; - void dir(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.dir(#)', arg) : null; + void dir([Object? item, Object? options]) => _isConsoleDefined + ? JS('void', 'window.console.dir(#, #)', item, options) + : null; - void dirxml(Object arg) => + void dirxml(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.dirxml(#)', arg) : null; - void error(Object arg) => + void error(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.error(#)', arg) : null; - void group(Object arg) => + void group(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.group(#)', arg) : null; - void groupCollapsed(Object arg) => _isConsoleDefined + void groupCollapsed(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.groupCollapsed(#)', arg) : null; void groupEnd() => _isConsoleDefined ? JS('void', 'window.console.groupEnd()') : null; - void info(Object arg) => + void info(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.info(#)', arg) : null; - void log(Object arg) => + void log(Object? arg) => _isConsoleDefined ? JS('void', 'window.console.log(#)', arg) : null; - void markTimeline(Object arg) => _isConsoleDefined - ? JS('void', 'window.console.markTimeline(#)', arg) + void table([Object? tabularData, List? properties]) => + _isConsoleDefined + ? JS('void', 'window.console.table(#, #)', tabularData, properties) + : null; + + void time([String? label]) => + _isConsoleDefined ? JS('void', 'window.console.time(#)', label) : null; + + void timeEnd([String? label]) => + _isConsoleDefined ? JS('void', 'window.console.timeEnd(#)', label) : null; + + void timeLog([String? label, Object? arg]) => _isConsoleDefined + ? JS('void', 'window.console.timeLog(#, #)', label, arg) : null; - void profile(String title) => + void trace(Object? arg) => + _isConsoleDefined ? JS('void', 'window.console.trace(#)', arg) : null; + + void warn(Object? arg) => + _isConsoleDefined ? JS('void', 'window.console.warn(#)', arg) : null; + + // The following are non-standard methods. + void profile([String? title]) => _isConsoleDefined ? JS('void', 'window.console.profile(#)', title) : null; - void profileEnd(String title) => _isConsoleDefined + void profileEnd([String? title]) => _isConsoleDefined ? JS('void', 'window.console.profileEnd(#)', title) : null; - void table(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.table(#)', arg) : null; - - void time(String title) => - _isConsoleDefined ? JS('void', 'window.console.time(#)', title) : null; - - void timeEnd(String title) => - _isConsoleDefined ? JS('void', 'window.console.timeEnd(#)', title) : null; - - void timeStamp(Object arg) => + void timeStamp([Object? arg]) => _isConsoleDefined ? JS('void', 'window.console.timeStamp(#)', arg) : null; - void trace(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.trace(#)', arg) : null; - - void warn(Object arg) => - _isConsoleDefined ? JS('void', 'window.console.warn(#)', arg) : null; + // The following is deprecated and should be removed once we drop support for + // older Safari browsers. + void markTimeline(Object? arg) => _isConsoleDefined + ? JS('void', 'window.console.markTimeline(#)', arg) + : null; } diff --git a/tools/dom/templates/html/dart2js/impl_Console.darttemplate b/tools/dom/templates/html/dart2js/impl_Console.darttemplate deleted file mode 100644 index 890ad2d6b59..00000000000 --- a/tools/dom/templates/html/dart2js/impl_Console.darttemplate +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -part of $LIBRARYNAME; - -$(ANNOTATIONS)$(CLASS_MODIFIERS)class Console { - - const Console._safe(); - - static const Console _safeConsole = const Console._safe(); - - bool get _isConsoleDefined => JS('bool', 'typeof console != "undefined"'); - - MemoryInfo get memory => _isConsoleDefined ? - JS('MemoryInfo', 'console.memory') : null; - - void assertCondition(bool condition, Object arg) => _isConsoleDefined ? - JS('void', 'console.assertCondition(#, #)', condition, arg) : null; - - void clear(Object arg) => _isConsoleDefined ? - JS('void', 'console.clear(#)', arg) : null; - - void count(Object arg) => _isConsoleDefined ? - JS('void', 'console.count(#)', arg) : null; - - void debug(Object arg) => _isConsoleDefined ? - JS('void', 'console.debug(#)', arg) : null; - - void dir(Object arg) => _isConsoleDefined ? - JS('void', 'console.dir(#)', arg) : null; - - void dirxml(Object arg) => _isConsoleDefined ? - JS('void', 'console.dirxml(#)', arg) : null; - - void error(Object arg) => _isConsoleDefined ? - JS('void', 'console.error(#)', arg) : null; - - void group(Object arg) => _isConsoleDefined ? - JS('void', 'console.group(#)', arg) : null; - - void groupCollapsed(Object arg) => _isConsoleDefined ? - JS('void', 'console.groupCollapsed(#)', arg) : null; - - void groupEnd() => _isConsoleDefined ? - JS('void', 'console.groupEnd()') : null; - - void info(Object arg) => _isConsoleDefined ? - JS('void', 'console.info(#)', arg) : null; - - void log(Object arg) => _isConsoleDefined ? - JS('void', 'console.log(#)', arg) : null; - - void markTimeline(Object arg) => _isConsoleDefined ? - JS('void', 'console.markTimeline(#)', arg) : null; - - void profile(String title) => _isConsoleDefined ? - JS('void', 'console.profile(#)', title) : null; - - void profileEnd(String title) => _isConsoleDefined ? - JS('void', 'console.profileEnd(#)', title) : null; - - void table(Object arg) => _isConsoleDefined ? - JS('void', 'console.table(#)', arg) : null; - - void time(String title) => _isConsoleDefined ? - JS('void', 'console.time(#)', title) : null; - - void timeEnd(String title) => _isConsoleDefined ? - JS('void', 'console.timeEnd(#)', title) : null; - - void timeStamp(Object arg) => _isConsoleDefined ? - JS('void', 'console.timeStamp(#)', arg) : null; - - void trace(Object arg) => _isConsoleDefined ? - JS('void', 'console.trace(#)', arg) : null; - - void warn(Object arg) => _isConsoleDefined ? - JS('void', 'console.warn(#)', arg) : null; -$!MEMBERS -}