Add name to the function property names (#4760)

Furthermore prototype should be the first property.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2021-09-03 12:42:06 +02:00 committed by GitHub
parent 1523ca3b26
commit fea10bb7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 13 deletions

View File

@ -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);

View File

@ -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")

View File

@ -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");