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

esm: fixup process Proxy to handle toString correctly #25963

Closed
wants to merge 1 commit into from

Conversation

guybedford
Copy link
Contributor

This fixes the following --experimental-modules bug:

import process from 'process';
// returns [object Object] instead of [object process]
console.log(Object.prototype.toString.call(process));

//cc @devsnek

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

@bmeck
Copy link
Member

bmeck commented Feb 6, 2019

Should we just set this unconditionally when we setup the process Object to begin with? Why do it lazily?

lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
@joyeecheung
Copy link
Member

Should we just set this unconditionally when we setup the process Object to begin with? Why do it lazily?

The process object is not a proxy, only the one exported by import process from 'process' is.

@devsnek
Copy link
Member

devsnek commented Feb 7, 2019

This seems kind of backward, why not just install Symbol.toStringTag on the process object anyway?

@zenparsing
Copy link

zenparsing commented Feb 7, 2019

I've run into a few test failures when experimenting with removing the experimental-modules flag. I'm worried that proxifying native modules is going to cause other breaking changes in addition to the one described here.

Copy link
Member

@jdalton jdalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 👎 on this work. Next week (2019-02-13) the Module WG will resolve a bunch of things that affect the direction and features of experimental modules. I don't see a strong pull for this addition when it will likely change come April.

@guybedford
Copy link
Contributor Author

This is a bug fix to existing behaviour. If you're against the existing behaviour, sure, but I don't think complaints against the existing behaviour should stop bug fixes from landing against it, that seems very counter-productive.

@guybedford
Copy link
Contributor Author

@jdalton the freeze on modules in Node.js core was for new features not bug fixes as well. Note also that the current minimal implementation also retains this work as well so that this isn't currently slated for any changes or removals either.

@guybedford
Copy link
Contributor Author

This seems kind of backward, why not just install Symbol.toStringTag on the process object anyway?

@devsnek could you share a code example of what you mean here? I thought that was what this is doing already?

@devsnek
Copy link
Member

devsnek commented Feb 17, 2019

@guybedford right now the toString behaviour comes from setting a native name in the V8 API. instead of doing that, let's just put a toStringTag on the original process object, and then no changes to the proxy need to be made.

@guybedford
Copy link
Contributor Author

Ok, I've updated this approach to simply define Symbol.toStringTag on process to begin with.

@danbev
Copy link
Contributor

danbev commented Feb 18, 2019

PR-URL: nodejs#25963
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@guybedford
Copy link
Contributor Author

@jasnell
Copy link
Member

jasnell commented Feb 22, 2019

Manual LGTM as the Review button appears to currently be broken in the Github UI

@guybedford
Copy link
Contributor Author

Running CI again due to a bsd flaky case, just to be sure - https://ci.nodejs.org/job/node-test-pull-request/21165/.

@guybedford
Copy link
Contributor Author

Landed in ccaebde.

@guybedford guybedford closed this Mar 3, 2019
BridgeAR pushed a commit that referenced this pull request Mar 4, 2019
PR-URL: #25963
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Mar 4, 2019
@SimenB
Copy link
Member

SimenB commented Mar 7, 2019

This change has broken Jest (4.5M weekly downloads): jestjs/jest#8069

While this is fixed in Jest on master old versions are still broken. Not sure if just making it writable fixes it?

@guybedford
Copy link
Contributor Author

guybedford commented Mar 7, 2019 via email

@SimenB
Copy link
Member

SimenB commented Mar 7, 2019

#26488

@targos
Copy link
Member

targos commented Mar 7, 2019

Is there anything blocking us from having Jest tested in CITGM?

Edit: Yes. I opened nodejs/citgm#684

@targos
Copy link
Member

targos commented Mar 7, 2019

I labeled this dont-land on LTS

@SimenB
Copy link
Member

SimenB commented Mar 7, 2019

We've tried before, but colors were wrong (a whole bunch of Jest's tests fail if terminal colors do not work), ref nodejs/citgm#560 (comment)

nikolas added a commit to ccnmtl/astro-simulations that referenced this pull request Mar 7, 2019
Should fix the jest failure on master.

* nodejs/node#25963 (comment)
* jestjs/jest#8069
nikolas added a commit to ccnmtl/astro-simulations that referenced this pull request Mar 7, 2019
Should fix the jest failure on master.

* nodejs/node#25963 (comment)
* jestjs/jest#8069
nikolas added a commit to ccnmtl/astro-simulations that referenced this pull request Mar 7, 2019
Should fix the jest failure on master.

* nodejs/node#25963 (comment)
* jestjs/jest#8069
nikolas added a commit to ccnmtl/econplayground.js that referenced this pull request Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.