Skip to content

Commit 053bfa0

Browse files
authored
Support resource name and user value for implicit class constructors (#4771)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 430289b commit 053bfa0

13 files changed

+469
-325
lines changed

jerry-core/api/jerry.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -5468,15 +5468,14 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
54685468
return ecma_copy_value (ecma_get_resource_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p));
54695469
}
54705470

5471-
const ecma_compiled_code_t *bytecode_p = ecma_bytecode_get_from_value (value);
5471+
ecma_value_t script_value = ecma_script_get_from_value (value);
54725472

5473-
if (bytecode_p == NULL)
5473+
if (script_value == JMEM_CP_NULL)
54745474
{
54755475
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
54765476
}
54775477

5478-
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
5479-
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
5478+
const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
54805479

54815480
return ecma_copy_value (script_p->resource_name);
54825481
#else /* !JERRY_RESOURCE_NAME */
@@ -5497,15 +5496,14 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
54975496
jerry_value_t
54985497
jerry_get_user_value (const jerry_value_t value) /**< jerry api value */
54995498
{
5500-
const ecma_compiled_code_t *bytecode_p = ecma_bytecode_get_from_value (value);
5499+
ecma_value_t script_value = ecma_script_get_from_value (value);
55015500

5502-
if (bytecode_p == NULL)
5501+
if (script_value == JMEM_CP_NULL)
55035502
{
55045503
return ECMA_VALUE_UNDEFINED;
55055504
}
55065505

5507-
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
5508-
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
5506+
const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
55095507

55105508
if (!(script_p->refs_and_type & CBC_SCRIPT_HAS_USER_VALUE))
55115509
{

jerry-core/ecma/base/ecma-gc.c

+72-55
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,8 @@ ecma_gc_mark_properties (ecma_object_t *object_p, /**< object */
421421
* Mark compiled code.
422422
*/
423423
static void
424-
ecma_gc_mark_compiled_code (const ecma_compiled_code_t *compiled_code_p) /**< compiled code */
424+
ecma_gc_mark_compiled_code (ecma_value_t script_value) /**< script value */
425425
{
426-
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
427-
428-
ecma_value_t script_value = ((cbc_uint8_arguments_t *) compiled_code_p)->script_value;
429426
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
430427

431428
if (script_p->refs_and_type & CBC_SCRIPT_USER_VALUE_IS_OBJECT)
@@ -895,7 +892,9 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
895892
const ecma_compiled_code_t *compiled_code_p;
896893
compiled_code_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
897894
ext_object_p->u.cls.u3.value);
898-
ecma_gc_mark_compiled_code (compiled_code_p);
895+
896+
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
897+
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
899898
break;
900899
}
901900
#endif /* JERRY_PARSER */
@@ -934,7 +933,10 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
934933
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE)
935934
&& module_p->u.compiled_code_p != NULL)
936935
{
937-
ecma_gc_mark_compiled_code (module_p->u.compiled_code_p);
936+
const ecma_compiled_code_t *compiled_code_p = module_p->u.compiled_code_p;
937+
938+
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
939+
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
938940
}
939941

940942
ecma_module_node_t *node_p = module_p->imports_p;
@@ -1095,21 +1097,16 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
10951097
break;
10961098
}
10971099
#endif /* JERRY_BUILTIN_PROXY */
1098-
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
1099-
{
1100-
ecma_gc_mark_bound_function_object (object_p);
1101-
break;
1102-
}
11031100
case ECMA_OBJECT_TYPE_FUNCTION:
11041101
{
11051102
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
11061103
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
11071104
ext_func_p->u.function.scope_cp));
11081105

1109-
const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code (ext_func_p);
1106+
const ecma_compiled_code_t *compiled_code_p = ecma_op_function_get_compiled_code (ext_func_p);
11101107

