Skip to content
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

Add new API function #1161

Merged

Conversation

LaszloLango
Copy link
Contributor

Implemented 'jerry_is_array' and 'jerry_get_array_length' API functions.

JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]

@LaszloLango LaszloLango added api Related to the public API development Feature implementation labels Jun 17, 2016
@LaszloLango LaszloLango added this to the Release v1.0 milestone Jun 17, 2016
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (ret_value));

return length;
} /* jerry_get_length */
Copy link
Member

Choose a reason for hiding this comment

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

Why this separate function is needed?

ECMA_FINALIZE (len_value);

ecma_deref_ecma_string (magic_string_length_p);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (ret_value));
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to handle/free the error if we happen to get one. I don't think hoping that people will play by the rules, and only pass valid arrays to this function is enough.

@LaszloLango LaszloLango force-pushed the jerry-api-update branch 3 times, most recently from 501b6db to 93e6c5a Compare June 22, 2016 08:26
@LaszloLango LaszloLango mentioned this pull request Jun 22, 2016
13 tasks
ecma_value_t len_value = ecma_op_object_get ((jerry_object_t *) object_p, magic_string_length_p);
ecma_deref_ecma_string (magic_string_length_p);

ecma_number_t num_var = ecma_number_make_nan ();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think an intermediate variable is necessary.

@LaszloLango
Copy link
Contributor Author

@dbatyai, @zherczeg, I've updated the PR.

*
* Note:
* Returns 0, if the given parameter is not an array object or
* cannot retrieve the length.
Copy link
Member

Choose a reason for hiding this comment

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

If it is an array you can always retreive the length. It is an unconfigurable data property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can pass any 'const jerry_object_t *object_p' to this function

Copy link
Member

Choose a reason for hiding this comment

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

I am sorry I wasn't clear. So:
if array -> return length, always
if not -> return 0

So the correct comment is:
Returns 0, if the given parameter is not an array object

@zherczeg
Copy link
Member

LGTM after these are fixed

Implemented 'jerry_is_array' and 'jerry_get_array_length' API functions.

JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
@dbatyai
Copy link
Member

dbatyai commented Jun 24, 2016

LGTM

1 similar comment
@zherczeg
Copy link
Member

LGTM

@LaszloLango LaszloLango merged commit cfa0c94 into jerryscript-project:master Jun 24, 2016
@LaszloLango LaszloLango deleted the jerry-api-update branch July 12, 2016 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the public API development Feature implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants