You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing testing utilities and have trouble on nodejs platform ridding off unwanted output.
"console" is writable property in a browser. On nodejs "console's" methods could be rewritten iterating them, so making "console" non-writable does not give any insurance, but only make solving of my problem and similar more tedious. From my point of view having "console" non-writable counter-intuitive neither reasonable.
@Wandalen If you want, you can open a PR; the code you’ll want to look at is in setupGlobalConsole() in lib/internal/bootstrap_node.js.
It’s not as simple as just switching a boolean, though; I think you might need to do something like addBuiltinLibsToObject() in lib/internal/module.js to work around the fact that we currently need a getter mechanism for global.console.
I think it’s both ok to fix this and to leave it as is – the property is still configurable, so if you really want to, you can delete global.console; global.console = …; already.
Let us know if you have any questions or there’s something we can help with!
Thank you @watilde for the link on w3c test and test from the repo, it was extremely useful. @addaleax you are right, overriding of a console with 2 steps( delete, assign ) was possible. Nevertheless, it was not consistent with the standard.
The first commit makes console overridable without delete with minimum changes.
The second commit makes console writable, not enumerable and give property descriptor value field as it supposes to be according to the standard.
One more test case stays commented out.
A prototype of a console should have own none fields according to the standard, but currently, have:
'constructor',
'log',
'info',
'warn',
'error',
'dir',
'time',
'timeEnd',
'trace',
'assert'
Please let me know should I make corresponding adjustments to make the test case pass.
A prototype of a console should have own none fields according to the standard
That is true, but Node.js has always had console as an instance of require('console').Console, and it might be unfortunately too late to change that now due to backwards compatibility requirements.
@TimothyGu thanks for your suggestions. Regarding the test case, I can try. Do you think that aspect of functionality covered by tests good enough to trust them? Currently, don't see why it would be impossible.
Activity
sam-github commentedon Mar 23, 2017
Sounds OK to me, @Wandalen, are you going to PR this?
Wandalen commentedon Mar 23, 2017
OK fixing or OK leaving as is? :) I would be glad to make a pull request.
addaleax commentedon Mar 27, 2017
@Wandalen If you want, you can open a PR; the code you’ll want to look at is in
setupGlobalConsole()inlib/internal/bootstrap_node.js.It’s not as simple as just switching a boolean, though; I think you might need to do something like
addBuiltinLibsToObject()inlib/internal/module.jsto work around the fact that we currently need a getter mechanism forglobal.console.I think it’s both ok to fix this and to leave it as is – the property is still configurable, so if you really want to, you can
delete global.console; global.console = …;already.Let us know if you have any questions or there’s something we can help with!
Wandalen commentedon Mar 27, 2017
Yes, sure, I will do. Thank you for hints, Addaleax.
watilde commentedon Mar 27, 2017
FYI: I think you could pick a test from WPT to test writable console as like test-whatwg-url-constructor.js.
Wandalen commentedon Mar 27, 2017
Understood, thank you. Will find free time soon.
Wandalen commentedon Apr 17, 2017
Thank you @watilde for the link on w3c test and test from the repo, it was extremely useful. @addaleax you are right, overriding of a console with 2 steps( delete, assign ) was possible. Nevertheless, it was not consistent with the standard.
Wandalen commentedon Apr 17, 2017
The first commit makes console overridable without delete with minimum changes.
The second commit makes console writable, not enumerable and give property descriptor value field as it supposes to be according to the standard.
One more test case stays commented out.
A prototype of a console should have own none fields according to the standard, but currently, have:
'constructor',
'log',
'info',
'warn',
'error',
'dir',
'time',
'timeEnd',
'trace',
'assert'
Please let me know should I make corresponding adjustments to make the test case pass.
TimothyGu commentedon Apr 17, 2017
That is true, but Node.js has always had
consoleas an instance ofrequire('console').Console, and it might be unfortunately too late to change that now due to backwards compatibility requirements.Wandalen commentedon Apr 17, 2017
@TimothyGu changes which you requested break test suite.
Wandalen commentedon Apr 17, 2017
@TimothyGu thanks for your suggestions. Regarding the test case, I can try. Do you think that aspect of functionality covered by tests good enough to trust them? Currently, don't see why it would be impossible.
TimothyGu commentedon Apr 17, 2017
@Wandalen let's talk more about what you have included in the PR in the PR itself.
Wandalen commentedon Apr 22, 2017
@TimothyGu, @watilde, @addaleax, @sam-github, @bnoordhuis, @Fishrock123 do you want any other adjustment? Can I be useful with other related issue?
console: make console consistent with the standard - overridable
console: make console consistent - writable, not enumerable
console: take care of console set undefined case
Trott commentedon Aug 16, 2017
I revived #12454 in the hopes of getting it landed (or, if there are firm objections to the whole concept, closed).
lib: make console writable and non-enumerable
lib: make console writable and non-enumerable
lib: make console writable and non-enumerable