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

Storten Number and Infinity constants #340

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Storten Number and Infinity constants #340

wants to merge 7 commits into from

Conversation

FarSeeing
Copy link

Add unsafe shortcuts for Number constants (idea taken from #262).

Number.POSITIVE_INFINITY and Infinity to 1/0,
Number.NEGATIVE_INFINITY and -Infinity to -1/0,
Number.NaN to NaN

Transformations are only made if the are no Infinity or NaN in scope, but still there is a curios thing:
using them as array index/property name also gets affected. It (possibly) can lead to a problem, but current browsers handle it correctly:

>>> x = {Infinity: 3}
Object { Infinity=3}
>>> x[Infinity]
3
>>> x[1/0]
3

@RGustBardon
Copy link
Contributor

When it comes to evaluating the production MemberExpression : MemberExpression [ Expression ], this is to be expected. Relevant steps are as follows:

  1. “Division of a nonzero finite value by a zero results in a signed infinity.” (11.5.2).
  2. “Let propertyNameReference be the result of evaluating Expression.” (11.2.1).
  3. “Let propertyNameValue be GetValue(propertyNameReference).” (11.2.1).
  4. “If Type(V) is not Reference, return V.” (8.7.1)
  5. “Let propertyNameString be ToString(propertyNameValue).” (11.2.1).
  6. “If m is infinity, return the String "Infinity".” (9.8.1).

Would it not be more consequent to replace Number.NaN with 0/0 instead of NaN?

@FarSeeing
Copy link
Author

Thanks for the explanation.

Also, 0/0 for Number.NaN seems good, made it.

@@ -44,6 +44,37 @@ function ast_squeeze_more(ast) {
}
}
},

// shorten Number constants:
// Number.POSITIVE_INFINITY to 1/0, Number.NEGATIVE_INFINITY to -1/0, Number.NaN to NaN
Copy link
Contributor

Choose a reason for hiding this comment

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

Number.NaN to 0/0

@RGustBardon
Copy link
Contributor

As suggested in #262, should this transformation be applied, it could be more useful to transform -Infinity into 1/-0 instead of -1/0 (cf. #411).

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