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

fix: compatibility with Secure EcmaScript #914

Closed
wants to merge 3 commits into from
Closed

fix: compatibility with Secure EcmaScript #914

wants to merge 3 commits into from

Conversation

Jack-Works
Copy link

I fixed it by replacing Draft{Map, Set}.prototype.method = to Object.defineProperty(...)

@netlify
Copy link

netlify bot commented Mar 2, 2022

✔️ Deploy Preview for quizzical-lovelace-dcbd6a canceled.

🔨 Explore the source changes: f4a3964

🔍 Inspect the deploy log: https://app.netlify.com/sites/quizzical-lovelace-dcbd6a/deploys/622431e9317aa40007288174

@Jack-Works
Copy link
Author

using https://github.com/immerjs/immer/pull/914/files?diff=unified&w=1 hide white space will make this PR easier to review.

@mweststrate
Copy link
Collaborator

thanks! looks ok in general, but could you elaborate a bit more what problem with secure EcmaScript this solves? (Or what that is). Also it might be a bit cleaner to convert it to single Object.defineProperties calls?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1920713780

  • 115 of 115 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.553%

Totals Coverage Status
Change from base Build 1774254151: 0.0%
Covered Lines: 786
Relevant Lines: 794

💛 - Coveralls

@Jack-Works
Copy link
Author

Thanks for the reply. I have written a description about why this fix can resolve the problem, see MikeMcl/decimal.js-light#20 (comment)

I will do the changes you requested tomorrow.

@Jack-Works
Copy link
Author

@mweststrate hi! can you review this again? thanks!

@mweststrate
Copy link
Collaborator

@Jack-Works I checked the proposal, but it is still in stage 1 and looks largely inactive for the last 2 years, so I don't see a reason to provide all other users with a slower and slightly less straightforward implementation atm? Typically only at stage 3 it becomes interesting for popular libs like immer to get involved.

@Jack-Works
Copy link
Author

I don't think defineProperty will be slow... I think the Proxy is more serve than defineProperty. If immer can merge this, we can get rid of patch-package to modify node_modules...

@mweststrate
Copy link
Collaborator

mweststrate commented Apr 4, 2022

patch-package is the perfect solution for cases like this. one-off, innocent looking changes for a single user has too many times come back to ruin the day later somewhere down the road for me in the past. Landing this PR would basically mean committing to not change any built-in objects with a prototype in the future, which is quite a blanket cheque. So saving the inconvenience of patch-package in an exotic setup is not a strong enough argument for a package that is used this widely imho.

@Jack-Works
Copy link
Author

strange... it's working in node --frozen-intrinsics, so it should also works in SES lockdown()

image

@erights
Copy link

erights commented Jan 8, 2023

Please look again and consider reopening. The code in the proposed changes is simply better code than the code it replaces. The original code already uses a defineProperty for the size property as it must, since this is an accessor property. But even this points out why defineProperty/defineProperties is the right level of abstraction for overriding inherited properties. Property assignment is not a workable way to express property override --- both because the inherited property may be an accessor (like size) or because the inherited property may not be writable (for example, if the prototype has been frozen). For all these reasons, the class abstraction mechanism, introduced in EcmaScript 6, realizes the semantics of overriding inherited properties with defineProperty/defineProperties semantics rather than assign semantics.

The situation of frozen prototypes is not obscure, and changing code to live better with them is not an obscure improvement. This affects

  • Hardened JavaScript, aka SES
  • Node --frozen-intrinsics as noted above
  • Compat with TC53 standard for JavaScript for embedded
  • Moddable XS engine, which implements the TC53 standard.

Landing this PR would basically mean committing to not change any built-in objects with a prototype in the future, which is quite a blanket cheque.

I do not understand this argument. By accepting this PR, you'd only be removing an incompatibility with frozen prototypes. This is no more a commitment to frozen prototypes than is any other code that is already compatible with frozen prototypes.

@erights
Copy link

erights commented Jan 8, 2023

strange... it's working in node --frozen-intrinsics, so it should also works in SES lockdown()

@Jack-Works yes, that does seem strange! Do you understand why it does seem to work with node --frozen-intrinsics without your patch, but does not seem to work in SES / Hardened JS?

@Jack-Works
Copy link
Author

@erights immer v10 is now compatible with ses.

@erights
Copy link

erights commented Apr 19, 2023

OMG thanks!

@erights
Copy link

erights commented Apr 19, 2023

Any clarification of the previous mysteries? Just curious.

@Jack-Works
Copy link
Author

Any clarification of the previous mysteries? Just curious.

no idea, haven't inspected that since then

@mweststrate
Copy link
Collaborator

mweststrate commented Apr 19, 2023 via email

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.

None yet

4 participants