11111108
#if JERRY_ESNEXT
1112-
if (CBC_FUNCTION_IS_ARROW (byte_code_p->status_flags))
1109+
if (CBC_FUNCTION_IS_ARROW (compiled_code_p->status_flags))
11131110
{
11141111
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;
11151112

@@ -1126,25 +1123,22 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
11261123
#endif /* JERRY_ESNEXT */
11271124

11281125
#if JERRY_SNAPSHOT_EXEC
1129-
if (JERRY_UNLIKELY (byte_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
1126+
if (JERRY_UNLIKELY (compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
11301127
{
11311128
/* Static snapshot functions have a global realm */
11321129
break;
11331130
}
11341131
#endif /* JERRY_SNAPSHOT_EXEC */
11351132

1136-
ecma_gc_mark_compiled_code (byte_code_p);
1133+
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
1134+
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
11371135
break;
11381136
}
1139-
#if JERRY_BUILTIN_REALMS
1140-
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
1137+
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
11411138
{
1142-
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
1143-
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
1144-
native_function_p->realm_value));
1139+
ecma_gc_mark_bound_function_object (object_p);
11451140
break;
11461141
}
1147-
#endif /* JERRY_BUILTIN_REALMS */
11481142
#if JERRY_ESNEXT || JERRY_BUILTIN_REALMS
11491143
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
11501144
{
@@ -1226,6 +1220,22 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
12261220
break;
12271221
}
12281222
#endif /* JERRY_ESNEXT || JERRY_BUILTIN_REALMS */
1223+
#if JERRY_ESNEXT
1224+
case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION:
1225+
{
1226+
ecma_gc_mark_compiled_code (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value);
1227+
break;
1228+
}
1229+
#endif /* JERRY_ESNEXT */
1230+
#if JERRY_BUILTIN_REALMS
1231+
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
1232+
{
1233+
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
1234+
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
1235+
native_function_p->realm_value));
1236+
break;
1237+
}
1238+
#endif /* JERRY_BUILTIN_REALMS */
12291239
default:
12301240
{
12311241
break;
@@ -1974,40 +1984,6 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
19741984
#endif /* JERRY_SNAPSHOT_EXEC */
19751985
break;
19761986
}
1977-
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
1978-
{
1979-
ext_object_size = sizeof (ecma_bound_function_t);
1980-
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
1981-
1982-
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
1983-
1984-
#if JERRY_ESNEXT
1985-
ecma_free_value (bound_func_p->target_length);
1986-
#endif /* JERRY_ESNEXT */
1987-
1988-
if (!ecma_is_value_integer_number (args_len_or_this))
1989-
{
1990-
ecma_free_value_if_not_object (args_len_or_this);
1991-
break;
1992-
}
1993-
1994-
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
1995-
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
1996-
1997-
for (ecma_integer_value_t i = 0; i < args_length; i++)
1998-
{
1999-
ecma_free_value_if_not_object (args_p[i]);
2000-
}
2001-
2002-
size_t args_size = ((size_t) args_length) * sizeof (ecma_value_t);
2003-
ext_object_size += args_size;
2004-
break;
2005-
}
2006-
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
2007-
{
2008-
ext_object_size = sizeof (ecma_native_function_t);
2009-
break;
2010-
}
20111987
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
20121988
{
20131989
ecma_extended_object_t *extended_func_p = (ecma_extended_object_t *) object_p;
@@ -2071,6 +2047,47 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
20712047
#endif /* JERRY_ESNEXT */
20722048
break;
20732049
}
2050+
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
2051+
{
2052+
ext_object_size = sizeof (ecma_bound_function_t);
2053+
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
2054+
2055+
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
2056+
2057+
#if JERRY_ESNEXT
2058+
ecma_free_value (bound_func_p->target_length);
2059+
#endif /* JERRY_ESNEXT */
2060+
2061+
if (!ecma_is_value_integer_number (args_len_or_this))
2062+
{
2063+
ecma_free_value_if_not_object (args_len_or_this);
2064+
break;
2065+
}
2066+
2067+
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
2068+
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
2069+
2070+
for (ecma_integer_value_t i = 0; i < args_length; i++)
2071+
{
2072+
ecma_free_value_if_not_object (args_p[i]);
2073+
}
2074+
2075+
size_t args_size = ((size_t) args_length) * sizeof (ecma_value_t);
2076+
ext_object_size += args_size;
2077+
break;
2078+
}
2079+
#if JERRY_ESNEXT
2080+
case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION:
2081+
{
2082+
ecma_script_deref (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value);
2083+
break;
2084+
}
2085+
#endif /* JERRY_ESNEXT */
2086+
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
2087+
{
2088+
ext_object_size = sizeof (ecma_native_function_t);
2089+
break;
2090+
}
20742091
default:
20752092
{
20762093
JERRY_UNREACHABLE ();

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

+25-5
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,10 @@ typedef enum
715715
ECMA_OBJECT_TYPE_PROXY = 6, /**< Proxy object ECMAScript v6 26.2 */
716716
/* Note: these 4 types must be in this order. See IsCallable operation. */
717717
ECMA_OBJECT_TYPE_FUNCTION = 7, /**< Function objects (15.3), created through 13.2 routine */
718-
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 8, /**< Function objects (15.3), created through 15.3.4.5 routine */
719-
ECMA_OBJECT_TYPE_NATIVE_FUNCTION = 9, /**< Native function object */
720-
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION = 10, /**< Native built-in function object */
718+
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION = 8, /**< Native built-in function object */
719+
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 9, /**< Function objects (15.3), created through 15.3.4.5 routine */
720+
ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION = 10, /**< implicit class constructor function */
721+
ECMA_OBJECT_TYPE_NATIVE_FUNCTION = 11, /**< Native function object */
721722

722723
ECMA_OBJECT_TYPE__MAX /**< maximum value */
723724
} ecma_object_type_t;
@@ -1161,6 +1162,17 @@ typedef struct
11611162
jmem_cpointer_tag_t target_function; /**< target function */
11621163
ecma_value_t args_len_or_this; /**< length of arguments or this value */
11631164
} bound_function;
1165+
1166+
#if JERRY_ESNEXT
1167+
/**
1168+
* Description of implicit class constructor function.
1169+
*/
1170+
struct
1171+
{
1172+
ecma_value_t script_value; /**< script value */
1173+
uint8_t flags; /**< constructor flags */
1174+
} constructor_function;
1175+
#endif /* JERRY_ESNEXT */
11641176
} u;
11651177
} ecma_extended_object_t;
11661178

@@ -2477,8 +2489,8 @@ typedef struct
24772489
*/
24782490
typedef enum
24792491
{
2480-
ECMA_DATE_TZA_NONE = 0,
2481-
ECMA_DATE_TZA_SET = 1 << 0,
2492+
ECMA_DATE_TZA_NONE = 0, /**< no time-zone adjustment is set */
2493+
ECMA_DATE_TZA_SET = (1 << 0), /**< time-zone adjustment is set */
24822494
} ecma_date_object_flags_t;
24832495

24842496
/**
@@ -2490,6 +2502,14 @@ typedef struct
24902502
ecma_number_t date_value; /**< [[DateValue]] internal property */
24912503
} ecma_date_object_t;
24922504

2505+
/**
2506+
* Implicit class constructor flags
2507+
*/
2508+
typedef enum
2509+
{
2510+
ECMA_CONSTRUCTOR_FUNCTION_HAS_HERITAGE = (1 << 0), /**< heritage object is present */
2511+
} ecma_constructor_function_flags_t;
2512+
24932513
#endif /* JERRY_ESNEXT */
24942514

24952515
/**

0 commit comments

Comments
 (0)