From 8e83638daa24b9f9ffffc83e61d55063e2e9d490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Mon, 18 Jan 2021 18:20:24 +0100 Subject: [PATCH] Update the name handling of anonymous functions to ES11 (#4279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu --- jerry-core/ecma/base/ecma-helpers-value.c | 13 ++++++++++++ jerry-core/ecma/base/ecma-helpers.h | 1 + .../ecma/operations/ecma-function-object.c | 21 ++++++++----------- jerry-core/jmem/jmem.h | 6 ++++++ jerry-core/parser/js/js-parser.c | 9 ++++---- jerry-core/vm/opcodes.c | 5 ++++- tests/jerry/es.next/function-name.js | 6 +++--- tests/test262-es6-excludelist.xml | 4 ++++ tests/test262-esnext-excludelist.xml | 9 -------- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/jerry-core/ecma/base/ecma-helpers-value.c b/jerry-core/ecma/base/ecma-helpers-value.c index b90c6325f..23bbd43f9 100644 --- a/jerry-core/ecma/base/ecma-helpers-value.c +++ b/jerry-core/ecma/base/ecma-helpers-value.c @@ -340,6 +340,19 @@ ecma_is_value_symbol (ecma_value_t value) /**< ecma value */ #endif /* ENABLED (JERRY_ESNEXT) */ } /* ecma_is_value_symbol */ +/** + * Check if the value is a specific magic string. + * + * @return true - if the value the magic string value, + * false - otherwise + */ +extern inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE +ecma_is_value_magic_string (ecma_value_t value, /**< ecma value */ + lit_magic_string_id_t id) /**< magic string id */ +{ + return value == ecma_make_magic_string_value (id); +} /* ecma_is_value_magic_string */ + /** * Check if the value is bigint. * diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index 98c4ca532..3340c79f6 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -234,6 +234,7 @@ bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_magic_string (ecma_value_t value, lit_magic_string_id_t id); bool JERRY_ATTR_CONST ecma_is_value_bigint (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value); diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index afa8994c0..f901f8a3f 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1787,19 +1787,16 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**< if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR) { ecma_value_t value = *ecma_compiled_code_resolve_function_name (bytecode_data_p); - if (value != ECMA_VALUE_EMPTY) - { - JERRY_ASSERT (ecma_is_value_string (value)); + JERRY_ASSERT (ecma_is_value_string (value)); - /* Initialize 'name' property */ - ecma_property_t *value_prop_p; - ecma_property_value_t *value_p = ecma_create_named_data_property (object_p, - property_name_p, - ECMA_PROPERTY_FLAG_CONFIGURABLE, - &value_prop_p); - value_p->value = ecma_copy_value (value); - return value_prop_p; - } + /* Initialize 'name' property */ + ecma_property_t *value_prop_p; + ecma_property_value_t *value_p = ecma_create_named_data_property (object_p, + property_name_p, + ECMA_PROPERTY_FLAG_CONFIGURABLE, + &value_prop_p); + value_p->value = ecma_copy_value (value); + return value_prop_p; } } diff --git a/jerry-core/jmem/jmem.h b/jerry-core/jmem/jmem.h index a89f705df..960a6bf24 100644 --- a/jerry-core/jmem/jmem.h +++ b/jerry-core/jmem/jmem.h @@ -277,6 +277,12 @@ void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer); #define JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, cp_value) \ ((type *) (jmem_decompress_pointer ((cp_value & ~JMEM_TAG_MASK) >> JMEM_TAG_SHIFT))) +/** + * Extract tag bits from pointer-tag value + */ +#define JMEM_CP_GET_POINTER_TAG_BITS(cp_value) \ + (cp_value & (JMEM_FIRST_TAG_BIT_MASK | JMEM_SECOND_TAG_BIT_MASK | JMEM_THIRD_TAG_BIT_MASK)) + /** * Get value of each tag from specified pointer-tag value */ diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 0031dfe0c..a64a37aa0 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -1358,7 +1358,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ #if ENABLED (JERRY_ESNEXT) if (!(context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)) { - *(--base_p) = ECMA_VALUE_EMPTY; + *(--base_p) = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); } if (context_p->argument_length != UINT16_MAX) @@ -2625,9 +2625,10 @@ parser_check_anonymous_function_declaration (parser_context_t *context_p) /**< c const ecma_compiled_code_t *bytecode_p; bytecode_p = (const ecma_compiled_code_t *) (PARSER_GET_LITERAL (literal_index)->u.bytecode_p); - ecma_value_t *func_name_start_p = ecma_compiled_code_resolve_function_name (bytecode_p); + bool is_anon = ecma_is_value_magic_string (*ecma_compiled_code_resolve_function_name (bytecode_p), + LIT_MAGIC_STRING__EMPTY); - return (*func_name_start_p == ECMA_VALUE_EMPTY ? literal_index : PARSER_NAMED_FUNCTION); + return (is_anon ? literal_index : PARSER_NAMED_FUNCTION); } /* parser_check_anonymous_function_declaration */ /** @@ -2659,7 +2660,7 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex ecma_value_t *func_name_start_p; func_name_start_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_p); - if (JERRY_UNLIKELY (*func_name_start_p != ECMA_VALUE_EMPTY)) + if (JERRY_UNLIKELY (!ecma_is_value_magic_string (*func_name_start_p, LIT_MAGIC_STRING__EMPTY))) { return; } diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index a79d4fe79..3e7e92573 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -1183,7 +1183,10 @@ opfunc_set_home_object (ecma_object_t *func_p, /**< function object */ { JERRY_ASSERT (!ecma_get_object_is_builtin (func_p)); - ECMA_SET_NON_NULL_POINTER_TAG (((ecma_extended_object_t *) func_p)->u.function.scope_cp, parent_env_p, 0); + ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_p; + ECMA_SET_NON_NULL_POINTER_TAG (ext_func_p->u.function.scope_cp, + parent_env_p, + JMEM_CP_GET_POINTER_TAG_BITS (ext_func_p->u.function.scope_cp)); } } /* opfunc_set_home_object */ diff --git a/tests/jerry/es.next/function-name.js b/tests/jerry/es.next/function-name.js index f2a9e4fe8..f2c2a3eab 100644 --- a/tests/jerry/es.next/function-name.js +++ b/tests/jerry/es.next/function-name.js @@ -68,7 +68,7 @@ assertMethodName(func2, 'bar'); var func3 = (function () {}).prototype.constructor; assert(typeof func3 === 'function'); -assertNameNotExists(func3); +assertMethodName(func3, ''); var func4; func4 = function () {} @@ -80,7 +80,7 @@ assertMethodName(func5, 'bar'); var func6; (func6) = function () {} -assertNameNotExists(func6); +assertMethodName(func6, ''); var func7; (func7) = function bar () {} @@ -290,7 +290,7 @@ let arFunc; let array = []; array['original'] = array; array['original'][arFunc = ()=>{ }]=function(){} -assertNameNotExists(array[arFunc]); +assertMethodName(array[arFunc], ''); var o = { 0 : class {} }; diff --git a/tests/test262-es6-excludelist.xml b/tests/test262-es6-excludelist.xml index a47f06133..870ac5c71 100644 --- a/tests/test262-es6-excludelist.xml +++ b/tests/test262-es6-excludelist.xml @@ -333,4 +333,8 @@ ES11: arguments object no longer has caller property ES11+: ProxyCreate does not check Proxy handler and target. ES11+: ProxyCreate does not check Proxy handler and target. + Outdated test, anonymous funtions should now have a name property + Outdated test, anonymous funtions should now have a name property + Outdated test, anonymous funtions should now have a name property + Outdated test, anonymous funtions should now have a name property diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 3d6116994..bc584442a 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -105,7 +105,6 @@ Test expects incorrect call order Test expects incorrect call order Test expects incorrect call order - Test expects incorrect call order @@ -217,7 +216,6 @@ - @@ -260,14 +258,9 @@ - - - - - @@ -302,11 +295,9 @@ - -