From d92d9db40fe4180e6411d8727c0aaff14b7878da Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Wed, 22 Jul 2020 15:17:39 +0200 Subject: [PATCH] Fix property name comparison when external strings are used. (#4033) JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- jerry-core/ecma/base/ecma-helpers-string.c | 18 ++-------- tests/unit-core/test-external-string.c | 38 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index bb060d97c..67a8cfba5 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -1843,25 +1843,11 @@ ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, /**< ecma- return false; } - ecma_string_container_t string1_container = ECMA_STRING_GET_CONTAINER (string1_p); - - if (string1_container != ECMA_STRING_GET_CONTAINER (string2_p)) + if (ECMA_STRING_GET_CONTAINER (string1_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) { - return false; + return ECMA_STRING_GET_CONTAINER (string2_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC; } - if (string1_container == ECMA_STRING_CONTAINER_UINT32_IN_DESC) - { - return true; - } - -#if ENABLED (JERRY_ESNEXT) - if (string1_container == ECMA_STRING_CONTAINER_SYMBOL) - { - return false; - } -#endif /* ENABLED (JERRY_ESNEXT) */ - return ecma_compare_ecma_strings_longpath (string1_p, string2_p); } /* ecma_compare_ecma_non_direct_strings */ diff --git a/tests/unit-core/test-external-string.c b/tests/unit-core/test-external-string.c index 55dd83c58..48882d98e 100644 --- a/tests/unit-core/test-external-string.c +++ b/tests/unit-core/test-external-string.c @@ -22,6 +22,7 @@ static int free_count = 0; static const char *external_1 = "External string! External string! External string! External string!"; static const char *external_2 = "Object"; static const char *external_3 = "x!?:s"; +static const char *external_4 = "Object property external string! Object property external string!"; static void free_external1 (void *ptr) @@ -117,6 +118,43 @@ main (void) jerry_release_value (external_string); TEST_ASSERT (free_count == 5); + /* Test property access. */ + external_string = jerry_create_external_string ((jerry_char_t *) external_4, NULL); + other_string = jerry_create_string ((jerry_char_t *) external_4); + + jerry_value_t obj = jerry_create_object (); + result = jerry_set_property (obj, external_string, other_string); + TEST_ASSERT (jerry_value_is_boolean (result)); + TEST_ASSERT (jerry_get_boolean_value (result)); + jerry_release_value (result); + + jerry_value_t get_result = jerry_get_property (obj, other_string); + TEST_ASSERT (jerry_value_is_string (get_result)); + + result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, get_result, external_string); + jerry_release_value (get_result); + TEST_ASSERT (jerry_value_is_boolean (result)); + TEST_ASSERT (jerry_get_boolean_value (result)); + jerry_release_value (result); + + result = jerry_set_property (obj, other_string, external_string); + TEST_ASSERT (jerry_value_is_boolean (result)); + TEST_ASSERT (jerry_get_boolean_value (result)); + jerry_release_value (result); + + get_result = jerry_get_property (obj, external_string); + TEST_ASSERT (jerry_value_is_string (get_result)); + + result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, get_result, other_string); + jerry_release_value (get_result); + TEST_ASSERT (jerry_value_is_boolean (result)); + TEST_ASSERT (jerry_get_boolean_value (result)); + jerry_release_value (result); + + jerry_release_value (obj); + jerry_release_value (external_string); + jerry_release_value (other_string); + jerry_cleanup (); return 0; } /* main */