Skip to content
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 more standard compliant #17708

Closed
wants to merge 3 commits into from

Conversation

@BridgeAR
Copy link
Member

commented Dec 16, 2017

According to the standard the property descriptor of console
should be writable and non-enumerable.

Refs #12454
Fixes: #11805

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

console

const prototype1 = Object.getPrototypeOf(console);
const prototype2 = Object.getPrototypeOf(prototype1);

// This got commented out from the original test because in Node.js all functions are declared on the prototype.

This comment has been minimized.

Copy link
@Trott

Trott Dec 16, 2017

Member

Nit: Even though the test isn't ours, this comment is, right? If so, maybe wrap it at 80 chars?

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Dec 16, 2017

Author Member

Sure

@Trott

This comment has been minimized.

Copy link
Member

commented Dec 16, 2017

pinging previous approvers: @TimothyGu @refack @bnoordhuis @addaleax @benjamingr @watilde @cjihrig

pinging author of first commit: @Wandalen

@@ -354,10 +352,9 @@
originalConsole[key],
wrappedConsole[key],
config);
delete originalConsole[key];

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 16, 2017

Member

Why was this added and why were the two lines below removed?

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Dec 16, 2017

Author Member

Ah, this should probably be a individual commit. It is only about a few entries but it did not feel good that we checked all entries again instead of just removing them beforehand.

This comment has been minimized.

Copy link
@apapirovski

apapirovski Jan 17, 2018

Member

Hmm, I'm not sure what effect deleting originalConsole[key] could have. Is it really safe?


// Should be above require, because code in require read console
// what we are trying to avoid
// set should be earlier than get

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 16, 2017

Member

Cryptic comment. Maybe this?

Patch global.console before importing modules that may modify the console object.

// 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.

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 16, 2017

Member

Incomprehensible comment... I'd remove it.

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Dec 16, 2017

Author Member

After reading it... I totally agree. I have no idea what it stands for.

@BridgeAR BridgeAR force-pushed the BridgeAR:console-standard branch 2 times, most recently from 44ea72f to 965146c Dec 16, 2017

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Dec 16, 2017

I addressed the comments and refactored the test as it did feel like it could need some further polishing. Originally I did not touch the version from @Wandalen to keep the authorship in tact. This way it diverges quite a lot from the original.

@bnoordhuis I also separated the other bootstrapping part. It was just to minimize the necessary operations. Since delete is actually still slow, it might not yield any performance benefit but the opposite, so I am also totally fine with removing that part again.

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Dec 18, 2017

@BridgeAR BridgeAR added author ready and removed author ready labels Dec 18, 2017

@BridgeAR BridgeAR requested a review from nodejs/tsc Dec 18, 2017

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Dec 21, 2017

@nodejs/tsc PTAL. This needs more LGs.

@targos

targos approved these changes Dec 21, 2017

@mcollina
Copy link
Member

left a comment

LGTM

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Dec 21, 2017

@Wandalen I do not feel comfortable landing this with my changes to the tests without your permission. Would you be so kind and have a look?

A alternative would probably be to use the original code from @Wandalen and have a separate commit from me that changes the file accordingly. What do you all think about that?

lib: make console writable and non-enumerable
According to the standard the property descriptor of console
should be writable and non-enumerable.

Fixes: #11805

@BridgeAR BridgeAR force-pushed the BridgeAR:console-standard branch from 965146c to 8388836 Jan 17, 2018

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Jan 17, 2018

I separated the code from @Wandalen and me.

@BridgeAR BridgeAR requested a review from apapirovski Jan 17, 2018

@apapirovski
Copy link
Member

left a comment

LGTM but the one delete statement flagged by @bnoordhuis does concern me.

@@ -354,10 +352,9 @@
originalConsole[key],
wrappedConsole[key],
config);
delete originalConsole[key];

This comment has been minimized.

Copy link
@apapirovski

apapirovski Jan 17, 2018

Member

Hmm, I'm not sure what effect deleting originalConsole[key] could have. Is it really safe?

@apapirovski

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Also, FWIW, I think the check is very likely faster than the delete. The latter is very expensive in my experience.

@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Jan 17, 2018

