Skip to content

Commit 6b9e24a

Browse files
authored
Fix function name evaluation order (#4830)
JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]
1 parent 4592143 commit 6b9e24a

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

jerry-core/ecma/operations/ecma-function-object.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,8 @@ ecma_op_function_list_lazy_property_names (ecma_object_t *object_p, /**< functio
22482248
#endif /* JERRY_ESNEXT */
22492249

22502250
#if JERRY_ESNEXT
2251-
if (!CBC_FUNCTION_HAS_PROTOTYPE (bytecode_data_p->status_flags))
2251+
if (!CBC_FUNCTION_HAS_PROTOTYPE (bytecode_data_p->status_flags)
2252+
|| (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_CONSTRUCTOR))
22522253
{
22532254
return;
22542255
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ parser_is_constructor_literal (parser_context_t *context_p) /**< context */
520520
*/
521521
static bool
522522
parser_parse_class_body (parser_context_t *context_p, /**< context */
523-
parser_class_literal_opts_t opts) /**< class literal parsing options */
523+
parser_class_literal_opts_t opts, /**< class literal parsing options */
524+
uint16_t class_name_index) /**< class literal index */
524525
{
525526
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE);
526527

@@ -541,6 +542,11 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
541542
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR);
542543
}
543544

545+
if (class_name_index != PARSER_INVALID_LITERAL_INDEX)
546+
{
547+
parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, class_name_index);
548+
}
549+
544550
parser_emit_cbc_ext (context_p, CBC_EXT_INIT_CLASS);
545551

546552
bool is_static = false;
@@ -1014,12 +1020,11 @@ parser_parse_class (parser_context_t *context_p, /**< context */
10141020
}
10151021

10161022
/* ClassDeclaration is parsed. Continue with class body. */
1017-
bool has_static_field = parser_parse_class_body (context_p, opts);
1023+
bool has_static_field = parser_parse_class_body (context_p, opts, class_name_index);
10181024

10191025
if (class_name_index != PARSER_INVALID_LITERAL_INDEX)
10201026
{
10211027
parser_emit_cbc_ext_literal (context_p, CBC_EXT_FINALIZE_NAMED_CLASS, class_name_index);
1022-
parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, class_name_index);
10231028
PARSER_MINUS_EQUAL_U16 (context_p->scope_stack_top, 1);
10241029
}
10251030
else

tests/jerry/es.next/class-fields3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ let C3 = class C4 {
7878
static yy = this
7979
}
8080

81-
assert(Reflect.ownKeys(C3).toString() === "length,prototype,f,name,xx,yy")
81+
assert(Reflect.ownKeys(C3).toString() === "length,name,prototype,f,xx,yy")
8282
check_property(C3, "xx", C3)
8383
check_property(C3, "yy", C3)

tests/test262-es6-excludelist.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,7 @@
335335
<test id="language/expressions/assignment/fn-name-lhs-member.js"><reason>Outdated test, anonymous functions should now have a name property</reason></test>
336336
<test id="language/expressions/function/name.js"><reason>Outdated test, anonymous functions should now have a name property</reason></test>
337337
<test id="language/expressions/generators/name.js"><reason>Outdated test, anonymous functions should now have a name property</reason></test>
338+
<test id="language/computed-property-names/class/static/method-number.js"><reason>ES12 15.7.14.15.d: The evaluation order has been changed</reason></test>
339+
<test id="language/computed-property-names/class/static/method-string.js"><reason>ES12 15.7.14.15.d: The evaluation order has been changed</reason></test>
340+
<test id="language/computed-property-names/class/static/method-symbol.js"><reason>ES12 15.7.14.15.d: The evaluation order has been changed</reason></test>
338341
</excludeList>

tests/test262-esnext-excludelist.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-async-function.js"><reason></reason></test>
6262
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-function.js"><reason></reason></test>
6363
<test id="language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-generator.js"><reason></reason></test>
64-
<test id="language/computed-property-names/class/static/method-number.js"><reason></reason></test>
65-
<test id="language/computed-property-names/class/static/method-string.js"><reason></reason></test>
66-
<test id="language/computed-property-names/class/static/method-symbol.js"><reason></reason></test>
6764
<test id="language/eval-code/direct/non-definable-function-with-function.js"><reason></reason></test>
6865
<test id="language/eval-code/direct/non-definable-function-with-variable.js"><reason></reason></test>
6966
<test id="language/eval-code/direct/non-definable-global-function.js"><reason></reason></test>

0 commit comments

Comments
 (0)