Skip to content

Commit 8e83638

Browse files
author
Dániel Bátyai
authored
Update the name handling of anonymous functions to ES11 (#4279)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
1 parent 6ec4455 commit 8e83638

File tree

9 files changed

+46
-30
lines changed

9 files changed

+46
-30
lines changed

jerry-core/ecma/base/ecma-helpers-value.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ ecma_is_value_symbol (ecma_value_t value) /**< ecma value */
340340
#endif /* ENABLED (JERRY_ESNEXT) */
341341
} /* ecma_is_value_symbol */
342342

343+
/**
344+
* Check if the value is a specific magic string.
345+
*
346+
* @return true - if the value the magic string value,
347+
* false - otherwise
348+
*/
349+
extern inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE
350+
ecma_is_value_magic_string (ecma_value_t value, /**< ecma value */
351+
lit_magic_string_id_t id) /**< magic string id */
352+
{
353+
return value == ecma_make_magic_string_value (id);
354+
} /* ecma_is_value_magic_string */
355+
343356
/**
344357
* Check if the value is bigint.
345358
*

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value);
234234
bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value);
235235
bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value);
236236
bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value);
237+
bool JERRY_ATTR_CONST ecma_is_value_magic_string (ecma_value_t value, lit_magic_string_id_t id);
237238
bool JERRY_ATTR_CONST ecma_is_value_bigint (ecma_value_t value);
238239
bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value);
239240
bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value);

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,19 +1787,16 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**<
17871787
if (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) != CBC_FUNCTION_CONSTRUCTOR)
17881788
{
17891789
ecma_value_t value = *ecma_compiled_code_resolve_function_name (bytecode_data_p);
1790-
if (value != ECMA_VALUE_EMPTY)
1791-
{
1792-
JERRY_ASSERT (ecma_is_value_string (value));
1793-
1794-
/* Initialize 'name' property */
1795-
ecma_property_t *value_prop_p;
1796-
ecma_property_value_t *value_p = ecma_create_named_data_property (object_p,
1797-
property_name_p,
1798-
ECMA_PROPERTY_FLAG_CONFIGURABLE,
1799-
&value_prop_p);
1800-
value_p->value = ecma_copy_value (value);
1801-
return value_prop_p;
1802-
}
1790+
JERRY_ASSERT (ecma_is_value_string (value));
1791+
1792+
/* Initialize 'name' property */
1793+
ecma_property_t *value_prop_p;
1794+
ecma_property_value_t *value_p = ecma_create_named_data_property (object_p,
1795+
property_name_p,
1796+
ECMA_PROPERTY_FLAG_CONFIGURABLE,
1797+
&value_prop_p);
1798+
value_p->value = ecma_copy_value (value);
1799+
return value_prop_p;
18031800
}
18041801
}
18051802

jerry-core/jmem/jmem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
277277
#define JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, cp_value) \
278278
((type *) (jmem_decompress_pointer ((cp_value & ~JMEM_TAG_MASK) >> JMEM_TAG_SHIFT)))
279279

280+
/**
281+
* Extract tag bits from pointer-tag value
282+
*/
283+
#define JMEM_CP_GET_POINTER_TAG_BITS(cp_value) \
284+
(cp_value & (JMEM_FIRST_TAG_BIT_MASK | JMEM_SECOND_TAG_BIT_MASK | JMEM_THIRD_TAG_BIT_MASK))
285+
280286
/**
281287
* Get value of each tag from specified pointer-tag value
282288
*/

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
13581358
#if ENABLED (JERRY_ESNEXT)
13591359
if (!(context_p->status_flags & PARSER_CLASS_CONSTRUCTOR))
13601360
{
1361-
*(--base_p) = ECMA_VALUE_EMPTY;
1361+
*(--base_p) = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
13621362
}
13631363

