Implement for[in/of]-let construct. (#3294)
This patch implements let/const support for all "for" statements. It includes an algorithm for cloning declarative lexical environments. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
58f71e6ffa
commit
da69589f05
@@ -1335,6 +1335,14 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case VM_OC_CLONE_CONTEXT:
|
||||
{
|
||||
JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE);
|
||||
|
||||
bool copy_values = (byte_code_start_p[1] == CBC_EXT_CLONE_FULL_CONTEXT);
|
||||
frame_ctx_p->lex_env_p = ecma_clone_decl_lexical_environment (frame_ctx_p->lex_env_p, copy_values);
|
||||
continue;
|
||||
}
|
||||
case VM_OC_SET_COMPUTED_PROPERTY:
|
||||
{
|
||||
/* Swap values. */
|
||||
@@ -3025,6 +3033,13 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
stack_top_p[-3] = 0;
|
||||
stack_top_p[-4] = expr_obj_value;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_CLONE_CONTEXT)
|
||||
{
|
||||
/* No need to duplicate the first context. */
|
||||
byte_code_p += 2;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
continue;
|
||||
}
|
||||
case VM_OC_FOR_IN_GET_NEXT:
|
||||
@@ -3124,6 +3139,11 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
stack_top_p[-2] = iterator_step;
|
||||
stack_top_p[-3] = iterator;
|
||||
|
||||
if (byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_CLONE_CONTEXT)
|
||||
{
|
||||
/* No need to duplicate the first context. */
|
||||
byte_code_p += 2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case VM_OC_FOR_OF_GET_NEXT:
|
||||
|
||||
@@ -226,6 +226,7 @@ typedef enum
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
VM_OC_ASSIGN_LET_CONST, /**< assign values to let/const declarations */
|
||||
VM_OC_CLONE_CONTEXT, /**< clone lexical environment with let/const declarations */
|
||||
VM_OC_SET_COMPUTED_PROPERTY, /**< set computed property */
|
||||
|
||||
VM_OC_FOR_OF_CREATE_CONTEXT, /**< for of create context */
|
||||
@@ -265,6 +266,7 @@ typedef enum
|
||||
#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_CLONE_CONTEXT = VM_OC_NONE, /**< clone lexical environment with 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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user