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

Number constants #420

Merged
merged 16 commits into from
May 26, 2020
Merged

Number constants #420

merged 16 commits into from
May 26, 2020

Conversation

Lan2u
Copy link

@Lan2u Lan2u commented May 25, 2020

This Pull Request fixes #414 .

It changes the following:

  • Adds Number builtin constants of EPSILON, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, MAX_VALUE, MIN_VALUE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NAN.

The constant NaN is expressed currently as NAN because using the lowercase a was causing the parser to interpret it as an identifier not a constant.

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

This looks good! Check my comments to see on how we can improve it :)

boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/number/mod.rs Outdated Show resolved Hide resolved
@Lan2u
Copy link
Author

Lan2u commented May 25, 2020

This looks good! Check my comments to see on how we can improve it :)

Thanks for the help, changes made :)

With regards to Number.NaN vs Number.NAN is this something which should be looked at as part of this or separately? (unless I've made a mistake of course).

@HalidOdat
Copy link
Member

HalidOdat commented May 25, 2020

With regards to Number.NaN vs Number.NAN is this something which should be looked at as part of this or separately? (unless I've made a mistake of course).

About this, it should be treated separately, it would require changes to the lexer and parser. For now you can comment it out and add a TODO with an explanation.

@HalidOdat HalidOdat added builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request labels May 25, 2020
@HalidOdat HalidOdat added this to the v0.9.0 milestone May 25, 2020
Comment on lines 422 to 424
// Constants from:
// Draft ECMA-262 / May 22, 2020 ECMAScript® 2021 Language Specification
// Section 20.1.2 Properties of the Number Constructor
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this for a link?

Copy link
Author

Choose a reason for hiding this comment

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

Removed section and added link

number.set_field("POSITIVE_INFINITY", Value::from(f64::INFINITY));

// TODO: Currently parsing/lexing Number.NaN is not supported due to the inclusion of the lower case 'a'.
// number.set_field("NaN", Value::from(f64::NAN));
Copy link
Member

@Razican Razican May 26, 2020

Choose a reason for hiding this comment

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

I would still add this here, so that when we fix the lexer this will just work. What do you think, @HalidOdat?

Copy link
Member

@HalidOdat HalidOdat May 26, 2020

Choose a reason for hiding this comment

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

I would still add this here, so that when we fix the lexer this will just work. What do you think, @HalidOdat?

Yep. We could add it! That's probably the best option.

Edit: we might be able to access it with Number["NaN"]

Copy link
Author

Choose a reason for hiding this comment

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

Will add it back :)

Copy link
Member

Choose a reason for hiding this comment

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

I created #421 related to this.

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

This is good to go for me, thanks for the work!

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

Looks good to me too :)

@HalidOdat HalidOdat merged commit d837e04 into boa-dev:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Number object constants
3 participants