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

domain: Make `.domain` on async resources non-enumerable #26210

Closed
wants to merge 1 commit into
base: master
from

Conversation

@ljharb
Copy link
Contributor

ljharb commented Feb 20, 2019

In particular, this comes into play in the node repl, which apparently enables domains by default. Whenever any Promise gets inspected, a .domain property is displayed, which is very confusing, especially since it has some kind of WeakReference attached to it, which is not yet a language feature.

This change will prevent it from showing up in casual inspection, but will leave it available for use.

I have not run the tests locally yet, because they're incredibly slow and I need to do other things with my machine, and because the last time I tried some of them failed on master anyways.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

cc @addaleax @devsnek

domain: set `.domain` non-enumerable on resources
In particular, this comes into play in the node repl, which apparently
enables domains by default. Whenever any Promise gets inspected, a
`.domain` property is displayed, which is *very confusing*, especially
since it has some kind of WeakReference attached to it, which is not yet
a language feature.

This change will prevent it from showing up in casual inspection, but
will leave it available for use.
@addaleax
Copy link
Member

addaleax left a comment

LGTM

/cc @BridgeAR

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch 2 times, most recently from 9d0013e to ed34d24 Feb 20, 2019

@BridgeAR
Copy link
Member

BridgeAR left a comment

LGTM. It would be nice to add a test to it as well.

@targos

targos approved these changes Feb 20, 2019

@lpinca

lpinca approved these changes Feb 20, 2019

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch 2 times, most recently from b233a06 to 084f7b2 Feb 21, 2019

@MylesBorins

This comment has been minimized.

Copy link
Member

MylesBorins commented Feb 22, 2019

@Trott

This comment has been minimized.

Copy link
Member

Trott commented Feb 22, 2019

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch 2 times, most recently from 11c1de7 to caa10ed Feb 25, 2019

@addaleax

This comment has been minimized.

@ChALkeR

ChALkeR approved these changes Mar 1, 2019

Copy link
Member

ChALkeR left a comment

LGTM!

Does this need tests?

What's the semver status of this? I don't think this is a major, but is it a minor or patch?

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 1, 2019

I’d call it a patch; imo it fixes confusion in the repl.

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch from caa10ed to 311cec0 Mar 3, 2019

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 5, 2019

@ljharb would you mind adding a test?

@Trott

This comment has been minimized.

Copy link
Member

Trott commented Mar 5, 2019

I have not run the tests locally yet, because they're incredibly slow and I need to do other things with my machine, and because the last time I tried some of them failed on master anyways.

@ljharb If you want to only run domain tests, you can do tools/test.py domain. On my machine, that runs 50 test files in 11 seconds. (No failures on master branch.)

@Trott

This comment has been minimized.

Copy link
Member

Trott commented Mar 5, 2019

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 5, 2019

@BridgeAR I've added some; let me know if that's not what you had in mind :-)

@Trott

no dice :-/
$ tools/test.py domain
Traceback (most recent call last):
  File "tools/test.py", line 1766, in <module>
    sys.exit(Main())
  File "tools/test.py", line 1639, in Main
    vm = context.GetVm(arch, mode)
  File "tools/test.py", line 953, in GetVm
    raise ValueError('Could not find executable. Should be ' + name)
ValueError: Could not find executable. Should be out/Release/node

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch from 311cec0 to 9be90d9 Mar 5, 2019

@addaleax

This comment was marked as outdated.

Copy link
Member

addaleax commented Mar 5, 2019

@ljharb Something like python tools/test.py '*/test-domain*' should work.

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 5, 2019

@ljharb you have to compile Node.js first. Otherwise the tests can't run.

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 5, 2019

@ljharb I just started a CI and it seems like there are linter errors.

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch from 9be90d9 to 5aca8a1 Mar 6, 2019

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 6, 2019

@BridgeAR thanks, fixed.

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch from 5aca8a1 to 3308853 Mar 8, 2019

@BridgeAR
Copy link
Member

BridgeAR left a comment

Do we really need all of these defineProperty calls? If I am not mistaken we only have to set the property to enumerable false once and every following assignment will keep the descriptor in place.

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 10, 2019

@BridgeAR certainly you're right, but for all of the objects that aren't previously defined - like newly created resources, errors, event emitters, etc - it'd need the defineProperty every time.

Show resolved Hide resolved lib/domain.js Outdated
Show resolved Hide resolved lib/domain.js Outdated

@ljharb ljharb force-pushed the ljharb:domain_non_enumerable branch from 3308853 to b1ae6f4 Mar 11, 2019

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 11, 2019

@BridgeAR updated

@devsnek

This comment has been minimized.

Copy link
Member

devsnek commented Mar 12, 2019

@MylesBorins

This comment has been minimized.

Copy link
Member

MylesBorins commented Mar 12, 2019

@misterdjules do you have any thoughts on this?

@ljharb

This comment has been minimized.

Copy link
Contributor Author

ljharb commented Mar 12, 2019

As far as semver - this could be considered semver-major if someone was using the domains flag, and also enumerating an async resource, and then relying on domain to be present there - but I can't imagine why anyone would be doing that. That would make this either a major or a patch, depending on the level of conservatism.

@addaleax

This comment has been minimized.

Copy link
Member

addaleax commented Mar 13, 2019

Landed in 377c583 :)

@addaleax addaleax closed this Mar 13, 2019

addaleax added a commit that referenced this pull request Mar 13, 2019

domain: set `.domain` non-enumerable on resources
In particular, this comes into play in the node repl, which apparently
enables domains by default. Whenever any Promise gets inspected, a
`.domain` property is displayed, which is *very confusing*, especially
since it has some kind of WeakReference attached to it, which is not yet
a language feature.

This change will prevent it from showing up in casual inspection, but
will leave it available for use.

PR-URL: #26210
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>

@ljharb ljharb deleted the ljharb:domain_non_enumerable branch Mar 13, 2019

BridgeAR added a commit that referenced this pull request Mar 14, 2019

domain: set `.domain` non-enumerable on resources
In particular, this comes into play in the node repl, which apparently
enables domains by default. Whenever any Promise gets inspected, a
`.domain` property is displayed, which is *very confusing*, especially
since it has some kind of WeakReference attached to it, which is not yet
a language feature.

This change will prevent it from showing up in casual inspection, but
will leave it available for use.

PR-URL: #26210
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>

BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 14, 2019

domain: set `.domain` non-enumerable on resources
In particular, this comes into play in the node repl, which apparently
enables domains by default. Whenever any Promise gets inspected, a
`.domain` property is displayed, which is *very confusing*, especially
since it has some kind of WeakReference attached to it, which is not yet
a language feature.

This change will prevent it from showing up in casual inspection, but
will leave it available for use.

PR-URL: nodejs#26210
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>

BridgeAR added a commit that referenced this pull request Mar 14, 2019

domain: set `.domain` non-enumerable on resources
In particular, this comes into play in the node repl, which apparently
enables domains by default. Whenever any Promise gets inspected, a
`.domain` property is displayed, which is *very confusing*, especially
since it has some kind of WeakReference attached to it, which is not yet
a language feature.

This change will prevent it from showing up in casual inspection, but
will leave it available for use.

PR-URL: #26210
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@misterdjules

This comment has been minimized.

Copy link
Contributor

misterdjules commented Mar 14, 2019

@MylesBorins This is great!

I ran into this recently when logging restify errors created from within a domain and we had to filter the domain property out. Having that property not enumerable would have avoided that issue in the first place.

And thanks for pinging me here, very much appreciated ❤️

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.