Skip to content

Merge jerry_get_value_without_error and jerry_value_clear_error_flag #2350

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

Conversation

imiklos
Copy link
Contributor

@imiklos imiklos commented May 22, 2018

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos [email protected]

Get the value from an error.

Extract the api value from an error. If the second argument is true
it will release the the input error value.
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary the.

* Get the value from an error value.
*
* Extract the api value from an error. If the second argument is true
* it will release the the input error value.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@imiklos imiklos force-pushed the jerry_get_value_from_error branch from 1a22ad7 to baaa4ac Compare May 22, 2018 10:48
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

Good patch. Few more changes.

void
jerry_value_clear_error_flag (jerry_value_t *value_p) /**< api value */
jerry_value_t jerry_get_value_from_error (jerry_value_t value, /**< api value */
bool release) /**< release value */
Copy link
Member

Choose a reason for hiding this comment

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

comment: release api value


TEST_ASSERT (jerry_get_error_type (error_obj) == errors[idx]);

jerry_release_value (error_obj);

Copy link
Member

Choose a reason for hiding this comment

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

Remove this newline.

@@ -27,10 +27,12 @@ main (void)
jerry_value_set_error_flag (&obj_val);
jerry_value_t err_val = jerry_acquire_value (obj_val);

jerry_value_clear_error_flag (&obj_val);
jerry_release_value (obj_val);
obj_val = jerry_get_value_from_error (obj_val, true);
Copy link
Member

Choose a reason for hiding this comment

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

I think the obj_val should be err_val in jerry_get_value_from_error (obj_val, true);,

jerry_release_value (err_val);
jerry_release_value (obj_val);

Copy link
Member

Choose a reason for hiding this comment

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

Remove this newline.

@imiklos imiklos force-pushed the jerry_get_value_from_error branch from baaa4ac to df50c20 Compare May 22, 2018 13:43
@imiklos
Copy link
Contributor Author

imiklos commented May 22, 2018

Thank you for the reviews, I updated the PR with these changes.

Get the value from an error.

Extract the api value from an error. If the second argument is true
it will release the input error value.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this won't be enough information for a new developer who is not familiar with JerryScript. Furthermore the example must show the two different use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion:

Many API functions cannot be called with an error value. This function extracts the API value from an error. The second argument defines whether the input error value must be released or not. If it is set to `true`, then a [`jerry_release_value`](#jerry_release_value) function will be called for the first argument, so the error value won't be available after the call of `jerry_get_value_from_error`. The second argument should be false if both error and its represented value are needed. The first argument is returned unchanged if it is not an error.

```

- `value_p` - pointer to an api value
Copy link
Contributor

Choose a reason for hiding this comment

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

  • value - error (api) value
  • release - defines whether input api value must be released

Get the value from an error.

Extract the api value from an error. If the second argument is true
it will release the input error value.
Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion:

Many API functions cannot be called with an error value. This function extracts the API value from an error. The second argument defines whether the input error value must be released or not. If it is set to `true`, then a [`jerry_release_value`](#jerry_release_value) function will be called for the first argument, so the error value won't be available after the call of `jerry_get_value_from_error`. The second argument should be false if both error and its represented value are needed. The first argument is returned unchanged if it is not an error.

*/
void
jerry_value_clear_error_flag (jerry_value_t *value_p) /**< api value */
jerry_value_t jerry_get_value_from_error (jerry_value_t value, /**< api value */
Copy link
Contributor

Choose a reason for hiding this comment

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

return value must be on separate line:

jerry_value_t
jerry_get_value_from_error (jerry_value_t value, /**< api value */

```

- `value_p` - pointer to an api value

**Example**

```c
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an example for a not release error too.

@imiklos imiklos force-pushed the jerry_get_value_from_error branch from df50c20 to 359d25f Compare May 24, 2018 08:31
@LaszloLango LaszloLango added this to the Release 2.0 milestone May 24, 2018
@LaszloLango
Copy link
Contributor

Related issue #2213

@imiklos
Copy link
Contributor Author

imiklos commented May 24, 2018

I updated the PR. Thanks for the reviews.

Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

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

One minor deficiency, good to me after that.


jerry_value_set_error_flag (&error);
jerry_value_t value = jerry_get_value_from_error (error, false);

Copy link
Contributor

Choose a reason for hiding this comment

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

... // both 'error' and 'value' can be used and must be released when they are no longer needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated the PR.

…functions

JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos [email protected]
@imiklos imiklos force-pushed the jerry_get_value_from_error branch from 359d25f to 880ee70 Compare May 24, 2018 10:13
Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants