-
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
Implemented Array.prototype.pop(). #22
Implemented Array.prototype.pop(). #22
Conversation
{ | ||
/* 5.c */ | ||
ECMA_TRY_CATCH (del_value, ecma_op_object_delete (obj_p, index_str, true), ret_value); | ||
ECMA_FINALIZE (del_value); |
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.
Hi Dániel.
index_str
used in the line, was freed with ecma_deref_ecma_string
.
The ECMA_TRY_CATCH
would overwrite ret_value
upon exception.
Generally, ret_value
should be written only once - with value that would be actually returned from a procedure.
Could you, please, add "_p" suffix to index_str
like for other pointer variables?
Hi Ruben! I fixed the issues you mentioned and updated the commit. |
ecma_make_number_value (len_p), | ||
true), | ||
ret_value); | ||
ECMA_FINALIZE (put_value); |
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.
Hi Dániel.
The ECMA_TRY_CATCH
, upon exception, would overwrite ret_value
without freeing it, and, so, causing memory leak.
We've recently introduced assertion check for similar cases (May 8, b05d239).
So, in future, precommit testing would check for the issues.
We could move code, writing length property, to a separate function, returning ecma_completion_value_t
('normal undefined' if no exception was thrown, and 'throw completion' - otherwise).
So, we could call it with ECMA_TRY_CATCH
in if
and else
blocks.
if (len > 0)
+ {
+ len--;
+ /* 5.a */
+ ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (len);
+
+ /* 5.b */
+ ECMA_TRY_CATCH (get_value, ecma_op_object_get (obj_p, index_str_p), ret_value);
+
+ /* 5.c */
+ ECMA_TRY_CATCH (del_value, ecma_op_object_delete (obj_p, index_str_p, true), ret_value);
+ ECMA_TRY_CATCH (set_length_value,
+ ecma_builtin_array_prototype_helper_set_length (obj_p, len),
+ ret_value);
+ ret_value = ecma_make_normal_completion_value (ecma_copy_value (get_value, true));
+ ECMA_FINALIZE (set_length_value);
+ ECMA_FINALIZE (del_value);
+
+ ECMA_FINALIZE (get_value)
+
+ ecma_deref_ecma_string (index_str_p);
+ }
Hi Ruben! I've updated the commit as you suggested. Please take a look. |
I've made a slight change, I believe it's better this way. |
|
||
try { | ||
obj.pop(); | ||
} catch (e) { |
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.
If the .pop does not throw the error, then there will be no assert check and we'll assume that everything is ok. We should add an assert (false);
after the .pop call to detect that there should have been an exception.
I've updated the test to make sure an exception was thrown by pop, when that's the expected behavior. |
Hello, Dániel. It's great, currently the changes seem to be semantically correct. Now, we can proceed to style questions:
Following the list above, I updated your patch. Please, compare the two versions, considering updated version as supplement to the guideline, and try to follow the style for this and subsequent patches.
|
Hello, @ruben-ayrapetyan Regarding the ECMA_TRY_CATCH macro usage: I think that it clutters the code in more complex situations. Like if there is a for iteration in the code (just like in the join method), then to correctly free everything with the ECMA_FINALIZE, the developer needs to add a break into the for, and extra checks outside of it to ensure the for loop ran fine. Also having early returns with the Additional note: |
Hi Ruben! I've updated the patch based on what you supplied, and will revisit my other patches as well. |
Hello, @galpeter I agree that As for Specifically, the
|
@dbatyai , Also, cppcheck warnings that initialization of From other view points, your patch seems to be ready for merge. Please, fix cppcheck's warning, add the comments, make sure that precommit passes successfully ( |
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
@ruben-ayrapetyan, |
…iments-dev Move registers allocation to parser.cpp (first stage) and temporary turn of evaluation of Identifier in squares (to be fixed later)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]