Skip to content

Commit 5fdeb7c

Browse files
authored
[[Prototype]] object's reference count should be increased by jerry_get_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]
1 parent d740470 commit 5fdeb7c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

jerry-core/api/jerry.c

+4
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,9 @@ jerry_get_object_keys (const jerry_value_t obj_val) /**< object value */
27852785
/**
27862786
* Get the prototype of the specified object
27872787
*
2788+
* Note:
2789+
* returned value must be freed with jerry_release_value, when it is no longer needed.
2790+
*
27882791
* @return prototype object or null value - if success
27892792
* value marked with error flag - otherwise
27902793
*/
@@ -2806,6 +2809,7 @@ jerry_get_prototype (const jerry_value_t obj_val) /**< object value */
28062809
}
28072810

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

28102814
return ecma_make_object_value (proto_obj_p);
28112815
} /* jerry_get_prototype */

tests/unit-core/test-api.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,16 @@ main (void)
683683
jerry_release_value (prim_val);
684684

685685
/* Test: jerry_get_prototype */
686+
proto_val = jerry_get_prototype (jerry_create_undefined ());
687+
TEST_ASSERT (jerry_value_is_error (proto_val));
688+
jerry_value_t error = jerry_get_value_from_error (proto_val, true);
689+
TEST_ASSERT (jerry_get_error_type (error) == JERRY_ERROR_TYPE);
690+
jerry_release_value (error);
691+
686692
proto_val = jerry_get_prototype (obj_val);
687693
TEST_ASSERT (!jerry_value_is_error (proto_val));
688694
TEST_ASSERT (jerry_value_is_object (proto_val));
695+
jerry_release_value (proto_val);
689696
jerry_release_value (obj_val);
690697

691698
/* Test: jerry_set_prototype */
@@ -695,7 +702,9 @@ main (void)
695702
TEST_ASSERT (jerry_value_is_boolean (res));
696703
TEST_ASSERT (jerry_get_boolean_value (res));
697704

698-
res = jerry_set_prototype (obj_val, jerry_create_object ());
705+
jerry_value_t new_proto = jerry_create_object ();
706+
res = jerry_set_prototype (obj_val, new_proto);
707+
jerry_release_value (new_proto);
699708
TEST_ASSERT (!jerry_value_is_error (res));
700709
TEST_ASSERT (jerry_value_is_boolean (res));
701710
TEST_ASSERT (jerry_get_boolean_value (res));

0 commit comments

Comments
 (0)