-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console: make console consistent with the standard - overridable #12454
console: make console consistent with the standard - overridable #12454
Conversation
const prototype1 = Object.getPrototypeOf(console); | ||
const prototype2 = Object.getPrototypeOf(prototype1); | ||
// console.log('console',Object.getOwnPropertyNames(console)); | ||
// console.log('prototype1',Object.getOwnPropertyNames(prototype1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did these two lines come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { test, assert_equals, assert_true, assert_false } = common.WPT; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the standard header for WPT tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi TinothyGu. Do you mean remove assert_false from the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. I was referring to the "WPT Refs" block in the file I linked. Specifically, a permalink to the source of the file as well as a URL pointing to the license under which the WPT test is used should be included for compliance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explanation. Added.
'The [[Prototype]]\'s [[Prototype]] must be Object Prototype'); | ||
|
||
}, 'The prototype chain must be correct'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please use the standard footer here, since the test below is not part of WPT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added /* eslint-enable */
lib/internal/bootstrap_node.js
Outdated
return console; | ||
}, | ||
set: function(customConsole) { | ||
console = customConsole; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment will invalidate the if (console)
check above in the getter, in the case that global.console
is deliberately set to any falsy value like global.console = undefined;
. Instead, do the same thing you did in the getter and use Object.defineProperty()
on global
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu not certain I understood you. global.console = undefined is completely legal operation according to the standard. @TimothyGu purpose of the PR is making nodejs console consistent with the standard. Do you understand it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu removing set will make console not-overridable again. If you see a problem please explain it to find better solution than suggested by you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was:
// Initially, the `console` variable is `undefined`, since console will be lazily
// loaded in the getter.
global.console = undefined;
// global.console's setter is called; the `console` variable remains `undefined`.
assert.strictEqual(global.console, undefined);
// global.console's getter is called
// Since the `console` cache variable is `undefined` and therefore false-y,
// the getter still calls NativeModule.require() and returns the object
// obtained from it, instead of returning `undefined` as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thinking about solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested solution. Good point actually. I added a separate test suite specifically for the problem. It sets global.console = undefined above requires. Otherwise something in requires read global.console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu any further requests/insights?
configurable: true, | ||
writable: true, | ||
enumerable: false, | ||
value: console |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customConsole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh mine. I'm sleepy. It's late here. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to add more tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu added few more tests.
|
||
/* eslint-disable */ | ||
/* WPT Refs: | ||
https://github.com/w3c/web-platform-tests/blob/master/console/console-is-a-namespace.any.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better reference a specific commit hash here (40e451c
instead of master
) in case the file changes or turns into a 404
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/internal/bootstrap_node.js
Outdated
@@ -268,15 +268,29 @@ | |||
var console; | |||
Object.defineProperty(global, 'console', { | |||
configurable: true, | |||
enumerable: true, | |||
enumerable: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes need to be semver-major as this might break user code, although hopefully very rarely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html | ||
*/ | ||
|
||
assert.doesNotThrow(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't come from the WPT, and we don't use it in this test. I think we can get rid of it :)
const assert = require('assert'); | ||
const { test, assert_equals, assert_true, assert_false } = common.WPT; | ||
|
||
assert.doesNotThrow(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with L23. We can get rid of this test from this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @watilde
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean exclude a duplicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you're right! It's better to keep the test case to verify the update, and we don't need to move it into a separate file since this test is related to namespace :)
|
||
// Initially, the `console` variable is `undefined`, since console will be | ||
// lazily loaded in the getter. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make jslint
threw an error:
node/test/parallel/test-console-assing-undefined.js
1:1 error Mandatory module "common" must be loaded required-modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding require common gives "'common' is assigned a value but never used". What would be appropriate resolution of the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simulating of usage or adding a directive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just don't assign it anywhere. Instead of const common = require('../common');
do require('../common');
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aqrln Smart. Do you participate in OdesaJS this year?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@watilde fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wandalen almost there :) The common
module should be the first one that a test require
s. Please see our guide on writing tests.
Do you participate in OdessaJS this year?
Yep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aqrln I shall share my experience too if organizers won't be mean :)
lib/internal/bootstrap_node.js
Outdated
return console; | ||
}, | ||
set: function(customConsole) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use a set(customConsole) {
shorthand here (for the getter as well if you like) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax thank you for your advices. I used => shorthand as you advised in the recent commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax can/should I push that changes after TimothyGu launched remote testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wandalen go ahead and push it. The CI is done already (the "pending" windows-fanned instance is having some infrastructural issues). And we can always launch a new CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
writable: true, | ||
enumerable: false, | ||
value: console | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this maybe use the setter directly, i.e. as global.console = console
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax I tried that. global.console = console fails at test/common.js:407 with message
AssertionError: Unexpected global(s) found: console
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can fix that in test-console-is-a-namespace.js by calling common.allowGlobals('console')
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail comes form
=== release console_low_stack_space ===
Path: message/console_low_stack_space
Hello, World!
assert.js:86
throw new assert.AssertionError({
I tried common.allowGlobals('console') in that file and 2 I create, it didn't help. Maybe I do something wrong.
@Wandalen could you add a link to the standard in the first comment (I assume it's https://console.spec.whatwg.org/#console-namespace) |
@nodejs/ctc This would require another CTC approval, do you mind taking a look? |
|
||
// Tests above are not from WPT. | ||
|
||
/* eslint-disable */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Node collaborators should not modify these tests in any way, please add a comment here stating that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjihrig like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the comment inside the existing WPT Refs:
block comment and say something like "The following tests are copied from upstream verbatim. Do not modify."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjihrig done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjihrig do you want any other improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjihrig are you going approve my PR? Do you have any objection? Do you make all newcomers feel unwelcome here or it's personal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wandalen ... this kind of comment is unwarranted. We are all busy and this repository has a high level of activity that is often difficult to keep track of. Many of us receive hundreds of notifications per day. Patience would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell could you please tell what would be an appropriate comment there? I caught another issue with ArrayBuffer. Looking forward to starting work on that issue once you will approve the PR. At the point, I clearly see that the majority of the community is friendly, but the minority make me feel unwelcome here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wandalen try not to get frustrated, and really don't take it personally.
Initially I also had a hard time trying to deduce people's intention and emotions from just these text messages. It's hard, I misunderstood some stuff, I took it personally, and I got frustrated, and then angry, and that leads to nowhere good.
If you found another issue to channel your energy into, I say go for it. This PR will most probably land in due time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack thank you for kind words.
I personally think all these specs make way too many things unenumberable without much reason, so... -1 on that? I guess? |
@Fishrock123 on what? enumerability off or the whole propose? |
98388d5
to
662a8ba
Compare
I'd like to see this get across the finish line or, if that's not something that's going to happen, closed. So, I rebased, fixed a failing test, pulled in the latest/greatest from the WPT test suite for one test, and updated some comments. PTAL! @Fishrock123 Is your -1 a blocking -1 or just an expression of annoyance with standards bodies' fondness for making things unenumerable? @cjihrig I think your changes-requested can be dismissed, but let me know if that's not right. If anyone is all "Wait, what, no way! Don't do this!", now's a great time to register your opinion. |
Update the test from the most recent WPT contents. Copyedit some existing comments.
662a8ba
to
490374f
Compare
const self = global; | ||
|
||
/* eslint-disable */ | ||
/* The following tests are copied from */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still prefer if this said not to modify, not just that it's copied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but it would be great to have the comment nit addressed.
When I just ran the tests for it again I realized that this is not working. It works with the following patch --- a/test/message/console_low_stack_space.js
+++ b/test/message/console_low_stack_space.js
@@ -16,7 +16,7 @@ function a() {
try {
return a();
} catch (e) {
- compiledConsole = consoleDescriptor.get();
+ compiledConsole = consoleDescriptor.value;
if (compiledConsole.log) {
// Using `console.log` itself might not succeed yet, but the code for it
// has been compiled. Addressing the nit diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js
index 1beb392621..28b0668f41 100644
--- a/test/parallel/test-console-is-a-namespace.js
+++ b/test/parallel/test-console-is-a-namespace.js
@@ -13,7 +13,7 @@ assert.doesNotThrow(() => {
const self = global;
/* eslint-disable */
-/* The following tests are copied from */
+/* The following tests should not be modified as they are copied from */
/* WPT Refs:
https://github.com/w3c/web-platform-tests/blob/40e451c/console/console-is-a-namespace.any.js
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html I would also like to add the following patch because I think it is a bad idea to add commented code to core. Instead it should be added when necessary. diff --git a/test/parallel/test-console-is-a-namespace.js b/test/parallel/test-console-is-a-namespace.js
index f413000805..1beb392621 100644
--- a/test/parallel/test-console-is-a-namespace.js
+++ b/test/parallel/test-console-is-a-namespace.js
@@ -38,12 +38,4 @@ test(() => {
assert_false("Console" in self);
}, "Console (uppercase, as if it were an interface) must not exist");
-
-// test(() => {
-// const prototype1 = Object.getPrototypeOf(console);
-// const prototype2 = Object.getPrototypeOf(prototype1);
-
-// assert_equals(Object.getOwnPropertyNames(prototype1).length, 0, "The [[Prototype]] must have no properties");
-// assert_equals(prototype2, Object.prototype, "The [[Prototype]]'s [[Prototype]] must be %ObjectPrototype%");
-// }, "The prototype chain must be correct");
/* eslint-enable */ |
Hello @BridgeAR. What test cases does it break? Why did you added enumerable: true? I believe there should be enumerable: false. |
I did not change the console to be enumerable (your test case would also fail in that case) and you actually struggled with the test case that I fixed. The default for enumerable is So please feel free to add my patches so this can land. @Wandalen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test must be fixed and I would like the other two comments addressed as well.
Ping @Wandalen this now needs a rebase. |
Closing this due to the long inactivity. @Wandalen please leave a comment if you would like to pursue this further. |
make console overridable by custom console( without delete )
add test suite from w3c/web-platform-tests( console-is-a-namespace )
few test cases commented out from the test suite
to make nodejs console even more consistent further changes needed
which will come in the next commit
which could be more breaking than this one
Fixes: #11805
Ref: https://console.spec.whatwg.org/#console-namespace
Ref: https://heycam.github.io/webidl/#es-namespaces
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)