Skip to content

avoid to change when meet __proto__ #956

Open

Description

@LongTengDao

Bug report or Feature request? Bug report

Version (complete output of terser -V or specific git commit) 5.6.0

Complete CLI command or minify() options used

terser input

// sample 1:
const o = {};
o.p = 1;
o.__proto__ = { set q (v) {} };
o.q = 2;
console.log(o);

// sample 2:
const x = { __proto__: { set p (v) {} } };
x.p = 1;
console.log(x);

terser output or error

// sample 1:
const o = { p: 1, __proto__: { set q (v) {} }, q: 2 };
console.log(o);

// sample 2:
const x = { __proto__: { set p (v) {} }, p: 1 };
console.log(x);

Expected result

// sample 1:
const o = { p: 1 };
o.__proto__ = { set q (v) {} };
o.q = 2;
console.log(o);

// sample 2:
const x = { __proto__: { set p (v) {} } };
x.p = 1;
console.log(x);

Activity

  1. fabiosantoscode commented on Apr 3, 2021

    @fabiosantoscode
    Collaborator

    Hey there! I can't reproduce sample 1. What were the options you used?

  2. LongTengDao commented on Apr 4, 2021

    @LongTengDao
    ContributorAuthor

    I used default options, so I didn't write it in the issue.
    It's strange, because when I test, the sample 1 happens... And now it not happen...
    Let's ignore sample 1, until I figure out why...

  3. evanw commented on Apr 22, 2021

    @evanw

    I'm currently working through this for esbuild in evanw/esbuild#1166. I believe you can set missing properties to undefined when __proto__: null is present (so {__proto__: null}.a is always undefined) but not with ['__proto__']: null. You also need to be careful to preserve {__proto__: null}.__proto__ === undefined. JS is so messy.

  4. fabiosantoscode commented on Apr 23, 2021

    @fabiosantoscode
    Collaborator

    Thanks for the input @evanw. I've read through this esbuild issue (it mentioned #980) for more insight. I don't know how widespread __proto__: null is though, so I don't know if it's worth the extra complexity. Maybe it's more worth it to optimize Map and Set (maybe an unsafe_collections option), since their behaviour is way more linear!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions