diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index f15a225d3..0034286d2 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1981,35 +1981,51 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio ecma_collection_t *prop_names_p, /**< prop name collection */ ecma_property_counter_t *prop_counter_p) /**< prop counter */ { + const ecma_compiled_code_t *bytecode_data_p; + bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); + +#if JERRY_ESNEXT + bool append_prototype = CBC_FUNCTION_HAS_PROTOTYPE (bytecode_data_p->status_flags); +#else /* !JERRY_ESNEXT */ + bool append_prototype = true; +#endif /* JERRY_ESNEXT */ + + if (append_prototype) + { + /* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE)); + prop_counter_p->string_named_props++; + } + #if JERRY_ESNEXT ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p; + if (!ECMA_GET_FIRST_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) { /* Unintialized 'length' property is non-enumerable (ECMA-262 v6, 19.2.4.1) */ ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); prop_counter_p->string_named_props++; } + + if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR + && !ECMA_GET_SECOND_BIT_FROM_POINTER_TAG (ext_func_p->u.function.scope_cp)) + { + /* Unintialized 'name' property is non-enumerable (ECMA-262 v6, 19.2.4.2) */ + ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_NAME)); + prop_counter_p->string_named_props++; + } #else /* !JERRY_ESNEXT */ /* 'length' property is non-enumerable (ECMA-262 v5, 13.2.5) */ ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_LENGTH)); prop_counter_p->string_named_props++; #endif /* JERRY_ESNEXT */ - const ecma_compiled_code_t *bytecode_data_p; - bytecode_data_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p); - #if JERRY_ESNEXT - if (!CBC_FUNCTION_HAS_PROTOTYPE (bytecode_data_p->status_flags)) + if (!append_prototype) { return; } -#endif /* JERRY_ESNEXT */ - /* 'prototype' property is non-enumerable (ECMA-262 v5, 13.2.18) */ - ecma_collection_push_back (prop_names_p, ecma_make_magic_string_value (LIT_MAGIC_STRING_PROTOTYPE)); - prop_counter_p->string_named_props++; - -#if JERRY_ESNEXT bool append_caller_and_arguments = !(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE); #else /* !JERRY_ESNEXT */ bool append_caller_and_arguments = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE); diff --git a/tests/jerry/es.next/function-properties.js b/tests/jerry/es.next/function-properties.js index df9352b61..a3da998f8 100644 --- a/tests/jerry/es.next/function-properties.js +++ b/tests/jerry/es.next/function-properties.js @@ -44,3 +44,9 @@ assert(getProperties(bound_func) == "dummy caller arguments prototype"); // 'print' is an external function Object.setPrototypeOf(print, prototype_obj); assert(getProperties(print) == "dummy length caller arguments"); + +function f1() {} +assert(Reflect.ownKeys(f1).toString() === "prototype,length,name,caller,arguments") + +async function f2() {} +assert(Reflect.ownKeys(f2).toString() === "length,name") diff --git a/tests/jerry/es.next/regression-test-issue-3267.js b/tests/jerry/es.next/regression-test-issue-3267.js index 2f0f92b4e..43f9831d3 100644 --- a/tests/jerry/es.next/regression-test-issue-3267.js +++ b/tests/jerry/es.next/regression-test-issue-3267.js @@ -17,6 +17,7 @@ Object.preventExtensions(hasProp); assert (Object.isSealed(hasProp) === false); var keys = Object.getOwnPropertyNames(hasProp); -assert (keys.length === 1); -assert (keys[0] === "length"); - +assert (keys.length === 2); +/* Note: the order is currently wrong. */ +assert (keys[0] === "name"); +assert (keys[1] === "length");