Implement array/object destructuring (#3305)
This patch implements the core functionality of destructuring patterns. Function argument/for in-of pattern are currently unsupported. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Zoltan Herczeg
parent
b4b55a67a2
commit
213544ae47
+98
-1
@@ -1791,7 +1791,104 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
*stack_top_p++ = ecma_op_create_spread_object (left_value);
|
||||
goto free_left_value;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
case VM_OC_GET_ITERATOR:
|
||||
{
|
||||
result = ecma_op_get_iterator (stack_top_p[-1], ECMA_VALUE_EMPTY);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
*stack_top_p++ = result;
|
||||
continue;
|
||||
}
|
||||
case VM_OC_ITERATOR_STEP:
|
||||
{
|
||||
const int8_t index = (opcode == CBC_EXT_ITERATOR_STEP) ? -1 : -3;
|
||||
result = ecma_op_iterator_step (stack_top_p[index]);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
ecma_value_t value = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
if (!ecma_is_value_false (result))
|
||||
{
|
||||
value = ecma_op_iterator_value (result);
|
||||
ecma_free_value (result);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
result = value;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
*stack_top_p++ = value;
|
||||
continue;
|
||||
}
|
||||
case VM_OC_DEFAULT_INITIALIZER:
|
||||
{
|
||||
if (stack_top_p[-1] != ECMA_VALUE_UNDEFINED)
|
||||
{
|
||||
byte_code_p = byte_code_start_p + branch_offset;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case VM_OC_REST_INITIALIZER:
|
||||
{
|
||||
const int8_t iterator_index = (opcode == CBC_EXT_REST_INITIALIZER) ? -1 : -3;
|
||||
ecma_object_t *array_p = ecma_op_new_fast_array_object (0);
|
||||
ecma_value_t iterator = stack_top_p[iterator_index];
|
||||
uint32_t index = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
result = ecma_op_iterator_step (iterator);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ecma_is_value_false (result))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ecma_value_t value = ecma_op_iterator_value (result);
|
||||
ecma_free_value (result);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
result = value;
|
||||
goto error;
|
||||
}
|
||||
|
||||
bool set_result = ecma_fast_array_set_property (array_p, index++, value);
|
||||
JERRY_ASSERT (set_result);
|
||||
ecma_free_value (value);
|
||||
}
|
||||
|
||||
*stack_top_p++ = ecma_make_object_value (array_p);
|
||||
continue;
|
||||
}
|
||||
case VM_OC_INITIALIZER_PUSH_PROP:
|
||||
{
|
||||
result = vm_op_get_value (stack_top_p[-1], left_value);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
*stack_top_p++ = result;
|
||||
goto free_left_value;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
case VM_OC_PUSH_ELISON:
|
||||
{
|
||||
*stack_top_p++ = ECMA_VALUE_ARRAY_HOLE;
|
||||
|
||||
+11
-2
@@ -248,6 +248,11 @@ typedef enum
|
||||
VM_OC_PUSH_CONSTRUCTOR_THIS, /**< push 'this' inside a class constructor */
|
||||
VM_OC_CONSTRUCTOR_RET, /**< explicit return from a class constructor */
|
||||
VM_OC_CREATE_SPREAD_OBJECT, /**< create spread object */
|
||||
VM_OC_GET_ITERATOR, /**< GetIterator abstract operation */
|
||||
VM_OC_ITERATOR_STEP, /**< IteratorStep abstract operation */
|
||||
VM_OC_DEFAULT_INITIALIZER, /**< default initializer inside a pattern */
|
||||
VM_OC_REST_INITIALIZER, /**< create rest object inside an array pattern */
|
||||
VM_OC_INITIALIZER_PUSH_PROP, /**< push property for object initializer */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
VM_OC_NONE, /**< a special opcode for unsupported byte codes */
|
||||
} vm_oc_types;
|
||||
@@ -291,8 +296,12 @@ 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 */
|
||||
VM_OC_CREATE_SPREAD_OBJECT = VM_OC_NONE, /**< create spread object */
|
||||
#endif /* !ENABLED (JERRY_ES2015S) */
|
||||
|
||||
VM_OC_GET_ITERATOR = VM_OC_NONE, /**< GetIterator abstract operation */
|
||||
VM_OC_ITERATOR_STEP = VM_OC_NONE, /**< IteratorStep abstract operation */
|
||||
VM_OC_DEFAULT_INITIALIZER = VM_OC_NONE, /**< default initializer inside a pattern */
|
||||
VM_OC_REST_INITIALIZER = VM_OC_NONE, /**< create rest object inside an array pattern */
|
||||
VM_OC_INITIALIZER_PUSH_PROP = VM_OC_NONE, /**< push property for object initializer */
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */
|
||||
} vm_oc_unused_types;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user