-
Notifications
You must be signed in to change notification settings - Fork 687
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
Merge jerry_get_value_without_error and jerry_value_clear_error_flag #2350
Conversation
docs/02.API-REFERENCE.md
Outdated
| 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. |
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.
Unnecessary the.
jerry-core/api/jerry.c
Outdated
| * 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. |
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.
Ditto.
1a22ad7 to
baaa4ac
Compare
zherczeg
left a comment
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.
Good patch. Few more changes.
jerry-core/api/jerry.c
Outdated
| 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 */ |
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.
comment: release api value
tests/unit-core/test-api-errortype.c
Outdated
| TEST_ASSERT (jerry_get_error_type (error_obj) == errors[idx]); | ||
|
|
||
| jerry_release_value (error_obj); | ||
|
|
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.
Remove this newline.
|
|
||
| jerry_value_clear_error_flag (&obj_val); | ||
| jerry_release_value (obj_val); | ||
| obj_val = jerry_get_value_from_error (obj_val, true); |
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 the obj_val should be err_val in jerry_get_value_from_error (obj_val, true);,
| JERRY_ASSERT (obj_val != err_val); | ||
| jerry_release_value (err_val); | ||
| jerry_release_value (obj_val); | ||
|
|
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.
Remove this newline.
baaa4ac to
df50c20
Compare
|
Thank you for the reviews, I updated the PR with these changes. |
docs/02.API-REFERENCE.md
Outdated
| 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. |
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 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.
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.
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.
| jerry_get_value_from_error (jerry_value_t value, bool release) | ||
| ``` | ||
|
|
||
| - `value_p` - pointer to an api 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.
value- error (api) valuerelease- defines whether input api value must be released
docs/02.API-REFERENCE.md
Outdated
| 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. |
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.
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.
jerry-core/api/jerry.c
Outdated
| */ | ||
| 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 */ |
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.
return value must be on separate line:
jerry_value_t
jerry_get_value_from_error (jerry_value_t value, /**< api value */
|
|
||
| **Example** | ||
|
|
||
| ```c |
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.
Please add an example for a not release error too.
df50c20 to
359d25f
Compare
|
Related issue #2213 |
|
I updated the PR. Thanks for the reviews. |
LaszloLango
left a comment
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.
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); | ||
|
|
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.
... // both 'error' and 'value' can be used and must be released when they are no longer needed
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, updated the PR.
…functions JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu
359d25f to
880ee70
Compare
LaszloLango
left a comment
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.
LGTM
zherczeg
left a comment
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.
LGTM
JerryScript-DCO-1.0-Signed-off-by: Istvan Miklos imiklos2@inf.u-szeged.hu