Support resource name and user value for implicit class constructors (#4771)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-09-17 16:28:10 +02:00
committed by GitHub
parent 430289b27d
commit 053bfa0f9f
13 changed files with 471 additions and 327 deletions
+72 -55
View File
@@ -421,11 +421,8 @@ ecma_gc_mark_properties (ecma_object_t *object_p, /**< object */
* Mark compiled code.
*/
static void
ecma_gc_mark_compiled_code (const ecma_compiled_code_t *compiled_code_p) /**< compiled code */
ecma_gc_mark_compiled_code (ecma_value_t script_value) /**< script value */
{
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
ecma_value_t script_value = ((cbc_uint8_arguments_t *) compiled_code_p)->script_value;
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
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 */
const ecma_compiled_code_t *compiled_code_p;
compiled_code_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
ext_object_p->u.cls.u3.value);
ecma_gc_mark_compiled_code (compiled_code_p);
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
break;
}
#endif /* JERRY_PARSER */
@@ -934,7 +933,10 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE)
&& module_p->u.compiled_code_p != NULL)
{
ecma_gc_mark_compiled_code (module_p->u.compiled_code_p);
const ecma_compiled_code_t *compiled_code_p = module_p->u.compiled_code_p;
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
}
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 */
break;
}
#endif /* JERRY_BUILTIN_PROXY */
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ecma_gc_mark_bound_function_object (object_p);
break;
}
case ECMA_OBJECT_TYPE_FUNCTION:
{
ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) object_p;
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
ext_func_p->u.function.scope_cp));
const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code (ext_func_p);
const ecma_compiled_code_t *compiled_code_p = ecma_op_function_get_compiled_code (ext_func_p);
#if JERRY_ESNEXT
if (CBC_FUNCTION_IS_ARROW (byte_code_p->status_flags))
if (CBC_FUNCTION_IS_ARROW (compiled_code_p->status_flags))
{
ecma_arrow_function_t *arrow_func_p = (ecma_arrow_function_t *) object_p;
@@ -1126,25 +1123,22 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
#endif /* JERRY_ESNEXT */
#if JERRY_SNAPSHOT_EXEC
if (JERRY_UNLIKELY (byte_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
if (JERRY_UNLIKELY (compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
{
/* Static snapshot functions have a global realm */
break;
}
#endif /* JERRY_SNAPSHOT_EXEC */
ecma_gc_mark_compiled_code (byte_code_p);
JERRY_ASSERT (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION));
ecma_gc_mark_compiled_code (((cbc_uint8_arguments_t *) compiled_code_p)->script_value);
break;
}
#if JERRY_BUILTIN_REALMS
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
native_function_p->realm_value));
ecma_gc_mark_bound_function_object (object_p);
break;
}
#endif /* JERRY_BUILTIN_REALMS */
#if JERRY_ESNEXT || JERRY_BUILTIN_REALMS
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
{
@@ -1226,6 +1220,22 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
break;
}
#endif /* JERRY_ESNEXT || JERRY_BUILTIN_REALMS */
#if JERRY_ESNEXT
case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION:
{
ecma_gc_mark_compiled_code (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value);
break;
}
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_REALMS
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
{
ecma_native_function_t *native_function_p = (ecma_native_function_t *) object_p;
ecma_gc_set_object_visited (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
native_function_p->realm_value));
break;
}
#endif /* JERRY_BUILTIN_REALMS */
default:
{
break;
@@ -1974,40 +1984,6 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
#endif /* JERRY_SNAPSHOT_EXEC */
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ext_object_size = sizeof (ecma_bound_function_t);
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
#if JERRY_ESNEXT
ecma_free_value (bound_func_p->target_length);
#endif /* JERRY_ESNEXT */
if (!ecma_is_value_integer_number (args_len_or_this))
{
ecma_free_value_if_not_object (args_len_or_this);
break;
}
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
for (ecma_integer_value_t i = 0; i < args_length; i++)
{
ecma_free_value_if_not_object (args_p[i]);
}
size_t args_size = ((size_t) args_length) * sizeof (ecma_value_t);
ext_object_size += args_size;
break;
}
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
{
ext_object_size = sizeof (ecma_native_function_t);
break;
}
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
{
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 */
#endif /* JERRY_ESNEXT */
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
ext_object_size = sizeof (ecma_bound_function_t);
ecma_bound_function_t *bound_func_p = (ecma_bound_function_t *) object_p;
ecma_value_t args_len_or_this = bound_func_p->header.u.bound_function.args_len_or_this;
#if JERRY_ESNEXT
ecma_free_value (bound_func_p->target_length);
#endif /* JERRY_ESNEXT */
if (!ecma_is_value_integer_number (args_len_or_this))
{
ecma_free_value_if_not_object (args_len_or_this);
break;
}
ecma_integer_value_t args_length = ecma_get_integer_from_value (args_len_or_this);
ecma_value_t *args_p = (ecma_value_t *) (bound_func_p + 1);
for (ecma_integer_value_t i = 0; i < args_length; i++)
{
ecma_free_value_if_not_object (args_p[i]);
}
size_t args_size = ((size_t) args_length) * sizeof (ecma_value_t);
ext_object_size += args_size;
break;
}
#if JERRY_ESNEXT
case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION:
{
ecma_script_deref (((ecma_extended_object_t *) object_p)->u.constructor_function.script_value);
break;
}
#endif /* JERRY_ESNEXT */
case ECMA_OBJECT_TYPE_NATIVE_FUNCTION:
{
ext_object_size = sizeof (ecma_native_function_t);
break;
}
default:
{
JERRY_UNREACHABLE ();
+25 -5
View File
@@ -715,9 +715,10 @@ typedef enum
ECMA_OBJECT_TYPE_PROXY = 6, /**< Proxy object ECMAScript v6 26.2 */
/* Note: these 4 types must be in this order. See IsCallable operation. */
ECMA_OBJECT_TYPE_FUNCTION = 7, /**< Function objects (15.3), created through 13.2 routine */
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 8, /**< Function objects (15.3), created through 15.3.4.5 routine */
ECMA_OBJECT_TYPE_NATIVE_FUNCTION = 9, /**< Native function object */
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION = 10, /**< Native built-in function object */
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION = 8, /**< Native built-in function object */
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 9, /**< Function objects (15.3), created through 15.3.4.5 routine */
ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION = 10, /**< implicit class constructor function */
ECMA_OBJECT_TYPE_NATIVE_FUNCTION = 11, /**< Native function object */
ECMA_OBJECT_TYPE__MAX /**< maximum value */
} ecma_object_type_t;
@@ -1161,6 +1162,17 @@ typedef struct
jmem_cpointer_tag_t target_function; /**< target function */
ecma_value_t args_len_or_this; /**< length of arguments or this value */
} bound_function;
#if JERRY_ESNEXT
/**
* Description of implicit class constructor function.
*/
struct
{
ecma_value_t script_value; /**< script value */
uint8_t flags; /**< constructor flags */
} constructor_function;
#endif /* JERRY_ESNEXT */
} u;
} ecma_extended_object_t;
@@ -2477,8 +2489,8 @@ typedef struct
*/
typedef enum
{
ECMA_DATE_TZA_NONE = 0,
ECMA_DATE_TZA_SET = 1 << 0,
ECMA_DATE_TZA_NONE = 0, /**< no time-zone adjustment is set */
ECMA_DATE_TZA_SET = (1 << 0), /**< time-zone adjustment is set */
} ecma_date_object_flags_t;
/**
@@ -2490,6 +2502,14 @@ typedef struct
ecma_number_t date_value; /**< [[DateValue]] internal property */
} ecma_date_object_t;
/**
* Implicit class constructor flags
*/
typedef enum
{
ECMA_CONSTRUCTOR_FUNCTION_HAS_HERITAGE = (1 << 0), /**< heritage object is present */
} ecma_constructor_function_flags_t;
#endif /* JERRY_ESNEXT */
/**
+84 -60
View File
@@ -1406,6 +1406,63 @@ ecma_raise_error_from_error_reference (ecma_value_t value) /**< error reference
JERRY_CONTEXT (error_value) = referenced_value;
} /* ecma_raise_error_from_error_reference */
/**
* Decrease the reference counter of a script value.
*/
void
ecma_script_deref (ecma_value_t script_value) /**< script value */
{
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
script_p->refs_and_type -= CBC_SCRIPT_REF_ONE;
if (script_p->refs_and_type >= CBC_SCRIPT_REF_ONE)
{
return;
}
size_t script_size = sizeof (cbc_script_t);
uint32_t type = script_p->refs_and_type;
if (type & CBC_SCRIPT_HAS_USER_VALUE)
{
script_size += sizeof (ecma_value_t);
if (!(type & CBC_SCRIPT_USER_VALUE_IS_OBJECT))
{
ecma_value_t user_value = CBC_SCRIPT_GET_USER_VALUE (script_p);
JERRY_ASSERT (!ecma_is_value_object (user_value));
ecma_free_value (user_value);
}
}
#if JERRY_RESOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->resource_name));
#endif /* JERRY_RESOURCE_NAME */
#if JERRY_MODULE_SYSTEM
if (type & CBC_SCRIPT_HAS_IMPORT_META)
{
JERRY_ASSERT (!(type & CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS));
JERRY_ASSERT (ecma_is_value_object (CBC_SCRIPT_GET_IMPORT_META (script_p, type)));
script_size += sizeof (ecma_value_t);
}
#endif /* JERRY_MODULE_SYSTEM */
#if JERRY_FUNCTION_TO_STRING
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->source_code));
if (type & CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS)
{
ecma_deref_ecma_string (ecma_get_string_from_value (CBC_SCRIPT_GET_FUNCTION_ARGUMENTS (script_p, type)));
script_size += sizeof (ecma_value_t);
}
#endif /* JERRY_FUNCTION_TO_STRING */
jmem_heap_free_block (script_p, script_size);
} /* ecma_script_deref */
/**
* Increase reference counter of Compact
* Byte Code or regexp byte code.
@@ -1478,53 +1535,7 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
}
}
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
script_p->refs_and_type -= CBC_SCRIPT_REF_ONE;
if (script_p->refs_and_type < CBC_SCRIPT_REF_ONE)
{
size_t script_size = sizeof (cbc_script_t);
uint32_t type = script_p->refs_and_type;
if (type & CBC_SCRIPT_HAS_USER_VALUE)
{
script_size += sizeof (ecma_value_t);
if (!(type & CBC_SCRIPT_USER_VALUE_IS_OBJECT))
{
ecma_value_t user_value = CBC_SCRIPT_GET_USER_VALUE (script_p);
JERRY_ASSERT (!ecma_is_value_object (user_value));
ecma_free_value (user_value);
}
}
#if JERRY_RESOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->resource_name));
#endif /* JERRY_RESOURCE_NAME */
#if JERRY_MODULE_SYSTEM
if (type & CBC_SCRIPT_HAS_IMPORT_META)
{
JERRY_ASSERT (ecma_is_value_object (CBC_SCRIPT_GET_IMPORT_META (script_p, type)));
script_size += sizeof (ecma_value_t);
}
#endif /* JERRY_MODULE_SYSTEM */
#if JERRY_FUNCTION_TO_STRING
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->source_code));
if (type & CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS)
{
ecma_deref_ecma_string (ecma_get_string_from_value (CBC_SCRIPT_GET_FUNCTION_ARGUMENTS (script_p, type)));
script_size += sizeof (ecma_value_t);
}
#endif /* JERRY_FUNCTION_TO_STRING */
jmem_heap_free_block (script_p, script_size);
}
ecma_script_deref (((cbc_uint8_arguments_t *) bytecode_p)->script_value);
#if JERRY_ESNEXT
if (bytecode_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
@@ -1597,19 +1608,20 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
} /* ecma_bytecode_deref */
/**
* Gets the byte code asigned to a script / module / function
* Gets the script data asigned to a script / module / function
*
* @return byte code - if available, NULL - otherwise
* @return script data - if available, JMEM_CP_NULL - otherwise
*/
const ecma_compiled_code_t *
ecma_bytecode_get_from_value (ecma_value_t value) /**< compiled code */
ecma_value_t
ecma_script_get_from_value (ecma_value_t value) /**< compiled code */
{
if (!ecma_is_value_object (value))
{
return NULL;
return JMEM_CP_NULL;
}
ecma_object_t *object_p = ecma_get_object_from_value (value);
const ecma_compiled_code_t *bytecode_p = NULL;
while (true)
{
@@ -1621,8 +1633,9 @@ ecma_bytecode_get_from_value (ecma_value_t value) /**< compiled code */
if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_SCRIPT)
{
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
ext_object_p->u.cls.u3.value);
bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
ext_object_p->u.cls.u3.value);
break;
}
#if JERRY_MODULE_SYSTEM
@@ -1632,15 +1645,17 @@ ecma_bytecode_get_from_value (ecma_value_t value) /**< compiled code */
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE))
{
return module_p->u.compiled_code_p;
bytecode_p = module_p->u.compiled_code_p;
break;
}
}
#endif /* JERRY_MODULE_SYSTEM */
return NULL;
return JMEM_CP_NULL;
}
case ECMA_OBJECT_TYPE_FUNCTION:
{
return ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p);
bytecode_p = ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p);
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
{
@@ -1648,15 +1663,24 @@ ecma_bytecode_get_from_value (ecma_value_t value) /**< compiled code */
object_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
ext_object_p->u.bound_function.target_function);
break;
continue;
}
#if JERRY_ESNEXT
case ECMA_OBJECT_TYPE_CONSTRUCTOR_FUNCTION:
{
return ((ecma_extended_object_t *) object_p)->u.constructor_function.script_value;
}
#endif /* JERRY_ESNEXT */
default:
{
return NULL;
return JMEM_CP_NULL;
}
}
JERRY_ASSERT (bytecode_p != NULL);
return ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
}
} /* ecma_bytecode_get_from_value */
} /* ecma_script_get_from_value */
/**
* Resolve the position of the arguments list start of the compiled code
+2 -1
View File
@@ -531,9 +531,10 @@ ecma_value_t ecma_create_error_reference_from_context (void);
ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p);
void ecma_raise_error_from_error_reference (ecma_value_t value);
void ecma_script_deref (ecma_value_t script_value);
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
const ecma_compiled_code_t *ecma_bytecode_get_from_value (ecma_value_t value);
ecma_value_t ecma_script_get_from_value (ecma_value_t value);
ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p);
#if JERRY_ESNEXT
ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p);