From c74256ccbab5acb685778f05b5258398f08f3dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=A1l?= Date: Sat, 4 Apr 2020 01:43:52 +0200 Subject: [PATCH] Fix objects foreach unittest (#3660) The `jerry_objects_foreach` unittest incorrectly tried to create Map objects. Added extra checks and improved the Map object creation. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com --- tests/unit-core/test-objects-foreach.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/unit-core/test-objects-foreach.c b/tests/unit-core/test-objects-foreach.c index 3e7f9a84f..cce1949ef 100644 --- a/tests/unit-core/test-objects-foreach.c +++ b/tests/unit-core/test-objects-foreach.c @@ -47,13 +47,27 @@ test_container (void) return; } - const char *eval_str = "new Map ([[1, 2], [3, 4]])"; + { + /* Create a "DEMO" array which will be used for the Map below. */ + const char array_str[] = "var DEMO = [[1, 2], [3, 4]]; DEMO"; + jerry_value_t array = jerry_eval ((const jerry_char_t *) array_str, sizeof (array_str) - 1, 0); + TEST_ASSERT (jerry_value_is_object (array)); + TEST_ASSERT (!jerry_value_is_error (array)); + jerry_release_value (array); + } + + const char eval_str[] = "new Map (DEMO)"; { /* Make sure that the Map and it's prototype object/function is initialized. */ jerry_value_t result = jerry_eval ((const jerry_char_t *) eval_str, sizeof (eval_str) - 1, 0); + TEST_ASSERT (jerry_value_is_object (result)); + TEST_ASSERT (!jerry_value_is_error (result)); jerry_release_value (result); } + /* Do a bit of cleaning to clear up old objects. */ + jerry_gc (JERRY_GC_PRESSURE_LOW); + /* Get the number of iterable objects. */ int start_count = 0; jerry_objects_foreach (count_objects, &start_count); @@ -61,11 +75,14 @@ test_container (void) /* Create another map. */ jerry_value_t result = jerry_eval ((const jerry_char_t *) eval_str, sizeof (eval_str) - 1, 0); + /* Remove any old/unused objects. */ + jerry_gc (JERRY_GC_PRESSURE_LOW); + /* Get the current number of objects. */ int end_count = 0; jerry_objects_foreach (count_objects, &end_count); - /* As only one Map was created the number of iterable objects should be incremented only by one. */ + /* As only one Map was created the number of available iterable objects should be incremented only by one. */ TEST_ASSERT (end_count > start_count); TEST_ASSERT ((end_count - start_count) == 1);