13641364
if (context_p->argument_length != UINT16_MAX)
@@ -2625,9 +2625,10 @@ parser_check_anonymous_function_declaration (parser_context_t *context_p) /**< c
26252625

26262626
const ecma_compiled_code_t *bytecode_p;
26272627
bytecode_p = (const ecma_compiled_code_t *) (PARSER_GET_LITERAL (literal_index)->u.bytecode_p);
2628-
ecma_value_t *func_name_start_p = ecma_compiled_code_resolve_function_name (bytecode_p);
2628+
bool is_anon = ecma_is_value_magic_string (*ecma_compiled_code_resolve_function_name (bytecode_p),
2629+
LIT_MAGIC_STRING__EMPTY);
26292630

2630-
return (*func_name_start_p == ECMA_VALUE_EMPTY ? literal_index : PARSER_NAMED_FUNCTION);
2631+
return (is_anon ? literal_index : PARSER_NAMED_FUNCTION);
26312632
} /* parser_check_anonymous_function_declaration */
26322633

26332634
/**
@@ -2659,7 +2660,7 @@ parser_compiled_code_set_function_name (parser_context_t *context_p, /**< contex
26592660
ecma_value_t *func_name_start_p;
26602661
func_name_start_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_p);
26612662

2662-
if (JERRY_UNLIKELY (*func_name_start_p != ECMA_VALUE_EMPTY))
2663+
if (JERRY_UNLIKELY (!ecma_is_value_magic_string (*func_name_start_p, LIT_MAGIC_STRING__EMPTY)))
26632664
{
26642665
return;
26652666
}

jerry-core/vm/opcodes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,10 @@ opfunc_set_home_object (ecma_object_t *func_p, /**< function object */
11831183
{
11841184
JERRY_ASSERT (!ecma_get_object_is_builtin (func_p));
11851185

1186-
ECMA_SET_NON_NULL_POINTER_TAG (((ecma_extended_object_t *) func_p)->u.function.scope_cp, parent_env_p, 0);
1186+
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) func_p;
1187+
ECMA_SET_NON_NULL_POINTER_TAG (ext_func_p->u.function.scope_cp,
1188+
parent_env_p,
1189+
JMEM_CP_GET_POINTER_TAG_BITS (ext_func_p->u.function.scope_cp));
11871190
}
11881191
} /* opfunc_set_home_object */
11891192

tests/jerry/es.next/function-name.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ assertMethodName(func2, 'bar');
6868

6969
var func3 = (function () {}).prototype.constructor;
7070
assert(typeof func3 === 'function');
71-
assertNameNotExists(func3);
71+
assertMethodName(func3, '');
7272

7373
var func4;
7474
func4 = function () {}
@@ -80,7 +80,7 @@ assertMethodName(func5, 'bar');
8080

8181
var func6;
8282
(func6) = function () {}
83-
assertNameNotExists(func6);
83+
assertMethodName(func6, '');
8484

8585
var func7;
8686
(func7) = function bar () {}
@@ -290,7 +290,7 @@ let arFunc;
290290
let array = [];
291291
array['original'] = array;
292292
array['original'][arFunc = ()=>{ }]=function(){}
293-
assertNameNotExists(array[arFunc]);
293+
assertMethodName(array[arFunc], '');
294294

295295
var o = { 0 : class {} };
296296

tests/test262-es6-excludelist.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,8 @@
333333
<test id="language/statements/class/strict-mode/arguments-caller.js"><reason>ES11: arguments object no longer has caller property</reason></test>
334334
<test id="built-ins/Proxy/create-handler-is-revoked-proxy.js"><reason>ES11+: ProxyCreate does not check Proxy handler and target.</reason></test>
335335
<test id="built-ins/Proxy/create-target-is-revoked-proxy.js"><reason>ES11+: ProxyCreate does not check Proxy handler and target.</reason></test>
336+
<test id="language/expressions/assignment/fn-name-lhs-cover.js"><reason>Outdated test, anonymous funtions should now have a name property</reason></test>
337+
<test id="language/expressions/assignment/fn-name-lhs-member.js"><reason>Outdated test, anonymous funtions should now have a name property</reason></test>
338+
<test id="language/expressions/function/name.js"><reason>Outdated test, anonymous funtions should now have a name property</reason></test>
339+
<test id="language/expressions/generators/name.js"><reason>Outdated test, anonymous funtions should now have a name property</reason></test>
336340
</excludeList>

