Skip to content

Conversation

@croraf
Copy link
Contributor

@croraf croraf commented Jun 10, 2020

@codecov
Copy link

codecov bot commented Jun 10, 2020

Codecov Report

Merging #475 into master will decrease coverage by 0.00%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #475      +/-   ##
==========================================
- Coverage   66.46%   66.45%   -0.01%     
==========================================
  Files         147      149       +2     
  Lines        9408     9421      +13     
==========================================
+ Hits         6253     6261       +8     
- Misses       3155     3160       +5     
Impacted Files Coverage Δ
boa/src/syntax/lexer/mod.rs 55.85% <ø> (-0.11%) ⬇️
boa/src/syntax/lexer/tests.rs 100.00% <ø> (+0.33%) ⬆️
boa/src/builtins/nan/mod.rs 66.66% <66.66%> (ø)
boa/src/builtins/array/tests.rs 100.00% <100.00%> (ø)
boa/src/builtins/mod.rs 100.00% <100.00%> (ø)
boa/src/builtins/nan/tests.rs 100.00% <100.00%> (ø)
boa/src/builtins/value/mod.rs 55.88% <0.00%> (-0.84%) ⬇️
boa/src/builtins/json/tests.rs 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 634dfb7...aca2dee. Read the comment docs.

Comment on lines 3 to 8
/// Initialise the `NaN` property on the global object.
#[inline]
pub fn init(global: &Value) {
let _timer = BoaProfiler::global().start_event("NaN", "init");
global.set_field("NaN", Value::from(f64::NAN));
}
Copy link
Member

@HalidOdat HalidOdat Jun 10, 2020

Choose a reason for hiding this comment

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

I think its best to abstract it in a NaN struct and have this static method, like we do in number/mod.rs so we don't have free functions, and then call NaN::init(global) in init function in builtins/mod.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually wen't to implement it like that at first, but seemed like bloating the code. I then checked other globals and some do it like this and some don't (50-50). Are you sure this is beneficial. Is the init of for example String or Math struct really an inherent part of the struct, or just external binding of it to the global object?

Copy link
Member

Choose a reason for hiding this comment

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

We have other global functions related with numbers like parseInt in number, so maybe it makes sense to just add this there: https://github.com/boa-dev/boa/blob/a78934d424f17bc8b9132fdb14704b61e240bd40/boa/src/builtins/number/mod.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Razican Hmm. Number should be solely for the global object Number. Also these are not even the same functions in some cases. For example (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN):

The Number.isNaN() method determines whether the passed value is NaN and its type is Number. It is a more robust version of the original, global isNaN().

But on the other hand the global NaN is the same as Number.NaN so we should reuse that logic somehow.

Copy link
Member

Choose a reason for hiding this comment

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

@Razican Hmm. Number should be solely for the global object Number.

This makes sense

Also these are not even the same functions in some cases.

I was talking about parseInt() and parseFloat(), that were recently added. Maybe we should have a "global" object initialization, and we should put all the global things in there.

Actually, we already have it, it's the global initialization function, where we call all those init functions, so we should probably add them in that outer function.

Copy link
Contributor Author

@croraf croraf Jun 11, 2020

Choose a reason for hiding this comment

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

If you ask me I would remove all these init functions as all of them are one-liners binding the objects on the provided global object.

I would just put in here "boa/src/builtins/mod.rs", something like this:

pub fn init(global: &Value) {
    global.set_field("Function", Function::new());
    global.set_field("BigInt", BigInt::new());
    ...
    // instead of
    //BigInt::init(global);
    //Function::init(global);
    // ...
}```

Copy link
Member

Choose a reason for hiding this comment

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

If you ask me I would remove all these init functions as all of them are one-liners binding the objects on the provided global object.

I would just put in here "boa/src/builtins/mod.rs", something like this:

pub fn init(global: &Value) {
    global.set_field("Function", Function::new());
    global.set_field("BigInt", BigInt::new());
    ...
    // instead of
    //BigInt::init(global);
    //Function::init(global);
    // ...
}```

Yes, I think this is a good idea. We should have an InitBuiltin trait, that could be implemented by external libraries too, that just have an init() function and return a list of <&str, Value> that we would then add to the global object, maybe in parallel (or at least they could be generated in parallel).

Copy link
Member

Choose a reason for hiding this comment

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

BTW, something similar was commented here too.

@Razican Razican added builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jun 10, 2020
@Razican Razican added this to the v0.9.0 milestone Jun 10, 2020
@Razican Razican linked an issue Jun 10, 2020 that may be closed by this pull request
@Razican
Copy link
Member

Razican commented Jun 10, 2020

We should also uncomment this test:

// TODO: uncomment when NaN support is added

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. I think the init refactoring should be done in a separate issue/PR, and after #419 gets merged.

@Razican Razican requested a review from HalidOdat June 11, 2020 16:29
@HalidOdat HalidOdat marked this pull request as ready for review June 11, 2020 16:48
@HalidOdat HalidOdat merged commit 5a45ab5 into boa-dev:master Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working builtins PRs and Issues related to builtins/intrinsics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NaN is lexed as a number, not as an identifier

3 participants