Implement the for of statement (#2871)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Dániel Bátyai
parent
b6fc4e13ae
commit
343e80053b
@@ -79,6 +79,16 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
|
||||
vm_stack_top_p -= PARSER_WITH_CONTEXT_STACK_ALLOCATION;
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_FOR_OF)
|
||||
case VM_CONTEXT_FOR_OF:
|
||||
{
|
||||
ecma_free_value (vm_stack_top_p[-2]);
|
||||
ecma_free_value (vm_stack_top_p[-3]);
|
||||
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION);
|
||||
vm_stack_top_p -= PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_FOR_OF) */
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (vm_stack_top_p[-1]) == VM_CONTEXT_FOR_IN);
|
||||
|
||||
@@ -44,6 +44,9 @@ typedef enum
|
||||
VM_CONTEXT_SUPER_CLASS, /**< super class context */
|
||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
||||
VM_CONTEXT_FOR_IN, /**< for-in context */
|
||||
#if ENABLED (JERRY_ES2015_FOR_OF)
|
||||
VM_CONTEXT_FOR_OF, /**< for-of context */
|
||||
#endif /* ENABLED (JERRY_ES2015_FOR_OF) */
|
||||
} vm_stack_context_type_t;
|
||||
|
||||
ecma_value_t *vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, ecma_value_t *vm_stack_top_p);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-lcache.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
@@ -2888,6 +2889,93 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015_FOR_OF)
|
||||
case VM_OC_FOR_OF_CREATE_CONTEXT:
|
||||
{
|
||||
ecma_value_t value = *(--stack_top_p);
|
||||
|
||||
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
ecma_value_t iterator = ecma_op_get_iterator (value, ECMA_VALUE_EMPTY);
|
||||
|
||||
ecma_free_value (value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (iterator))
|
||||
{
|
||||
result = iterator;
|
||||
goto error;
|
||||
}
|
||||
|
||||
ecma_value_t iterator_step = ecma_op_iterator_step (iterator);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (iterator_step))
|
||||
{
|
||||
ecma_free_value (iterator);
|
||||
result = iterator_step;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ecma_is_value_false (iterator_step))
|
||||
{
|
||||
ecma_free_value (iterator);
|
||||
byte_code_p = byte_code_start_p + branch_offset;
|
||||
continue;
|
||||
}
|
||||
|
||||
branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p);
|
||||
|
||||
VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION);
|
||||
stack_top_p += PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION;
|
||||
stack_top_p[-1] = (ecma_value_t) VM_CREATE_CONTEXT (VM_CONTEXT_FOR_OF, branch_offset);
|
||||
stack_top_p[-2] = iterator_step;
|
||||
stack_top_p[-3] = iterator;
|
||||
|
||||
continue;
|
||||
}
|
||||
case VM_OC_FOR_OF_GET_NEXT:
|
||||
{
|
||||
ecma_value_t *context_top_p = frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth;
|
||||
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_OF);
|
||||
|
||||
ecma_value_t next_value = ecma_op_iterator_value (context_top_p[-2]);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (next_value))
|
||||
{
|
||||
result = next_value;
|
||||
goto error;
|
||||
}
|
||||
|
||||
*stack_top_p++ = next_value;
|
||||
continue;
|
||||
}
|
||||
case VM_OC_FOR_OF_HAS_NEXT:
|
||||
{
|
||||
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
ecma_value_t iterator_step = ecma_op_iterator_step (stack_top_p[-3]);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (iterator_step))
|
||||
{
|
||||
result = iterator_step;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_false (iterator_step))
|
||||
{
|
||||
ecma_free_value (stack_top_p[-2]);
|
||||
stack_top_p[-2] = iterator_step;
|
||||
byte_code_p = byte_code_start_p + branch_offset;
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_free_value (stack_top_p[-2]);
|
||||
ecma_free_value (stack_top_p[-3]);
|
||||
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION);
|
||||
stack_top_p -= PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION;
|
||||
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_FOR_OF) */
|
||||
case VM_OC_TRY:
|
||||
{
|
||||
/* Try opcode simply creates the try context. */
|
||||
|
||||
@@ -207,6 +207,11 @@ typedef enum
|
||||
VM_OC_FOR_IN_CREATE_CONTEXT, /**< for in create context */
|
||||
VM_OC_FOR_IN_GET_NEXT, /**< get next */
|
||||
VM_OC_FOR_IN_HAS_NEXT, /**< has next */
|
||||
#if ENABLED (JERRY_ES2015_FOR_OF)
|
||||
VM_OC_FOR_OF_CREATE_CONTEXT, /**< for of create context */
|
||||
VM_OC_FOR_OF_GET_NEXT, /**< get next */
|
||||
VM_OC_FOR_OF_HAS_NEXT, /**< has next */
|
||||
#endif /* ENABLED (JERRY_ES2015_FOR_OF) */
|
||||
VM_OC_TRY, /**< try */
|
||||
VM_OC_CATCH, /**< catch */
|
||||
VM_OC_FINALLY, /**< finally */
|
||||
@@ -269,6 +274,11 @@ typedef enum
|
||||
VM_OC_PUSH_CONSTRUCTOR_THIS = VM_OC_NONE, /**< push 'this' inside a class constructor */
|
||||
VM_OC_CONSTRUCTOR_RET = VM_OC_NONE, /**< explicit return from a class constructor */
|
||||
#endif /* !ENABLED (JERRY_ES2015_CLASS) */
|
||||
#if !ENABLED (JERRY_ES2015_FOR_OF)
|
||||
VM_OC_FOR_OF_CREATE_CONTEXT = VM_OC_NONE, /**< for of create context */
|
||||
VM_OC_FOR_OF_GET_NEXT = VM_OC_NONE, /**< get next */
|
||||
VM_OC_FOR_OF_HAS_NEXT = VM_OC_NONE, /**< has next */
|
||||
#endif /* !ENABLED (JERRY_ES2015_FOR_OF) */
|
||||
VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */
|
||||
} vm_oc_unused_types;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user