Skip to content

Commit c09c2c5

Browse files
authored
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 [email protected]
1 parent e6ebc2b commit c09c2c5

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

jerry-core/parser/js/js-parser.c

+5
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,11 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex
26902690

26912691
lexer_literal_t *name_lit_p = (lexer_literal_t *) PARSER_GET_LITERAL (name_index);
26922692

2693+
if (name_lit_p->type != LEXER_IDENT_LITERAL && name_lit_p->type != LEXER_STRING_LITERAL)
2694+
{
2695+
return;
2696+
}
2697+
26932698
uint8_t *name_buffer_p = (uint8_t *) name_lit_p->u.char_p;
26942699
uint32_t name_length = name_lit_p->prop.length;
26952700

jerry-core/vm/vm.c

+23-14
Original file line numberDiff line numberDiff line change
@@ -1834,31 +1834,40 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
18341834
char *prefix_p = NULL;
18351835
lit_utf8_size_t prefix_size = 0;
18361836

1837-
if (opcode == CBC_EXT_SET_CLASS_NAME)
1837+
if (opcode != CBC_EXT_SET_FUNCTION_NAME)
18381838
{
1839-
uint16_t literal_index;
1840-
READ_LITERAL_INDEX (literal_index);
1841-
left_value = ecma_copy_value (literal_start_p[literal_index]);
1842-
}
1843-
else if (opcode != CBC_EXT_SET_FUNCTION_NAME)
1844-
{
1845-
ecma_string_t *prop_name_p = ecma_op_to_prop_name (stack_top_p[-2]);
1839+
ecma_value_t prop_name_value;
1840+
1841+
if (opcode == CBC_EXT_SET_CLASS_NAME)
1842+
{
1843+
uint16_t literal_index;
1844+
READ_LITERAL_INDEX (literal_index);
1845+
prop_name_value = literal_start_p[literal_index];
1846+
}
1847+
else
1848+
{
1849+
prop_name_value = stack_top_p[-2];
1850+
}
1851+
1852+
ecma_string_t *prop_name_p = ecma_op_to_prop_name (prop_name_value);
18461853

18471854
if (JERRY_UNLIKELY (prop_name_p == NULL))
18481855
{
18491856
result = ECMA_VALUE_ERROR;
18501857
goto error;
18511858
}
18521859

1853-
ecma_free_value (stack_top_p[-2]);
1854-
ecma_ref_ecma_string (prop_name_p);
18551860
left_value = ecma_make_prop_name_value (prop_name_p);
1856-
stack_top_p[-2] = left_value;
18571861

1858-
if (opcode != CBC_EXT_SET_COMPUTED_FUNCTION_NAME)
1862+
if (opcode != CBC_EXT_SET_CLASS_NAME)
1863+
{
1864+
ecma_ref_ecma_string (prop_name_p);
1865+
ecma_free_value (stack_top_p[-2]);
1866+
stack_top_p[-2] = left_value;
1867+
}
1868+
1869+
if (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME || opcode == CBC_EXT_SET_COMPUTED_SETTER_NAME)
18591870
{
1860-
JERRY_ASSERT (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME
1861-
|| opcode == CBC_EXT_SET_COMPUTED_SETTER_NAME);
18621871
prefix_p = (opcode == CBC_EXT_SET_COMPUTED_GETTER_NAME) ? "get " : "set ";
18631872
prefix_size = 4;
18641873
}

tests/jerry/es2015/function-name.js

+10
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,13 @@ assert(Object.getOwnPropertyDescriptor(Array, Symbol.species).get.name === 'get
285285
assert(Object.getOwnPropertyDescriptor(String.prototype, Symbol.iterator).value.name === '[Symbol.iterator]');
286286
assert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get.name === 'get __proto__');
287287
assert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set.name === 'set __proto__');
288+
289+
let arFunc;
290+
let array = [];
291+
array['original'] = array;
292+
array['original'][arFunc = ()=>{ }]=function(){}
293+
assertNameNotExists(array[arFunc]);
294+
295+
var o = { 0 : class {} };
296+
297+
assertMethodName(o['0'], '0');

0 commit comments

Comments
 (0)