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

String() does not set length on instance #398

Closed
jasonwilliams opened this issue May 13, 2020 · 0 comments · Fixed by #404
Closed

String() does not set length on instance #398

jasonwilliams opened this issue May 13, 2020 · 0 comments · Fixed by #404
Labels
bug Something isn't working E-Easy Easy good first issue Good for newcomers
Milestone

Comments

@jasonwilliams
Copy link
Member

jasonwilliams commented May 13, 2020

Describe the bug
Calling new String('some text') does not set the instance

E.g

let a = new String("1234");
a.length;

Should return 4

To Reproduce
Put the above into a test.js file and run it, you should get 0

Expected behavior
it should return 4

Implementation is here:
Master: https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/string/mod.rs#L31-L49

The string passed in lives at args.get(0), you can call len() then convert it back into a JSValue by calling to_value() on it.
There's an example commented out here:
https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/string/mod.rs#L36-L37

 let a: String = from_value(args.get(0).expect("failed to get argument for String method").clone()).unwrap();
 this.set_field_slice("length", to_value(a.len() as i32));
@jasonwilliams jasonwilliams added bug Something isn't working good first issue Good for newcomers E-Easy Easy labels May 13, 2020
@Razican Razican added this to the v0.8.0 milestone May 26, 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 E-Easy Easy good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants