Skip to content

fix: do not make __proto__ setters computed - #18602

Merged
JLHwung merged 2 commits into
mainfrom
jlhwung/fix-duplicate-keys-proto-setter
Nov 17, 2026
Merged

JLHwung merged 2 commits into
mainfrom
jlhwung/fix-duplicate-keys-proto-setter

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 12, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? See below
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? No
License MIT

{ __proto__() {}, __proto__: p } is not a duplicate: the second property sets the prototype and does not define a property.

Previously the second property was rewritten to ["__proto__"]: p, which defines an own property named "proto" and leaves the prototype untouched.

Assisted-by: Claude Fable 5.2

@JLHwung
JLHwung added this pull request to stack #18587 November 12, 2026 02:09
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Nov 12, 2026
@babel-bot

babel-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63387

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 0ead329

@JLHwung
JLHwung force-pushed the jlhwung/fix-duplicate-keys-proto-setter branch from 53e7f05 to 11df694 Compare November 12, 2026 02:25

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test with a duplicate proto setter? Do old browsers for which this plugin is needed have problems with that?

@JLHwung

JLHwung commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Can you add a test with a duplicate proto setter?
duplicate-proto-setter (({ __proto__: p, __proto__: q })) is already a parser error, so the plugin would not handle such AST.

Do old browsers for which this plugin is needed have problems with that?

Goode question. Old browsers, such as V8 3.14 and 3.28, used by Node.js 0.10 and 0.12 respectively, counts __proto__: p as a data property, so ({ get __proto__() {}, __proto__: p }) throws a syntax error in both strict and sloppy mode on those engines. Before this PR, we generate

({
  get __proto__() {},
  ["__proto__"]: p
})

which does not throw but changed the semantics. Currently, we keep the input as-is, semantics is correct but the old engines would not support it. I will push a new commit and make the other __proto__ members computed:

({
  get ["__proto__"]() {},
  __proto__: p
})

so the output should work on older engines.

Aside: we should revive another PR that allows us to run exec tests on older engines, such as Node.js 0.10 and 0.12.

@JLHwung
JLHwung force-pushed the jlhwung/fix-duplicate-keys-proto-setter branch 2 times, most recently from 2c86018 to 5c54b80 Compare November 16, 2026 21:25
Base automatically changed from jlhwung/fix-export-namespace-from-attributes to main November 17, 2026 12:13
`{ __proto__() {}, __proto__: p }` is not a duplicate: the second property sets the prototype and does not define a property.

Previously the second property was rewritten to `["__proto__"]: p`, which defines an own property named "__proto__" and leaves the prototype untouched.

Assisted-by: Claude Fable 5.2
…a proto setter

ES5 engines count `__proto__: value` as a data property named "__proto__"
in the duplicate property checks, so `{ get __proto__() {}, __proto__: p }`
is a SyntaxError there even in sloppy mode (tested on V8 3.14 and 3.28).

When an object literal has a `__proto__: value` property, every other
non-computed property named "__proto__" is now made computed, whatever
the order, so that the proto setter keeps setting the prototype.

Assisted-by: Claude Opus 5.5
@nicolo-ribaudo
nicolo-ribaudo force-pushed the jlhwung/fix-duplicate-keys-proto-setter branch from 5c54b80 to 0ead329 Compare November 17, 2026 12:13
@JLHwung
JLHwung added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 985597b Nov 17, 2026
40 checks passed
@JLHwung
JLHwung deleted the jlhwung/fix-duplicate-keys-proto-setter branch November 17, 2026 14:54
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18646.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants