Skip to content

Implemented Array.prototype.push() #7

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

Merged
merged 1 commit into from
May 6, 2015
Merged

Implemented Array.prototype.push() #7

merged 1 commit into from
May 6, 2015

Conversation

ILyoan
Copy link
Contributor

@ILyoan ILyoan commented Apr 29, 2015

for #3 and jerryscript-project/iotjs#9

JerryScript-DCO-1.0-Signed-off-by: Ilyong Cho ily.cho@samsung.com


ecma_object_t *obj_p = ecma_get_object_from_completion_value (completion_obj_this);

ecma_free_completion_value (completion_obj_this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Ilyong,

The call to ecma_free_completion_value would invalidate reference in obj_p.
So, it should be placed after obj_p becomes unnecessary.

Actually, for this simple case ECMA_TRY_CATCH / ECMA_FINALIZE macro are very useful.
With them it is possible to indicate scope of reference visilibity, handling exceptions at the same time.

ecma_completion_value_t ret_value;

ECMA_TRY_CATCH (obj_this_value, ecma_op_to_object (this_arg), ret_value);

// obj_this_value is accessible until corresponding ECMA_FINALIZE
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this_value);

// ...

ECMA_FINALIZE (obj_this_value);

return ret_value;

@ILyoan
Copy link
Contributor Author

ILyoan commented May 4, 2015

Hi ruben. Thank you for the review. We, here in Korea, are in vacation till 5th may for children's day. I'll check and manage this issue regarding to your opinion as soon as back to office.

@ILyoan
Copy link
Contributor Author

ILyoan commented May 6, 2015

Hi Ruben.
Long time no see.

I've amended PR following your guide.
Please take a look at it for review.

const ecma_value_t *argument_list_p, /**< arguments list */
ecma_length_t arguments_number) /**< number of arguments */
{
JERRY_ASSERT (&argument_list_p != NULL && arguments_number > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ilyong.

Couldn't the procedure receive arguments_list_p == NULL && arguments_number == 0?
Also, "&arguments_list_p" is always non-NULL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this assert if the js developer calls the method with zero arguments?
example:

var a = [];
a.push();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would assert. It is exactly the case, mentioned in the comment above.

@ILyoan
Copy link
Contributor Author

ILyoan commented May 6, 2015

Hi Ruben.
Thank you for review.

I've changed this PR once more.
The assert was my fault :(

Please give review again.

ret_value = ecma_make_normal_completion_value (num_length_value);

ECMA_FINALIZE (op_ret_value);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a point that I didn't notice during previous review.

If the [[Put]] threw an exception, and, so, ret_value = ecma_make_normal_completion_value (num_length_value); was not executed, num_length should be deallocated after the try-finalize block for [[Put]].

Could you, please, add call to ecma_dealloc_number?
Could you also, please, add "_p" suffix to num_length, like for other pointer variables?

  if (ecma_is_completion_value_empty (ret_value))
  {
    ecma_number_t *num_length_p = ecma_alloc_number ();
    *num_length_p = ecma_uint32_to_number (n);

    ecma_completion_value_t completion = ecma_op_object_put (obj_p,
                                                             length_str_p,
                                                             ecma_make_number_value (num_length_p),
                                                             true);

    if (unlikely (ecma_is_completion_value_throw (completion)
                  || ecma_is_completion_value_exit (completion)))
    {
      ret_value = completion;

      ecma_dealloc_number (num_length_p);
    }
    else
    {
      JERRY_ASSERT (ecma_is_completion_value_normal (completion));
      ecma_free_completion_value (completion);

      ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_length_p));
    }
  }

After adding deallocation, the changes would be ok to merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. you're right.
You have shape eyes.
I'll fix it right now and renew the PR.

JerryScript-DCO-1.0-Signed-off-by: Ilyong Cho ily.cho@samsung.com
@ILyoan
Copy link
Contributor Author

ILyoan commented May 6, 2015

@ruben-ayrapetyan
Changed Again.
Hopefully last review please?

@ruben-ayrapetyan ruben-ayrapetyan merged commit 8276255 into jerryscript-project:master May 6, 2015
@ruben-ayrapetyan
Copy link
Contributor

Hi Ilyong.

Thank you.

Changes were merged successfully.

@ILyoan
Copy link
Contributor Author

ILyoan commented May 6, 2015

@ruben-ayrapetyan
Thank you for the review.

By the way, I have a question.
How did you merge PR without making extra merge commit?
Did you merge it manually not pushing the button?

@ruben-ayrapetyan
Copy link
Contributor

@ILyoan
Yes, I've manually merged changes in fast-forward mode.
After merging, I've started make push (precommit testing + push), that pushed changes.
GitHub automatically detected that commit from pull request appeared in master branch,
and marked the pull request as merged.

@ILyoan
Copy link
Contributor Author

ILyoan commented May 6, 2015

@ruben-ayrapetyan
Good information!
I think IoT.js should merge commits in similar way.

matedabis pushed a commit to matedabis/jerryscript that referenced this pull request Jan 30, 2019
Added new test cases to array-prototype-concat.js to improve branch coverage.
Branch coverage:

    before: 10/14
    after: 13/14

JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi repasics@inf.u-szeged.hu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants