console: add console.count() and console.clear()#12678
console: add console.count() and console.clear()#12678jasnell wants to merge 2 commits intonodejs:masterfrom
Conversation
|
planning to tackle an implementation of the |
addaleax
left a comment
There was a problem hiding this comment.
LGTM with a couple of suggestions
test/parallel/test-console-clear.js
Outdated
There was a problem hiding this comment.
Fwiw I think all the global.s here are redundant
test/parallel/test-console-clear.js
Outdated
There was a problem hiding this comment.
Just check = '\u001b[1;1H\u001b[0J' should be fine :)
test/parallel/test-console-clear.js
Outdated
There was a problem hiding this comment.
I think this doesn’t need to be wrapped in .on('exit')
|
@addaleax ... updated to fix those nits :-) |
doc/api/console.md
Outdated
There was a problem hiding this comment.
FWIW: in repl.md there were ```js in such cases and I've tried to save this approach to preserve highlighting with something like this.
lib/console.js
Outdated
There was a problem hiding this comment.
Why not use Map here? Won't that remove the restriction about symbols?
Or at least Object.create(null) to go straight into dictionary mode.
There was a problem hiding this comment.
I've updated to Object.create(null)... the symbol restriction is actually there to approximate the behavior implemented by browsers. We can easily support Symbol if we wanted to.
|
Failures in CI are unrelated. |
doc/api/console.md
Outdated
lib/console.js
Outdated
There was a problem hiding this comment.
Oh, yeah, just forgot about it. I need to add that to the documentation :-)
|
We shouldn't implement |
doc/api/console.md
Outdated
There was a problem hiding this comment.
Is this an intentional way to designate optional parameters?
There was a problem hiding this comment.
This is just the only such case in the doc and it differs from the very console.log([data][, ...args]) fragment, but if it is intentional, it is OK)
There was a problem hiding this comment.
oh, I see what you're referring to. No, that was just a misplaced ] on my part :-)
There was a problem hiding this comment.
But it still misses a backtick)
Not sure what you mean here. It clears just fine in the terminal. |
|
Doesn't that just jump down to make it look like there is no output in the screen? I investigated implementing this a while ago (might have been almost a year ago) and it didn't look like there was a way to actually clear it so there was no current terminal history loaded (e.g. no scroll up). |
|
Sure, it leaves the scrollback buffer in place but that seems like a reasonable compromise. |
lib/console.js
Outdated
There was a problem hiding this comment.
According to the IDL, label is a DOMString with default being 'default'. This means that the implementation should be akin to:
function count(label = 'default') {
label = `${label}`;
// ...
this.log(`${label}: ${counts[label]}`);
}This should also allow the use of Map for this[kCounts].
There was a problem hiding this comment.
Yeah, I saw that but looking at the browser implementations, neither Chrome or Firefox treat console.count() and console.count('default') as being equivalent. They implement separate counters.
There was a problem hiding this comment.
Fair enough, but I would still be happier if a) this deviation is documented in a comment, and b) this[kCounts] is a Map.
There was a problem hiding this comment.
We've filed bugs and are fixing Chrome and Firefox; patches should be landing within the week.
There was a problem hiding this comment.
Given that, I've no problem with using default as the label.
@TimothyGu ... I'm curious why you want this[kCounts] to be a map. It would not have an impact on the ability to use Symbol as a key given the toString() restriction that would still exist. Using the dictionary mode object works just as well. Can you elaborate?
lib/console.js
Outdated
There was a problem hiding this comment.
That is indeed a problem. Can we file an issue at WHATWG, or supply a console.countReset(label) as an extension?
There was a problem hiding this comment.
Opening an issue in the WHATWG repo would be good. I'd be hesitant to add a non-standard method before it was added to the spec.
doc/api/console.md
Outdated
There was a problem hiding this comment.
I'd prefer console.table(tabularData[, properties]) like the IDL specifies.
doc/api/console.md
Outdated
There was a problem hiding this comment.
This might be better implemented as console.log(tabularData), since the second properties argument is not necessarily directly printed according to spec. Also, the spec limits the number of arguments to two, so rest arguments shouldn't be used anyway.
There was a problem hiding this comment.
I'm contemplating just dropping this in this PR, to be honest. Still stewing on it tho.
|
@TimothyGu ... I've pushed a new commit that removes the @Fishrock123 ... I've added a note clarifying that |
doc/api/console.md
Outdated
There was a problem hiding this comment.
Would it be clearer to just say label should be a string? Sure, the function will work if it's passed an object, but the output [object Object]: 1 is usually not what a user would want. Additionally it might be confusing that two distinct objects share a label (since they will both be coerced to [object Object]).
There was a problem hiding this comment.
This is fine but to match the behavior in browsers coercion will still be happening and two separate objects would still end up sharing a label unless they take steps to avoid it (e.g. by using Symbol.toPrimitive, etc)
test/parallel/test-console-clear.js
Outdated
There was a problem hiding this comment.
Nit: how about using camel case for the identifier?
test/parallel/test-console-clear.js
Outdated
There was a problem hiding this comment.
Nit: it doesn't harm, but I find common.mustCall() redundant in this case. The assertion below is sufficient imo.
|
@jasnell I would prefer to not implement it until we can get clarification on the spec end what "clear" means. https://console.spec.whatwg.org/#clear is, unfortunately, not very clear about that. |
|
@domenic ... any opinions on @Fishrock123's concerns around |
|
I don't understand them. The spec is pretty clear that you can do whatever is appropriate for your environment, including nothing. In general if something is about UI, it's up to the implementation to do what it thinks is best for its users. |
|
@TimothyGu ... updated! :-) |
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
|
Landed in cc43c8f ... fyi @addaleax ... this should cherry-pick cleanly into v8.x-staging if you wanted to pull it in to 8.3.0 at all. :-) |
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
|
Release team were +1 on backporting to v6.x. |
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This LTS release comes with 109 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 29 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
#12678
* crypto:
- expose ECDH class (Bryan English)
#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
#10209
- warn on invalid authentication tag length (Tobias Nießen)
#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
#16386
* net:
- return this from getConnections() (Sam Roberts)
#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
#12087
- add process.ppid (cjihrig)
#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
#15179
* url:
- WHATWG URL api support (James M Snell)
#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
#10308
PR-URL: #18342
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This LTS release comes with 109 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 29 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
#12678
* crypto:
- expose ECDH class (Bryan English)
#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
#10209
- warn on invalid authentication tag length (Tobias Nießen)
#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
#16386
* net:
- return this from getConnections() (Sam Roberts)
#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
#12087
- add process.ppid (cjihrig)
#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
#15179
* url:
- WHATWG URL api support (James M Snell)
#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
#10308
PR-URL: #18342
Both are simple utility functions defined by the WHATWG console spec (https://console.spec.whatwg.org/). PR-URL: #12678 Ref: #12675 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This LTS release comes with 109 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 29 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
#12678
* crypto:
- expose ECDH class (Bryan English)
#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
#10209
- warn on invalid authentication tag length (Tobias Nießen)
#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
#16386
* net:
- return this from getConnections() (Sam Roberts)
#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
#12087
- add process.ppid (cjihrig)
#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
#15179
* url:
- WHATWG URL api support (James M Snell)
#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
#10308
PR-URL: #18342
This LTS release comes with 112 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 30 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
#12678
* crypto:
- expose ECDH class (Bryan English)
#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
#10209
- warn on invalid authentication tag length (Tobias Nießen)
#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
#16386
* net:
- return this from getConnections() (Sam Roberts)
#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
#12087
- add process.ppid (cjihrig)
#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
#15179
* url:
- WHATWG URL api support (James M Snell)
#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
#10308
PR-URL: #18342
This LTS release comes with 112 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 30 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
#12678
* crypto:
- expose ECDH class (Bryan English)
#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
#10209
- warn on invalid authentication tag length (Tobias Nießen)
#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
#16386
* net:
- return this from getConnections() (Sam Roberts)
#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
#12087
- add process.ppid (cjihrig)
#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
#15179
* url:
- WHATWG URL api support (James M Snell)
#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
#10308
PR-URL: #18342
This LTS release comes with 112 commits, 17 of which are considered
Semver-Minor. This includes 32 which are doc related, 30 which are test
related, 8 which are build / tool related and 1 commit which updates
a dependency.
Notable Changes:
* console:
- added console.count() and console.clear() (James M Snell)
nodejs#12678
* crypto:
- expose ECDH class (Bryan English)
nodejs#8188
- added cypto.randomFill() and crypto.randomFillSync() (Evan Lucas)
nodejs#10209
- warn on invalid authentication tag length (Tobias Nießen)
nodejs#17566
* deps:
- upgrade libuv to 1.16.1 (cjihrig)
nodejs#16835
* dgram:
- added socket.setMulticastInterface() (Will Young)
nodejs#7855
* http:
- add agent.keepSocketAlive and agent.reuseSocket as to allow
overridable keep-alive behavior of `Agent` (Fedor Indutny)
nodejs#13005
* lib:
- return this from net.Socket.end() (Sam Roberts)
nodejs#13481
* module:
- add builtinModules api that provides list of all builtin modules in
Node (Jon Moss)
nodejs#16386
* net:
- return this from getConnections() (Sam Roberts)
nodejs#13553
* promises:
- more robust stringification for unhandled rejections (Timothy Gu)
nodejs#13784
* repl:
- improve require() autocompletion (Alexey Orlenko)
nodejs#14409
* src:
- add openssl-system-ca-path configure option (Daniel Bevenius)
nodejs#16790
- add --use-bundled-ca --use-openssl-ca check (Daniel Bevenius)
nodejs#12087
- add process.ppid (cjihrig)
nodejs#16839
* tls:
- accept `lookup` option for `tls.connect()` (Fedor Indutny)
nodejs#12839
* tools, build:
- a new macOS installer! (JP Wesselink)
nodejs#15179
* url:
- WHATWG URL api support (James M Snell)
nodejs#7448
* util:
- add %i and %f formatting specifiers (Roman Reiss)
nodejs#10308
PR-URL: nodejs#18342
Both are simple utility functions defined by the WHATWG console spec.
Ref: #12675
/cc @addaleax
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
console