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

Primitaint: Inconsistent behavior in switch-cases #5

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

0drai
Copy link

@0drai 0drai commented Aug 4, 2024

While switch-cases are typically strictly checked, they are optimized for small integer constants.

This results in the following inconsistency:

switch (Number.tainted(1234567)) {
  case 1234567:
    console.log("1"); // prints 1
    break;
  default:
    console.log("0");
    break;
}
switch (Number.tainted(1)) {
  case 1:
    console.log("1");
    break;
  default:
    console.log("0"); // prints 0
    break;
}

My approach to resolving this issue (akin to af544cf) is to check for taints in the discriminant and unbox it if necessary.

@0drai 0drai changed the title Primitaint: fixed optimized switch cases with tainted discriminants Primitaint: Inconsistent behavior in switch-cases Aug 4, 2024
Copy link
Owner

@tmbrbr tmbrbr left a comment

Choose a reason for hiding this comment

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

Good catch, the fix looks good!

@tmbrbr tmbrbr merged commit 64e50a2 into tmbrbr:primitaint-merge Aug 5, 2024
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.

2 participants