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

[[Prototype]] object's reference count should be increased by jerry_get_prototype #3550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jerry-core/api/jerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -2785,6 +2785,9 @@ jerry_get_object_keys (const jerry_value_t obj_val) /**< object value */
/**
* Get the prototype of the specified object
*
* Note:
* returned value must be freed with jerry_release_value, when it is no longer needed.
*
* @return prototype object or null value - if success
* value marked with error flag - otherwise
*/
Expand All @@ -2806,6 +2809,7 @@ jerry_get_prototype (const jerry_value_t obj_val) /**< object value */
}

ecma_object_t *proto_obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_p->u2.prototype_cp);
ecma_ref_object (proto_obj_p);

return ecma_make_object_value (proto_obj_p);
} /* jerry_get_prototype */
Expand Down
11 changes: 10 additions & 1 deletion tests/unit-core/test-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,16 @@ main (void)
jerry_release_value (prim_val);

/* Test: jerry_get_prototype */
proto_val = jerry_get_prototype (jerry_create_undefined ());
TEST_ASSERT (jerry_value_is_error (proto_val));
jerry_value_t error = jerry_get_value_from_error (proto_val, true);
TEST_ASSERT (jerry_get_error_type (error) == JERRY_ERROR_TYPE);
jerry_release_value (error);

proto_val = jerry_get_prototype (obj_val);
TEST_ASSERT (!jerry_value_is_error (proto_val));
TEST_ASSERT (jerry_value_is_object (proto_val));
jerry_release_value (proto_val);
jerry_release_value (obj_val);

/* Test: jerry_set_prototype */
Expand All @@ -695,7 +702,9 @@ main (void)
TEST_ASSERT (jerry_value_is_boolean (res));
TEST_ASSERT (jerry_get_boolean_value (res));

res = jerry_set_prototype (obj_val, jerry_create_object ());
jerry_value_t new_proto = jerry_create_object ();
res = jerry_set_prototype (obj_val, new_proto);
jerry_release_value (new_proto);
TEST_ASSERT (!jerry_value_is_error (res));
TEST_ASSERT (jerry_value_is_boolean (res));
TEST_ASSERT (jerry_get_boolean_value (res));
Expand Down