Skip to content

Commit

Permalink
[[Prototype]] object's reference count should be increased by jerry_g…
Browse files Browse the repository at this point in the history
…et_prototype (#3550)

This patch ensures that the implementation satisfies the requirements of the public API documentation.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
  • Loading branch information
rerobika authored Feb 7, 2020
1 parent d740470 commit 5fdeb7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 5fdeb7c

Please sign in to comment.