Skip to content

Actually set the prototype when using a __proto__ property#4112

Merged
lukastaegert merged 2 commits into
masterfrom
gh-4094-proto-accessors
May 29, 2021
Merged

Actually set the prototype when using a __proto__ property#4112
lukastaegert merged 2 commits into
masterfrom
gh-4094-proto-accessors

Conversation

@lukastaegert

@lukastaegert lukastaegert commented May 28, 2021

Copy link
Copy Markdown
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
Resolves #4094

Description

This replaces the clunky logic that was previously used for __proto__ object literal properties by actually setting the prototype when such a property is encountered. This will immediately add support for accessors on the new prototype. There is special handling for the case where the property is the literal null. Only in this case, a prototype-free object will be created: REPL

In all other cases, the expression given is used as prototype. As far as I can see, this should only lead to unnecessary but harmless deoptimizations in cases when e.g. undefined is provided (as then all prototype property accesses should just be treated as side effects).

@github-actions

github-actions Bot commented May 28, 2021

Copy link
Copy Markdown

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-4094-proto-accessors

or load it into the REPL:
https://rollupjs.org/repl/?pr=4112

@codecov

codecov Bot commented May 28, 2021

Copy link
Copy Markdown

Codecov Report

Merging #4112 (8c4e2d0) into master (edae1ba) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4112      +/-   ##
==========================================
+ Coverage   98.08%   98.10%   +0.01%     
==========================================
  Files         201      201              
  Lines        7056     7059       +3     
  Branches     2061     2063       +2     
==========================================
+ Hits         6921     6925       +4     
  Misses         64       64              
+ Partials       71       70       -1     
Impacted Files Coverage Δ
src/ast/nodes/ObjectExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/shared/ObjectEntity.ts 94.61% <0.00%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edae1ba...8c4e2d0. Read the comment docs.

@lukastaegert lukastaegert merged commit 1dd8ba7 into master May 29, 2021
@lukastaegert lukastaegert deleted the gh-4094-proto-accessors branch May 29, 2021 04:27
@stefcameron stefcameron mentioned this pull request Jun 1, 2021
9 tasks
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.

treeshake bug: __proto__ side effects in object literals ignored

1 participant