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

TypeError when to_object is passed null or undefined #518

Merged
merged 8 commits into from
Jun 23, 2020
Merged

TypeError when to_object is passed null or undefined #518

merged 8 commits into from
Jun 23, 2020

Conversation

zanayr
Copy link
Contributor

@zanayr zanayr commented Jun 22, 2020

This Pull Request fixes/closes #483.

It changes the following:

  • Changed the to_object implementation to throw a TypeError when passed an undefined or null value.

Best,

@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #518 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #518      +/-   ##
==========================================
+ Coverage   68.06%   68.09%   +0.02%     
==========================================
  Files         169      169              
  Lines        9918     9925       +7     
==========================================
+ Hits         6751     6758       +7     
  Misses       3167     3167              
Impacted Files Coverage Δ
boa/src/exec/mod.rs 66.91% <100.00%> (+0.12%) ⬆️
boa/src/exec/tests.rs 100.00% <100.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 8f8498e...1607588. Read the comment docs.

@zanayr
Copy link
Contributor Author

zanayr commented Jun 22, 2020

I think I did this correctly, not sure why I'm getting a large red rectangle and it failed that check. Not finding any useful information..

Please let me know if there is something i need to change/fix.

Best,

@Razican
Copy link
Member

Razican commented Jun 22, 2020

I think I did this correctly, not sure why I'm getting a large red rectangle and it failed that check. Not finding any useful information..

Please let me know if there is something i need to change/fix.

Best,

This check is related to the test coverage of the code. We should add a test that checks that this works as expected.

@Razican Razican added the execution Issues or PRs related to code execution label Jun 22, 2020
@zanayr
Copy link
Contributor Author

zanayr commented Jun 22, 2020

Ok! I will fix that tonight.

@zanayr
Copy link
Contributor Author

zanayr commented Jun 23, 2020

@Razican I didn't find an existing to_object test, so I worte this test:

#[test]
fn to_object() {
    let realm = Realm::create();
    let mut engine = Interpreter::new(realm);
    
    assert!(engine.to_object(&Value::undefined()).is_err());
    assert!(engine.to_object(&Value::null()).is_err());
}

My only question is where to put it? in the test.rs file in the src/exec directory?

@HalidOdat
Copy link
Member

HalidOdat commented Jun 23, 2020

My only question is where to put it? in the test.rs file in the src/exec directory?

Yes. that is the best place.

For the test I think it's best if we test that it's an Object rather than a thrown Value, because the previous test will pass before the fix too, since we were throwing undefined

#[test]
fn to_object() {
    let realm = Realm::create();
    let mut engine = Interpreter::new(realm);
    
    assert!(engine.to_object(&Value::undefined()).unwrap_err().is_object());
    assert!(engine.to_object(&Value::null()).unwrap_err().is_object());
}

@HalidOdat HalidOdat added the bug Something isn't working label Jun 23, 2020
@HalidOdat HalidOdat added this to the v0.9.0 milestone Jun 23, 2020
@zanayr
Copy link
Contributor Author

zanayr commented Jun 23, 2020

I think i messed something up... 😅
There was a conflict and I thought I resolved it... but it seems I made things worse.

boa/src/exec/mod.rs Outdated Show resolved Hide resolved
@HalidOdat HalidOdat merged commit 24418e7 into boa-dev:master Jun 23, 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 execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ToObject (to_object) should throw TypeError when there is null and undefined
3 participants