@apapirovski that is indeed probably true. It just felt more natural for me this way. I am also sure it is a safe thing to do but due to the concerns and since it is not necessary at all, I am going to remove that commit.

Wandalen and others added some commits Apr 17, 2017

test: add standard console tests
This imports a standard test from w3c/web-platform-tests
(console-is-a-namespace).

@BridgeAR BridgeAR force-pushed the BridgeAR:console-standard branch from 8388836 to 1193065 Jan 17, 2018

@BridgeAR

This comment has been minimized.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Jan 18, 2018

lib: make console writable and non-enumerable
According to the standard the property descriptor of console
should be writable and non-enumerable.

PR-URL: nodejs#17708
Fixes: nodejs#11805
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

BridgeAR added a commit to BridgeAR/node that referenced this pull request Jan 18, 2018

test: add standard console tests
This imports a standard test from w3c/web-platform-tests
(console-is-a-namespace).

PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

BridgeAR added a commit to BridgeAR/node that referenced this pull request Jan 18, 2018

test: improve console tests
PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
@BridgeAR

This comment has been minimized.

Copy link
Member Author

commented Jan 18, 2018

Landed in f054855...7809f38

@BridgeAR BridgeAR closed this Jan 18, 2018

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

lib: make console writable and non-enumerable
According to the standard the property descriptor of console
should be writable and non-enumerable.

PR-URL: nodejs#17708
Fixes: nodejs#11805
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

test: add standard console tests
This imports a standard test from w3c/web-platform-tests
(console-is-a-namespace).

PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

test: improve console tests
PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

lib: make console writable and non-enumerable
According to the standard the property descriptor of console
should be writable and non-enumerable.

PR-URL: nodejs#17708
Fixes: nodejs#11805
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

test: add standard console tests
This imports a standard test from w3c/web-platform-tests
(console-is-a-namespace).

PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

test: improve console tests
PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
@kfarnung kfarnung referenced this pull request Apr 21, 2018
2 of 2 tasks complete

kfarnung added a commit to kfarnung/node that referenced this pull request Apr 21, 2018

lib: make sure `console` is writable
The code currently assumes that `console` is already writable, but
that's only if it was previously defined as writable. If it hasn't
already been defined then the default value is false.

Refs: nodejs#17708

kfarnung added a commit that referenced this pull request Apr 24, 2018

lib: make sure `console` is writable
The code currently assumes that `console` is already writable, but
that's only if it was previously defined as writable. If it hasn't
already been defined then the default value is false.

Refs: #17708

PR-URL: #20185
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

MylesBorins added a commit that referenced this pull request May 4, 2018

lib: make sure `console` is writable
The code currently assumes that `console` is already writable, but
that's only if it was previously defined as writable. If it hasn't
already been defined then the default value is false.

Refs: #17708

PR-URL: #20185
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

MayaLekova added a commit to MayaLekova/node that referenced this pull request May 8, 2018

lib: make console writable and non-enumerable
According to the standard the property descriptor of console
should be writable and non-enumerable.

PR-URL: nodejs#17708
Fixes: nodejs#11805
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

MayaLekova added a commit to MayaLekova/node that referenced this pull request May 8, 2018

test: add standard console tests
This imports a standard test from w3c/web-platform-tests
(console-is-a-namespace).

PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

MayaLekova added a commit to MayaLekova/node that referenced this pull request May 8, 2018

test: improve console tests
PR-URL: nodejs#17708
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

@BridgeAR BridgeAR deleted the BridgeAR:console-standard branch Apr 1, 2019

decentralion added a commit to decentralion/node-eval that referenced this pull request Jul 5, 2019

ensure that globals includes process and console
The code attaches global properties to the sandbox context by iterating
over all the enumerable properties of `global`. However, in node v10,
`console` switched [to being non-enmuerable][1]. This means that for
users of this library with node>10, any `console.log`s in evaluated
scripts will fail.

This commit fixes this issue by manually attaching console to the
sandbox (when globals are being used). A test has been added. Prior to
the change to eval.js, the test would pass in node v8 but fail in v10
and v12.

Also, the tests were already failing in v12, because in v12 `process`
also became non-enumerable. I've applied a similar fix to `process` to
ensure that it's always available too.

[1]: nodejs/node#17708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.