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

Abnormal phenomenon #30

Open
XiSenao opened this issue Nov 29, 2024 · 1 comment
Open

Abnormal phenomenon #30

XiSenao opened this issue Nov 29, 2024 · 1 comment

Comments

@XiSenao
Copy link

XiSenao commented Nov 29, 2024

Input:

function Main() {
  const p = {};
  p.__proto__ = p.__proto__ || {};
  p.__proto__.a = 124;
  const m = Math.random(10);
  return m;
}


Main();

console.log(window.a);

Expected Output:

Include all statements.

Actual Output:

It seems that objects created by literals do not have a prototype chain, and references to global objects are automatically retained.

function Main() {
  const __unused_4577 = Math.random(10);
  return;
}
Main();
console.log(window.a);
@KermanX
Copy link
Owner

KermanX commented Nov 30, 2024

There are two separate problems:

  1. Math.random() not considered as pure yet. This will be solved in the future.
  2. Prototype pollution. IMO, the expected behavior should be:
function effect1(key, value) {
  ({})[key]?.x = value
}

({}).__proto__.x     // Preserved
effect("__proto__")  // Preserved
effect("" + unknown) // Although `unknown` is possible to be "__proto__", still remove it

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

No branches or pull requests

2 participants