tests/test262-esnext-excludelist.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<test id="built-ins/Promise/all/invoke-resolve-get-error.js"><reason>Test expects incorrect call order</reason></test>
106106
<test id="built-ins/Promise/all/resolve-non-callable.js"><reason>Test expects incorrect call order</reason></test>
107107
<test id="built-ins/Promise/race/invoke-resolve-get-error.js"><reason>Test expects incorrect call order</reason></test>
108-
<test id="built-ins/Promise/race/resolve-element-function-name.js"><reason></reason></test>
109108
<test id="built-ins/Promise/race/resolve-non-callable.js"><reason>Test expects incorrect call order</reason></test>
110109
<test id="built-ins/Proxy/preventExtensions/trap-is-undefined-target-is-proxy.js"><reason></reason></test>
111110
<test id="built-ins/Proxy/setPrototypeOf/toboolean-trap-result-false.js"><reason></reason></test>
@@ -217,7 +216,6 @@
217216
<test id="language/expressions/arrow-function/dstr/ary-init-iter-no-close.js"><reason></reason></test>
218217
<test id="language/expressions/arrow-function/dstr/dflt-ary-init-iter-no-close.js"><reason></reason></test>
219218
<test id="language/expressions/arrow-function/eval-var-scope-syntax-err.js"><reason></reason></test>
220-
<test id="language/expressions/arrow-function/name.js"><reason></reason></test>
221219
<test id="language/expressions/arrow-function/param-dflt-yield-expr.js"><reason></reason></test>
222220
<test id="language/expressions/assignment/S11.13.1_A5_T1.js"><reason></reason></test>
223221
<test id="language/expressions/assignment/S11.13.1_A5_T2.js"><reason></reason></test>
@@ -260,14 +258,9 @@
260258
<test id="language/expressions/assignment/dstr/array-rest-iter-thrw-close.js"><reason></reason></test>
261259
<test id="language/expressions/assignment/dstr/array-rest-lref-err.js"><reason></reason></test>
262260
<test id="language/expressions/assignment/dstr/array-rest-lref.js"><reason></reason></test>
263-
<test id="language/expressions/assignment/fn-name-lhs-cover.js"><reason></reason></test>
264-
<test id="language/expressions/assignment/fn-name-lhs-member.js"><reason></reason></test>
265261
<test id="language/expressions/async-arrow-function/await-as-param-nested-arrow-body-position.js"><reason></reason></test>
266262
<test id="language/expressions/async-arrow-function/await-as-param-nested-arrow-parameter-position.js"><reason></reason></test>
267263
<test id="language/expressions/async-arrow-function/await-as-param-rest-nested-arrow-parameter-position.js"><reason></reason></test>
268-
<test id="language/expressions/async-arrow-function/name.js"><reason></reason></test>
269-
<test id="language/expressions/async-function/name.js"><reason></reason></test>
270-
<test id="language/expressions/async-generator/name.js"><reason></reason></test>
271264
<test id="language/expressions/call/eval-spread-empty-leading.js"><reason></reason></test>
272265
<test id="language/expressions/call/eval-spread-empty-trailing.js"><reason></reason></test>
273266
<test id="language/expressions/call/eval-spread.js"><reason></reason></test>
@@ -302,11 +295,9 @@
302295
<test id="language/expressions/function/dstr/ary-init-iter-no-close.js"><reason></reason></test>
303296
<test id="language/expressions/function/dstr/dflt-ary-init-iter-no-close.js"><reason></reason></test>
304297
<test id="language/expressions/function/eval-var-scope-syntax-err.js"><reason></reason></test>
305-
<test id="language/expressions/function/name.js"><reason></reason></test>
306298
<test id="language/expressions/generators/dstr/ary-init-iter-no-close.js"><reason></reason></test>
307299
<test id="language/expressions/generators/dstr/dflt-ary-init-iter-no-close.js"><reason></reason></test>
308300
<test id="language/expressions/generators/eval-var-scope-syntax-err.js"><reason></reason></test>
309-
<test id="language/expressions/generators/name.js"><reason></reason></test>
310301
<test id="language/expressions/import.meta/distinct-for-each-module.js"><reason></reason></test>
311302
<test id="language/expressions/import.meta/import-meta-is-an-ordinary-object.js"><reason></reason></test>
312303
<test id="language/expressions/import.meta/same-object-returned.js"><reason></reason></test>

0 commit comments

Comments
 (0)