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

bootstrap: --frozen-intrinsics override workaround #28254

Closed
wants to merge 2 commits into from

Conversation

guybedford
Copy link
Contributor

@guybedford guybedford commented Jun 16, 2019

So it turns out I've been doing it wrong this whole time and SES already has a solution to the "override problem".

This adopts the approach taken in https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/mutable.js, which is to turn all intrinsic prototype value properties into getters and setters, with the setter updating the object as if it were still a value property in the override case.

This then gets all those edge cases that were previously documented with work-arounds to work out correctly, meaning that most third-party code becomes compatible with this flag. I just tested this on a large Node.js application and everything worked fine! I've also re-enabled the freezing of error prototypes and console now that these are supported.

Thanks @erights for the pointer on this one.

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

@nodejs-github-bot
Copy link
Collaborator

Sadly, an error occurred when I tried to trigger a build. :(

Copy link
Contributor

@erights erights left a comment

Choose a reason for hiding this comment

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

I think there's a more recent version of beMutable around somewhere. The name beMutable is my fault. It is terrible, since it does not make any object mutable. I think the more recent version, if I can find it, had a marginally better name but not a good one. Suggestions appreciated.

Doing this repair on all prototypes I suspect is overkill. Salesforce does it only for IIRC 5: Object.prototype, Array.prototype, Error.prototype, Function.prototype, and RegExp.prototype.

For the current state without this PR, can we gather statistics of where we're actually running into the override mistake on a corpus of real code?

Attn @jfparadis @michaelfig

@guybedford
Copy link
Contributor Author

Certainly we could reduce the application of the fix and then just apply it when we hit bugs (like we did with console in #27663), my concern with that is just that the bugs may be highly unexpected and difficult to track. While we could automate that process by running this flag against the CI smoke test libraries and see how far it gets, fixing as necessary, there will always be edge cases that will be missed.

I've been trying to think of this in terms of something we could imagine being lowered into v8 and a spec at some point, where the generic approach feels like it is probably the better way to ensure consistency? What would be the concerns of applying it to all intrinsic prototypes?

Will put some thought to naming too.

@erights
Copy link
Contributor

erights commented Jun 17, 2019

I agree there's no clear advantage to being stingy on applying this trick. Let's try it your way and see if we find any problems.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

nit: the commit message is not quite informative.

test/parallel/test-freeze-intrinsics.js Outdated Show resolved Hide resolved
@guybedford guybedford force-pushed the frozen-intrinsics-define branch 2 times, most recently from e4b11c9 to cb82de1 Compare June 17, 2019 10:26
@guybedford
Copy link
Contributor Author

I've changed the naming to enableDerivedOverrides. Best I could come up with, but suggestions welcome further too.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@guybedford
Copy link
Contributor Author

Landed in 554ffa3.

@guybedford guybedford closed this Jun 22, 2019
guybedford added a commit that referenced this pull request Jun 22, 2019
PR-URL: #28254
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jul 2, 2019
PR-URL: #28254
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos targos mentioned this pull request Jul 2, 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.

6 participants