-
Notifications
You must be signed in to change notification settings - Fork 676
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
Implement String.prototype.charCodeAt() #352
Implement String.prototype.charCodeAt() #352
Conversation
ecma_string_t *original_string_p = ecma_get_string_from_value (to_string_val); | ||
const ecma_length_t len = ecma_string_get_length (original_string_p); | ||
|
||
ecma_number_t * ret_num = ecma_alloc_number (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*ret_num_p
Good to me |
d251525
to
c19989e
Compare
Thanks, the patch is updated. |
ecma_string_t *original_string_p = ecma_get_string_from_value (to_string_val); | ||
const ecma_length_t len = ecma_string_get_length (original_string_p); | ||
|
||
ecma_number_t * ret_num_p = ecma_alloc_number (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the space after the *
c19989e
to
ae86c39
Compare
|
||
// check coercible - undefined | ||
try { | ||
assert(true.charCodeAt()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This testcase will not invoke the charCodeAt
at all. I think you wanted to write: String.prototype.charCodeAt.call(true)
cb1d234
to
5b7a0c6
Compare
LGTM |
else | ||
{ | ||
/* 6 */ | ||
ecma_char_t new_ecma_char = ecma_string_get_char_at_pos (original_string_p, ecma_number_to_uint32 (index_num)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While actual length of strings, currently, can't exceed uint32_t
range, value of index_num
can be bigger. ToInteger
is not equivalent to ToUInt32
, as ToUInt32
performs "modulo 2^32" operation on its argument, and ToInteger
performs floor
.
The code would work correctly, as index_num
doesn't exceed len
, as checked above.
Could you, please, add an assertion that ecma_number_to_uint32 (index_num) == ecma_number_trunc (index_num)
and add comment, describing why ToInteger
and ToUInt32
are equivalent in the case?
5b7a0c6
to
61a6e93
Compare
@ruben-ayrapetyan thanks for the comments, the patch is updated |
@lvidacs, thank you for update. |
@lvidacs, after fixing #352 (comment) the changes would look good to me |
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]
61a6e93
to
c7a47c1
Compare
Looks good to me |
|
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]