Implement environment record for class constructors (#4207)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-10-12 13:13:38 +02:00
committed by GitHub
parent d317124650
commit 3c2a3f5dd9
11 changed files with 220 additions and 95 deletions
+2 -2
View File
@@ -1557,9 +1557,9 @@ opfunc_form_super_reference (ecma_value_t **vm_stack_top_p, /**< current vm stac
{
if (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) == CBC_FUNCTION_CONSTRUCTOR)
{
ecma_property_t *prop_p = ecma_op_get_this_property (frame_ctx_p->lex_env_p);
ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p);
if (!ecma_op_this_binding_is_initialized (prop_p))
if (!ecma_op_this_binding_is_initialized (environment_record_p))
{
return ecma_raise_reference_error (ECMA_ERR_MSG ("Must call super constructor in derived class before "
"accessing 'this' or returning from it."));
+12 -12
View File
@@ -528,17 +528,17 @@ static const uint8_t vm_error_byte_code_p[] =
static ecma_object_t *
vm_get_class_function (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
{
while (true)
JERRY_ASSERT (frame_ctx_p != NULL);
if (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_NON_ARROW_FUNC)
{
JERRY_ASSERT (frame_ctx_p != NULL);
if (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_NON_ARROW_FUNC)
{
return VM_FRAME_CTX_GET_FUNCTION_OBJECT (frame_ctx_p);
}
frame_ctx_p = frame_ctx_p->prev_context_p;
return VM_FRAME_CTX_GET_FUNCTION_OBJECT (frame_ctx_p);
}
ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p);
JERRY_ASSERT (environment_record_p != NULL);
return ecma_get_object_from_value (environment_record_p->function_object);
} /* vm_get_class_function */
/**
@@ -575,7 +575,7 @@ vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
ecma_value_t func_value = *(--frame_ctx_p->stack_top_p);
ecma_value_t completion_value;
ecma_property_t *prop_p = ecma_op_get_this_property (frame_ctx_p->lex_env_p);
ecma_environment_record_t *environment_record_p = ecma_op_get_environment_record (frame_ctx_p->lex_env_p);
if (!ecma_is_constructor (func_value))
{
@@ -606,7 +606,7 @@ vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
ecma_free_value (proto_value);
}
if (!ECMA_IS_VALUE_ERROR (completion_value) && ecma_op_this_binding_is_initialized (prop_p))
if (!ECMA_IS_VALUE_ERROR (completion_value) && ecma_op_this_binding_is_initialized (environment_record_p))
{
ecma_free_value (completion_value);
completion_value = ecma_raise_reference_error (ECMA_ERR_MSG ("Super constructor may only be called once"));
@@ -647,7 +647,7 @@ vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
else
{
ecma_op_bind_this_value (prop_p, completion_value);
ecma_op_bind_this_value (environment_record_p, completion_value);
frame_ctx_p->this_binding = completion_value;
frame_ctx_p->byte_code_p = byte_code_p;