Skip to content

Fix several function name related issues #3848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jerry-core/parser/js/js-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
37 changes: 23 additions & 14 deletions jerry-core/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,31 +1834,40 @@ 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))
{
result = ECMA_VALUE_ERROR;
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;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/jerry/es2015/function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');