Fix several function name related issues (#3848)

- For non-computed name srcipt functions only identifier/string literal should be set as name
- Implicit class constructor names with non string function name should be ToString-ed

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik 2020-06-04 13:44:22 +02:00 committed by GitHub
parent e6ebc2be78
commit c09c2c5dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 14 deletions

View File

@ -2690,6 +2690,11 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex
lexer_literal_t *name_lit_p = (lexer_literal_t *) PARSER_GET_LITERAL (name_index);
if (name_lit_p->type != LEXER_IDENT_LITERAL && name_lit_p->type != LEXER_STRING_LITERAL)
{
return;
}
uint8_t *name_buffer_p = (uint8_t *) name_lit_p->u.char_p;
uint32_t name_length = name_lit_p->prop.length;

View File

@ -1834,15 +1834,22 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
char *prefix_p = NULL;
lit_utf8_size_t prefix_size = 0;
if (opcode == CBC_EXT_SET_CLASS_NAME)
if (opcode != CBC_EXT_SET_FUNCTION_NAME)
{
uint16_t literal_index;
READ_LITERAL_INDEX (literal_index);
left_value = ecma_copy_value (literal_start_p[literal_index]);
}
else if (opcode != CBC_EXT_SET_FUNCTION_NAME)
{
ecma_string_t *prop_name_p = ecma_op_to_prop_name (stack_top_p[-2]);
ecma_value_t prop_name_value;
if (opcode == CBC_EXT_SET_CLASS_NAME)
{
uint16_t literal_index;
READ_LITERAL_INDEX (literal_index);
prop_name_value = literal_start_p[literal_index];
}
else
{
prop_name_value = stack_top_p[-2];
}
ecma_string_t *prop_name_p = ecma_op_to_prop_name (prop_name_value);
if (JERRY_UNLIKELY (prop_name_p == NULL))
{
@ -1850,15 +1857,17 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
goto error;
}
ecma_free_value (stack_top_p[-2]);
ecma_ref_ecma_string (prop_name_p);
left_value = ecma_make_prop_name_value (prop_name_p);
stack_top_p[-2] = left_value;
if (opcode != CBC_EXT_SET_COMPUTED_FUNCTION_NAME)
if (opcode != CBC_EXT_SET_CLASS_NAME)
{
ecma_ref_ecma_string (prop_name_p);
ecma_free_value (stack_top_p[-2]);
stack_top_p[-2] = left_value;
}
if (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME || opcode == CBC_EXT_SET_COMPUTED_SETTER_NAME)
{
JERRY_ASSERT (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME
|| opcode == CBC_EXT_SET_COMPUTED_SETTER_NAME);
prefix_p = (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME) ? "get " : "set ";
prefix_size = 4;
}

View File

@ -285,3 +285,13 @@ assert(Object.getOwnPropertyDescriptor(Array, Symbol.species).get.name === 'get
assert(Object.getOwnPropertyDescriptor(String.prototype, Symbol.iterator).value.name === '[Symbol.iterator]');
assert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get.name === 'get __proto__');
assert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set.name === 'set __proto__');
let arFunc;
let array = [];
array['original'] = array;
array['original'][arFunc = ()=>{ }]=function(){}
assertNameNotExists(array[arFunc]);
var o = { 0 : class {} };
assertMethodName(o['0'], '0');