Implement throwing ReferenceErrors for let/const variables. (#3264)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2019-10-31 11:09:02 +01:00
committed by Dániel Bátyai
parent d1faed7d03
commit 6a342fcdd6
16 changed files with 306 additions and 75 deletions
+33 -2
View File
@@ -828,9 +828,17 @@ vm_init_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
{
prop_attributes = ECMA_PROPERTY_FLAG_ENUMERABLE;
}
#endif /* ENABLED (JERRY_ES2015) */
ecma_property_value_t *property_value_p;
property_value_p = ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, prop_attributes, NULL);
if (type != CBC_CREATE_LOCAL)
{
property_value_p->value = ECMA_VALUE_UNINITIALIZED;
}
#else /* !ENABLED (JERRY_ES2015) */
ecma_create_named_data_property (frame_ctx_p->lex_env_p, name_p, prop_attributes, NULL);
#endif /* ENABLED (JERRY_ES2015) */
break;
}
@@ -1307,6 +1315,29 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
continue;
}
#if ENABLED (JERRY_ES2015)
case VM_OC_ASSIGN_LET_CONST:
{
uint32_t literal_index;
READ_LITERAL_INDEX (literal_index);
JERRY_ASSERT (literal_index >= register_end);
JERRY_ASSERT (ecma_get_lex_env_type (frame_ctx_p->lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
ecma_string_t *name_p = ecma_get_string_from_value (literal_start_p[literal_index]);
ecma_property_t *property_p = ecma_find_named_property (frame_ctx_p->lex_env_p, name_p);
JERRY_ASSERT (property_p != NULL
&& ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA);
JERRY_ASSERT (ECMA_PROPERTY_VALUE_PTR (property_p)->value == ECMA_VALUE_UNINITIALIZED);
ECMA_PROPERTY_VALUE_PTR (property_p)->value = left_value;
if (ecma_is_value_object (left_value))
{
ecma_deref_object (ecma_get_object_from_value (left_value));
}
continue;
}
case VM_OC_SET_COMPUTED_PROPERTY:
{
/* Swap values. */
@@ -2012,7 +2043,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
case VM_OC_MOV_IDENT:
{
uint16_t literal_index;
uint32_t literal_index;
READ_LITERAL_INDEX (literal_index);
+2
View File
@@ -225,6 +225,7 @@ typedef enum
VM_OC_LINE, /**< line number of the next statement */
#endif /* ENABLED (JERRY_LINE_INFO) */
#if ENABLED (JERRY_ES2015)
VM_OC_ASSIGN_LET_CONST, /**< assign values to let/const declarations */
VM_OC_SET_COMPUTED_PROPERTY, /**< set computed property */
VM_OC_FOR_OF_CREATE_CONTEXT, /**< for of create context */
@@ -262,6 +263,7 @@ typedef enum
VM_OC_LINE = VM_OC_NONE, /**< line number of the next statement is unused */
#endif /* !ENABLED (JERRY_LINE_INFO) */
#if !ENABLED (JERRY_ES2015)
VM_OC_ASSIGN_LET_CONST = VM_OC_NONE, /**< assign values to let/const declarations */
VM_OC_SET_COMPUTED_PROPERTY = VM_OC_NONE, /**< set computed property is unused */
VM_OC_BLOCK_CREATE_CONTEXT = VM_OC_NONE, /**< create context for blocks enclosed in braces */