-
Notifications
You must be signed in to change notification settings - Fork 683
Implement Date.prototype.toString #336
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 Date.prototype.toString #336
Conversation
*/ | ||
static void | ||
date_insert_leading_zeros (ecma_string_t **str_p, /**< input/output string */ | ||
ecma_number_t num, /**< input 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.
Broken formatting
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.
Also, prefix should be ecma_date_
.
65c6ee3
to
cfb64fa
Compare
* Insert leading zeros to a string of a number if needed. | ||
*/ | ||
static void | ||
ecma_date_insert_leading_zeros (ecma_string_t **str_p, /**< input/output string */ |
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.
@ruben-ayrapetyan why ecma_date_
shouldn't it be ecma_builtin_date_
?
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.
I think ecma_builtin_date_
will be too long for a prefix and we used ecma_date_
for helpers in ecma-builtin-date.cpp
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.
I'm asking because neighbour function is named with ecma_builtin_date_
: https://github.com/Samsung/jerryscript/pull/336/files#diff-4c3f6b953c0f51c11d2a079e9dcc10f8R103
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.
@egavrin, I know, but those two functions are not builtins, only helpers.
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.
@egavrin, I think that you are right. Following current naming style, the prefix should be even ecma_builtin_date_prototype_helper_
. But this prefix is too long. So, probably, naming scheme for built-in helpers should be somehow updated. I'm not sure how exactly. But at least, ecma_date_
, of course, should be added.
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.
Let's leave as is ^_^
Good to me |
*str_p = concat_p; | ||
} | ||
|
||
} /* insert_leading_zeros */ |
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.
Incorrect comment
cfb64fa
to
7d57c2c
Compare
lgtm |
{ | ||
div /= 10; | ||
|
||
ecma_string_t *zero_str_p = ecma_new_ecma_string_from_number (ECMA_NUMBER_ZERO); |
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.
ecma_new_ecma_string_from_uint32 would be better in the case, as no additional pools chunk would be allocated for floating point value.
7d57c2c
to
0d865aa
Compare
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
0d865aa
to
9b24d8f
Compare
JERRY_ASSERT (length >= 1); | ||
|
||
/* If the length is bigger than the number of digits in num, then insert leding zeros. */ | ||
for (uint32_t i = length - 1; i > 0 && num < pow (10,i); i--) |
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.
Why do we need to perform pow
on every iteration? It is unnecessarily resource consuming.
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.
What do you suggest instead?
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.
The following is not the best solution, and can be improved, but pow
is calculated only once in the version:
uint32_t first_index = length - 1u;
ecma_number_t power_i = (ecma_number_t) pow (10, first_index);
for (uint32_t i = first_index; i > 0 && num < power_i; i--, power_i /= 10)
{
ecma_string_t *zero_str_p = ecma_new_ecma_string_from_uint32 (0);
ecma_string_t *concat_p = ecma_concat_ecma_strings (zero_str_p, *str_p);
ecma_deref_ecma_string (zero_str_p);
ecma_deref_ecma_string (*str_p);
*str_p = concat_p;
}
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.
Thanks, I'll do it. Is it good for you if I add this change to #360?
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.
It is better to open separate pull requests for unrelated changes.
If the change involves code, updated in the #360, it would be ok, if you would place the change into a separate commit of the pull request.
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.
It is also using these two helper functions.
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.
Ok.
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com