Add iterator close support for for-of statement (#3401)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-01-13 17:38:47 +01:00
committed by GitHub
parent f1dd59e4bd
commit be8ae3aae8
5 changed files with 290 additions and 6 deletions
+1 -1
View File
@@ -815,7 +815,7 @@ ecma_gc_free_executable_object (ecma_object_t *object_p) /**< object */
do
{
context_top_p[-1] &= (uint32_t) ~VM_CONTEXT_HAS_LEX_ENV;
context_top_p[-1] &= (uint32_t) ~(VM_CONTEXT_HAS_LEX_ENV | VM_CONTEXT_CLOSE_ITERATOR);
uint32_t offsets = vm_get_context_value_offsets (context_top_p);
+9 -1
View File
@@ -18,6 +18,7 @@
#include "ecma-helpers.h"
#include "vm-defines.h"
#include "vm-stack.h"
#include "ecma-iterator-object.h"
/** \addtogroup vm Virtual machine
* @{
@@ -79,8 +80,15 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
#if ENABLED (JERRY_ES2015)
case VM_CONTEXT_FOR_OF:
{
ecma_value_t iterator = vm_stack_top_p[-3];
if (context_info & VM_CONTEXT_CLOSE_ITERATOR)
{
ecma_op_iterator_close (iterator);
}
ecma_free_value (iterator);
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;
+8 -3
View File
@@ -28,13 +28,13 @@
/**
* Create context on the vm stack.
*/
#define VM_CREATE_CONTEXT(type, end_offset) ((ecma_value_t) ((type) | ((end_offset) << 6)))
#define VM_CREATE_CONTEXT(type, end_offset) ((ecma_value_t) ((type) | ((end_offset) << 7)))
/**
* Create context on the vm stack with environment.
*/
#define VM_CREATE_CONTEXT_WITH_ENV(type, end_offset) \
((ecma_value_t) ((type) | ((end_offset) << 6) | VM_CONTEXT_HAS_LEX_ENV))
(VM_CREATE_CONTEXT ((type),(end_offset)) | VM_CONTEXT_HAS_LEX_ENV)
/**
* Get type of a vm context.
@@ -44,13 +44,18 @@
/**
* Get the end position of a vm context.
*/
#define VM_GET_CONTEXT_END(value) ((value) >> 6)
#define VM_GET_CONTEXT_END(value) ((value) >> 7)
/**
* This flag is set if the context has a lexical environment.
*/
#define VM_CONTEXT_HAS_LEX_ENV 0x20
/**
* This flag is set if the iterator close operation should be invoked during a for-of context break.
*/
#define VM_CONTEXT_CLOSE_ITERATOR 0x40
/**
* Context types for the vm stack.
*/
+28 -1
View File
@@ -3485,7 +3485,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
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] = VM_CREATE_CONTEXT (VM_CONTEXT_FOR_OF, branch_offset);
stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_FOR_OF, branch_offset) | VM_CONTEXT_CLOSE_ITERATOR;
stack_top_p[-2] = next_value;
stack_top_p[-3] = iterator;
@@ -3587,6 +3587,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
case VM_OC_CONTEXT_END:
{
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
JERRY_ASSERT (!(stack_top_p[-1] & VM_CONTEXT_CLOSE_ITERATOR));
ecma_value_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]);
@@ -3653,6 +3654,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
case VM_OC_JUMP_AND_EXIT_CONTEXT:
{
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
JERRY_ASSERT (!jcontext_has_pending_exception ());
branch_offset += (int32_t) (byte_code_start_p - frame_ctx_p->byte_code_start_p);
@@ -3670,6 +3672,14 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
byte_code_p = frame_ctx_p->byte_code_start_p + branch_offset;
}
#if ENABLED (JERRY_ES2015)
if (jcontext_has_pending_exception ())
{
result = ECMA_VALUE_ERROR;
goto error;
}
#endif /* ENABLED (JERRY_ES2015) */
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
continue;
}
@@ -3944,10 +3954,27 @@ error:
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_FINALLY_RETURN);
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
#if ENABLED (JERRY_ES2015)
if (jcontext_has_pending_exception ())
{
stack_top_p[-1] = (ecma_value_t) (stack_top_p[-1] - VM_CONTEXT_FINALLY_RETURN + VM_CONTEXT_FINALLY_THROW);
ecma_free_value (result);
result = jcontext_take_exception ();
}
#endif /* ENABLED (JERRY_ES2015) */
byte_code_p = frame_ctx_p->byte_code_p;
stack_top_p[-2] = result;
continue;
}
#if ENABLED (JERRY_ES2015)
if (jcontext_has_pending_exception ())
{
ecma_free_value (result);
result = ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ES2015) */
}
else if (jcontext_has_pending_exception () && !jcontext_has_pending_abort ())
{