Add iterator close support for array destructuring (#3337)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
committed by
Zoltan Herczeg
parent
6b43ef8605
commit
2ddf134cef
@@ -26,6 +26,7 @@
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "jcontext.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
@@ -393,6 +394,97 @@ ecma_op_iterator_step (ecma_value_t iterator) /**< iterator value */
|
||||
return result;
|
||||
} /* ecma_op_iterator_step */
|
||||
|
||||
/**
|
||||
* IteratorClose operation
|
||||
*
|
||||
* See also: ECMA-262 v6, 7.4.6
|
||||
*
|
||||
* @return ECMA_VALUE_EMPTY - if "return" is succesfully invoked,
|
||||
* and the operation is called with normal completion
|
||||
* ECMA_VALUE_ERROR - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_iterator_close (ecma_value_t iterator) /**< iterator value */
|
||||
{
|
||||
/* 1. */
|
||||
JERRY_ASSERT (ecma_is_value_object (iterator));
|
||||
|
||||
/* 2. */
|
||||
ecma_value_t completion = ECMA_VALUE_EMPTY;
|
||||
|
||||
if (JERRY_CONTEXT (status_flags) & ECMA_STATUS_EXCEPTION)
|
||||
{
|
||||
completion = JERRY_CONTEXT (error_value);
|
||||
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_EXCEPTION;
|
||||
}
|
||||
|
||||
/* 3. */
|
||||
ecma_value_t return_method = ecma_op_get_method_by_magic_id (iterator, LIT_MAGIC_STRING_RETURN);
|
||||
|
||||
/* 4. */
|
||||
if (ECMA_IS_VALUE_ERROR (return_method))
|
||||
{
|
||||
ecma_free_value (completion);
|
||||
return return_method;
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
if (ecma_is_value_undefined (return_method))
|
||||
{
|
||||
if (ecma_is_value_empty (completion))
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION;
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
ecma_object_t *return_obj_p = ecma_get_object_from_value (return_method);
|
||||
ecma_value_t inner_result = ecma_op_function_call (return_obj_p, iterator, NULL, 0);
|
||||
ecma_deref_object (return_obj_p);
|
||||
|
||||
/* 7. */
|
||||
if (!ecma_is_value_empty (completion))
|
||||
{
|
||||
if (ECMA_IS_VALUE_ERROR (inner_result))
|
||||
{
|
||||
ecma_free_value (JERRY_CONTEXT (error_value));
|
||||
JERRY_CONTEXT (error_value) = completion;
|
||||
}
|
||||
|
||||
ecma_free_value (inner_result);
|
||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION;
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
/* 8. */
|
||||
if (ECMA_IS_VALUE_ERROR (inner_result))
|
||||
{
|
||||
ecma_free_value (completion);
|
||||
return inner_result;
|
||||
}
|
||||
|
||||
/* 9. */
|
||||
bool is_object = ecma_is_value_object (inner_result);
|
||||
ecma_free_value (inner_result);
|
||||
|
||||
if (!is_object)
|
||||
{
|
||||
ecma_free_value (completion);
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("method 'return' is not callable."));
|
||||
}
|
||||
|
||||
/* 10. */
|
||||
if (ecma_is_value_empty (completion))
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION;
|
||||
return ECMA_VALUE_ERROR;
|
||||
} /* ecma_op_iterator_close */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -52,6 +52,9 @@ ecma_op_iterator_value (ecma_value_t iter_result);
|
||||
ecma_value_t
|
||||
ecma_op_iterator_step (ecma_value_t iterator);
|
||||
|
||||
ecma_value_t
|
||||
ecma_op_iterator_close (ecma_value_t iterator);
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_ITERATOR) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -968,19 +968,21 @@ ecma_op_object_get_by_symbol_id (ecma_object_t *object_p, /**< the object */
|
||||
} /* ecma_op_object_get_by_symbol_id */
|
||||
|
||||
/**
|
||||
* GetMethod operation the property is a well-known symbol
|
||||
* GetMethod operation
|
||||
*
|
||||
* See also: ECMA-262 v6, 7.3.9
|
||||
*
|
||||
* Note:
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* @return iterator fucntion object - if success
|
||||
* @return iterator function object - if success
|
||||
* raised error - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */
|
||||
lit_magic_string_id_t property_id) /**< property symbol id */
|
||||
static ecma_value_t
|
||||
ecma_op_get_method_by_id (ecma_value_t value, /**< ecma value */
|
||||
lit_magic_string_id_t id, /**< property magic id */
|
||||
bool is_symbol_id) /**< true - if id represents a symbol id
|
||||
* false - otherwise */
|
||||
{
|
||||
/* 2. */
|
||||
ecma_value_t obj_value = ecma_op_to_object (value);
|
||||
@@ -991,7 +993,16 @@ ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
|
||||
ecma_value_t func = ecma_op_object_get_by_symbol_id (obj_p, property_id);
|
||||
ecma_value_t func;
|
||||
|
||||
if (is_symbol_id)
|
||||
{
|
||||
func = ecma_op_object_get_by_symbol_id (obj_p, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
func = ecma_op_object_get_by_magic_id (obj_p, id);
|
||||
}
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
/* 3. */
|
||||
@@ -1015,7 +1026,43 @@ ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */
|
||||
|
||||
/* 6. */
|
||||
return func;
|
||||
} /* ecma_op_get_method_by_id */
|
||||
|
||||
/**
|
||||
* GetMethod operation when the property is a well-known symbol
|
||||
*
|
||||
* See also: ECMA-262 v6, 7.3.9
|
||||
*
|
||||
* Note:
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* @return iterator function object - if success
|
||||
* raised error - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_get_method_by_symbol_id (ecma_value_t value, /**< ecma value */
|
||||
lit_magic_string_id_t symbol_id) /**< property symbol id */
|
||||
{
|
||||
return ecma_op_get_method_by_id (value, symbol_id, true);
|
||||
} /* ecma_op_get_method_by_symbol_id */
|
||||
|
||||
/**
|
||||
* GetMethod operation when the property is a magic string
|
||||
*
|
||||
* See also: ECMA-262 v6, 7.3.9
|
||||
*
|
||||
* Note:
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* @return iterator function object - if success
|
||||
* raised error - otherwise
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_get_method_by_magic_id (ecma_value_t value, /**< ecma value */
|
||||
lit_magic_string_id_t magic_id) /**< property magic id */
|
||||
{
|
||||
return ecma_op_get_method_by_id (value, magic_id, false);
|
||||
} /* ecma_op_get_method_by_magic_id */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,8 @@ ecma_value_t ecma_op_object_get_by_uint32_index (ecma_object_t *object_p, uint32
|
||||
ecma_value_t ecma_op_object_get_by_magic_id (ecma_object_t *object_p, lit_magic_string_id_t property_id);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
ecma_value_t ecma_op_object_get_by_symbol_id (ecma_object_t *object_p, lit_magic_string_id_t property_id);
|
||||
ecma_value_t ecma_op_get_method_by_symbol_id (ecma_value_t value, lit_magic_string_id_t property_id);
|
||||
ecma_value_t ecma_op_get_method_by_symbol_id (ecma_value_t value, lit_magic_string_id_t symbol_id);
|
||||
ecma_value_t ecma_op_get_method_by_magic_id (ecma_value_t value, lit_magic_string_id_t magic_id);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
ecma_value_t ecma_op_object_put (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_value_t value,
|
||||
bool is_throw);
|
||||
|
||||
Reference in New Issue
Block a user