Implement CreateAsyncFromSyncIterator (#4802)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
Robert Fancsik
2021-10-28 12:45:47 +02:00
committed by GitHub
parent dd77ec914a
commit d2388e907f
24 changed files with 1015 additions and 418 deletions
@@ -0,0 +1,374 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-builtin-handlers.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-iterator-object.h"
#include "ecma-objects.h"
#include "ecma-promise-object.h"
#include "jcontext.h"
#include "jerryscript-types.h"
#include "jrt.h"
#include "lit-magic-strings.h"
#include "lit-strings.h"
#include "opcodes.h"
#include "vm-defines.h"
#if JERRY_ESNEXT
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/**
* This object has a custom dispatch function.
*/
#define BUILTIN_CUSTOM_DISPATCH
/**
* List of built-in routine identifiers.
*/
enum
{
ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_START = 0, /**< buitlin routine start id */
ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT, /**< 'next' routine v11, 25.1.4.2.1 */
ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN, /**< 'return' routine v11, 25.1.4.2.2 */
ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW /**< 'throw' routine v11, 25.1.4.2.3 */
} ecma_async_from_sync_iterator_operation_type_t;
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-async-from-sync-iterator-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID async_from_sync_iterator_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup generator ECMA %AsyncFromSyncIteratorPrototype% object built-in
* @{
*/
/**
* AsyncFromSyncIteratorContinuation operation
*
* See also:
* ECMAScript v11, 25.1.4.4
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_op_async_from_sync_iterator_prototype_continuation (ecma_value_t result, /**< routine's 'result' argument */
ecma_object_t *capability_obj_p) /**< promise capability */
{
/* 1. */
ecma_value_t done = ecma_op_iterator_complete (result);
/* 2. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&done, capability_obj_p)))
{
return done;
}
uint16_t done_flag = ecma_is_value_false (done) ? 0 : (1 << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT);
ecma_free_value (done);
/* 3. */
ecma_value_t value = ecma_op_iterator_value (result);
/* 4. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&value, capability_obj_p)))
{
return value;
}
/* 5. */
ecma_value_t builtin_promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE));
ecma_value_t value_wrapper = ecma_promise_reject_or_resolve (builtin_promise, value, true);
ecma_free_value (value);
/* 6. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&value_wrapper, capability_obj_p)))
{
return value_wrapper;
}
/* 8 - 9. */
ecma_object_t *on_fullfilled = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP,
sizeof (ecma_extended_object_t));
((ecma_extended_object_t *) on_fullfilled)->u.built_in.u2.routine_flags = (uint8_t) done_flag;
/* 10. */
ecma_value_t then_result = ecma_promise_perform_then (value_wrapper,
ecma_make_object_value (on_fullfilled),
ECMA_VALUE_UNDEFINED,
capability_obj_p);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (then_result));
ecma_deref_object (on_fullfilled);
ecma_free_value (value_wrapper);
/* 11. */
return then_result;
} /* ecma_op_async_from_sync_iterator_prototype_continuation */
/**
* The %AsyncFromSyncIteratorPrototype% object's 'next' routine
*
* See also:
* ECMAScript v11, 25.1.4.2.1
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_async_from_sync_iterator_prototype_next (ecma_async_from_sync_iterator_object_t *iter_p, /**< iterator
* record*/
ecma_object_t *capability_p, /**< promise capability */
ecma_value_t value) /**< routine's 'value' argument */
{
/* 5. */
ecma_value_t next_result = ecma_op_iterator_next (iter_p->header.u.cls.u3.sync_iterator,
iter_p->sync_next_method,
value);
/* 6. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&next_result, capability_p)))
{
return next_result;
}
/* 7. */
ecma_value_t result = ecma_op_async_from_sync_iterator_prototype_continuation (next_result, capability_p);
ecma_free_value (next_result);
return result;
} /* ecma_builtin_async_from_sync_iterator_prototype_next */
/**
* The %AsyncFromSyncIteratorPrototype% object's 'return' and 'throw' routines
*
* See also:
* ECMAScript v11, 25.1.4.2.2
* ECMAScript v11, 25.1.4.2.3
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
static ecma_value_t
ecma_builtin_async_from_sync_iterator_prototype_do (ecma_async_from_sync_iterator_object_t *iter_p, /**< iterator
* record*/
ecma_object_t *capability_obj_p, /**< promise capability */
ecma_value_t value, /**< routine's 'value' argument */
lit_magic_string_id_t method_id) /**< method id */
{
/* 5. */
ecma_value_t sync_iterator = iter_p->header.u.cls.u3.sync_iterator;
ecma_value_t method = ecma_op_get_method_by_magic_id (sync_iterator, method_id);
/* 6. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&method, capability_obj_p)))
{
return method;
}
ecma_promise_capabality_t *capability_p = (ecma_promise_capabality_t *) capability_obj_p;
ecma_value_t call_arg;
uint32_t arg_size;
if (ecma_is_value_empty (value))
{
arg_size = 0;
call_arg = ECMA_VALUE_UNDEFINED;
}
else
{
arg_size = 1;
call_arg = value;
}
/* 7. */
if (ecma_is_value_undefined (method))
{
ecma_value_t func_obj;
if (method_id == LIT_MAGIC_STRING_RETURN)
{
/* 7.a. */
call_arg = ecma_create_iter_result_object (call_arg, ECMA_VALUE_TRUE);
arg_size = 1;
func_obj = capability_p->resolve;
}
else
{
func_obj = capability_p->reject;
}
/* 7.b. */
ecma_value_t resolve = ecma_op_function_call (ecma_get_object_from_value (func_obj),
ECMA_VALUE_UNDEFINED,
&call_arg,
arg_size);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (resolve));
ecma_free_value (resolve);
if (method_id == LIT_MAGIC_STRING_RETURN)
{
ecma_free_value (call_arg);
}
/* 7.c. */
return ecma_copy_value (capability_p->header.u.cls.u3.promise);
}
/* 8. */
ecma_value_t call_result;
if (!ecma_op_is_callable (method))
{
ecma_free_value (method);
call_result = ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_expected_a_function));
}
else
{
ecma_object_t *method_func_obj = ecma_get_object_from_value (method);
call_result = ecma_op_function_call (method_func_obj, sync_iterator, &call_arg, arg_size);
ecma_deref_object (method_func_obj);
}
/* 9. */
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&call_result, capability_obj_p)))
{
return call_result;
}
/* 10. */
if (!ecma_is_value_object (call_result))
{
ecma_free_value (call_result);
#if JERRY_ERROR_MESSAGES
const lit_utf8_byte_t *msg_p = (const lit_utf8_byte_t *) ecma_error_argument_is_not_an_object;
lit_utf8_size_t msg_size = (lit_utf8_size_t) ecma_error_argument_is_not_an_object_length;
JERRY_ASSERT (lit_zt_utf8_string_size (msg_p) == msg_size);
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii (msg_p, msg_size);
#else /* !JERRY_ERROR_MESSAGES */
ecma_string_t *error_msg_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
#endif /* JERRY_ERROR_MESSAGES */
ecma_object_t *type_error_obj_p = ecma_new_standard_error (JERRY_ERROR_TYPE, error_msg_p);
#if JERRY_ERROR_MESSAGES
ecma_deref_ecma_string (error_msg_p);
#endif /* JERRY_ERROR_MESSAGES */
ecma_value_t type_error = ecma_make_object_value (type_error_obj_p);
/* 10.a. */
ecma_value_t reject = ecma_op_function_call (ecma_get_object_from_value (capability_p->reject),
ECMA_VALUE_UNDEFINED,
&type_error,
1);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (reject));
ecma_deref_object (type_error_obj_p);
ecma_free_value (reject);
/* 10.b. */
return ecma_copy_value (capability_p->header.u.cls.u3.promise);
}
ecma_value_t result = ecma_op_async_from_sync_iterator_prototype_continuation (call_result, capability_obj_p);
ecma_free_value (call_result);
return result;
} /* ecma_builtin_async_from_sync_iterator_prototype_do */
/**
* Dispatcher of the %AsyncFromSyncIteratorPrototype% built-in's routines
*
* @return ecma value
* Returned value must be freed with ecma_free_value.
*/
ecma_value_t
ecma_builtin_async_from_sync_iterator_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide
* routine
* identifier */
ecma_value_t this_arg, /**< 'this' argument value */
const ecma_value_t arguments_list_p[], /**< list of
* arguments
* passed to
* routine */
uint32_t arguments_number) /**< length of
* arguments' list */
{
JERRY_UNUSED (arguments_number);
JERRY_ASSERT (ecma_is_value_object (this_arg));
ecma_object_t *this_obj_p = ecma_get_object_from_value (this_arg);
JERRY_ASSERT (ecma_object_class_is (this_obj_p, ECMA_OBJECT_CLASS_ASYNC_FROM_SYNC_ITERATOR));
ecma_async_from_sync_iterator_object_t *iter_p = (ecma_async_from_sync_iterator_object_t *) this_obj_p;
ecma_value_t builtin_promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE));
ecma_object_t *capability_p = ecma_promise_new_capability (builtin_promise, ECMA_VALUE_UNDEFINED);
JERRY_ASSERT (capability_p != NULL);
ecma_value_t result;
ecma_value_t arg = (arguments_number == 0 ? ECMA_VALUE_EMPTY : arguments_list_p[0]);
switch (builtin_routine_id)
{
case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT:
{
result = ecma_builtin_async_from_sync_iterator_prototype_next (iter_p, capability_p, arg);
break;
}
case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN:
{
result = ecma_builtin_async_from_sync_iterator_prototype_do (iter_p, capability_p, arg, LIT_MAGIC_STRING_RETURN);
break;
}
case ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW:
{
result = ecma_builtin_async_from_sync_iterator_prototype_do (iter_p, capability_p, arg, LIT_MAGIC_STRING_THROW);
break;
}
default:
{
JERRY_UNREACHABLE ();
break;
}
}
ecma_deref_object (capability_p);
return result;
} /* ecma_builtin_async_from_sync_iterator_prototype_dispatch_routine */
/**
* @}
* @}
* @}
*/
#endif /* JERRY_ESNEXT */
@@ -0,0 +1,32 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* %AsyncFromSyncIteratorPrototype% built-in description (AsyncFunction.prototype)
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if JERRY_ESNEXT
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (LIT_MAGIC_STRING_NEXT, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_NEXT, 1, 1)
ROUTINE (LIT_MAGIC_STRING_RETURN, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_RETURN, 1, 1)
ROUTINE (LIT_MAGIC_STRING_THROW, ECMA_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_ROUTINE_THROW, 1, 1)
#endif /* JERRY_ESNEXT */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -19,6 +19,7 @@
#include "ecma-builtin-handlers.h"
#include "ecma-promise-object.h"
#include "ecma-iterator-object.h"
static const ecma_builtin_handler_t ecma_native_handlers[] =
{
@@ -44,7 +44,7 @@ typedef enum
/**
* Shift for Promise helper handler function.
*/
#define ECMA_NATIVE_HANDLER_FLAGS_PROMISE_HELPER_SHIFT 2
#define ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT 2
ecma_builtin_handler_t
ecma_builtin_handler_get (ecma_native_handler_id_t id);
@@ -19,6 +19,7 @@ ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY, ecma_promise_then
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY, ecma_promise_catch_finally_cb, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER, ecma_promise_all_or_all_settled_handler_cb, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR, ecma_op_get_capabilities_executor_cb, 2)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_ASYNC_FROM_SYNC_ITERATOR_UNWRAP, ecma_async_from_sync_iterator_unwrap_cb, 1)
#if JERRY_BUILTIN_PROXY
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROXY_REVOKE, ecma_proxy_revoke_cb, 0)
#endif /* JERRY_BUILTIN_PROXY */
@@ -65,45 +65,6 @@ enum
* @{
*/
/**
* Reject the promise if the value is error.
*
* See also:
* ES2015 25.4.1.1.1
*
* @return ecma value of the new promise.
* Returned value must be freed with ecma_free_value.
*/
static inline ecma_value_t
ecma_builtin_promise_reject_abrupt (ecma_value_t value, /**< value */
ecma_object_t *capability_obj_p) /**< capability */
{
JERRY_ASSERT (ecma_object_class_is (capability_obj_p, ECMA_OBJECT_CLASS_PROMISE_CAPABILITY));
if (!ECMA_IS_VALUE_ERROR (value))
{
return value;
}
ecma_value_t reason = jcontext_take_exception ();
ecma_promise_capabality_t *capability_p = (ecma_promise_capabality_t *) capability_obj_p;
ecma_value_t call_ret = ecma_op_function_call (ecma_get_object_from_value (capability_p->reject),
ECMA_VALUE_UNDEFINED,
&reason,
1);
ecma_free_value (reason);
if (ECMA_IS_VALUE_ERROR (call_ret))
{
return call_ret;
}
ecma_free_value (call_ret);
return ecma_copy_value (capability_p->header.u.cls.u3.promise);
} /* ecma_builtin_promise_reject_abrupt */
/**
* Runtime Semantics: PerformPromiseRace.
*
@@ -118,7 +79,6 @@ ecma_builtin_promise_perform_race (ecma_value_t iterator, /**< the iterator for
ecma_value_t next_method, /**< next method */
ecma_object_t *capability_obj_p, /**< PromiseCapability record */
ecma_value_t ctor, /**< Constructor value */
ecma_value_t resolve, /** the resolve of Promise.all */
bool *done_p) /**< [out] iteratorRecord[[done]] */
{
JERRY_ASSERT (ecma_is_value_object (iterator));
@@ -127,6 +87,20 @@ ecma_builtin_promise_perform_race (ecma_value_t iterator, /**< the iterator for
ecma_promise_capabality_t *capability_p = (ecma_promise_capabality_t *) capability_obj_p;
ecma_value_t resolve = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (ctor),
LIT_MAGIC_STRING_RESOLVE);
if (ECMA_IS_VALUE_ERROR (resolve))
{
return resolve;
}
if (!ecma_op_is_callable (resolve))
{
ecma_free_value (resolve);
return ecma_raise_type_error (ECMA_ERR_MSG ("Resolve method must be callable"));
}
ecma_object_t *resolve_func_p = ecma_get_object_from_value (resolve);
ecma_value_t ret_value = ECMA_VALUE_ERROR;
@@ -184,6 +158,8 @@ ecma_builtin_promise_perform_race (ecma_value_t iterator, /**< the iterator for
done:
*done_p = true;
exit:
ecma_deref_object (resolve_func_p);
return ret_value;
} /* ecma_builtin_promise_perform_race */
@@ -201,7 +177,6 @@ ecma_builtin_promise_perform (ecma_value_t iterator, /**< iteratorRecord */
ecma_value_t next_method, /**< next method */
ecma_object_t *capability_obj_p, /**< PromiseCapability record */
ecma_value_t ctor, /**< the caller of Promise.all */
ecma_value_t resolve, /** the resolve of Promise.all */
uint8_t builtin_routine_id, /**< built-in wide routine identifier */
bool *done_p) /**< [out] iteratorRecord[[done]] */
{
@@ -211,6 +186,20 @@ ecma_builtin_promise_perform (ecma_value_t iterator, /**< iteratorRecord */
ecma_promise_capabality_t *capability_p = (ecma_promise_capabality_t *) capability_obj_p;
ecma_value_t resolve = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (ctor),
LIT_MAGIC_STRING_RESOLVE);
if (ECMA_IS_VALUE_ERROR (resolve))
{
return resolve;
}
if (!ecma_op_is_callable (resolve))
{
ecma_free_value (resolve);
return ecma_raise_type_error (ECMA_ERR_MSG ("Resolve method must be callable"));
}
ecma_object_t *resolve_func_p = ecma_get_object_from_value (resolve);
/* 3. */
@@ -321,11 +310,11 @@ ecma_builtin_promise_perform (ecma_value_t iterator, /**< iteratorRecord */
/* p. */
executor_p->remaining_elements = remaining;
uint8_t executor_type = ECMA_PROMISE_ALL_RESOLVE << ECMA_NATIVE_HANDLER_FLAGS_PROMISE_HELPER_SHIFT;
uint8_t executor_type = ECMA_PROMISE_ALL_RESOLVE << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ALLSETTLED)
{
executor_type = ECMA_PROMISE_ALLSETTLED_RESOLVE << ECMA_NATIVE_HANDLER_FLAGS_PROMISE_HELPER_SHIFT;
executor_type = ECMA_PROMISE_ALLSETTLED_RESOLVE << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT;
}
executor_p->header.u.built_in.u2.routine_flags |= executor_type;
@@ -343,11 +332,11 @@ ecma_builtin_promise_perform (ecma_value_t iterator, /**< iteratorRecord */
if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ALL)
{
uint8_t executor_type = ECMA_PROMISE_ALLSETTLED_REJECT << ECMA_NATIVE_HANDLER_FLAGS_PROMISE_HELPER_SHIFT;
uint8_t executor_type = ECMA_PROMISE_ALLSETTLED_REJECT << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ANY)
{
executor_type = ECMA_PROMISE_ANY_REJECT << ECMA_NATIVE_HANDLER_FLAGS_PROMISE_HELPER_SHIFT;
executor_type = ECMA_PROMISE_ANY_REJECT << ECMA_NATIVE_HANDLER_COMMON_FLAGS_SHIFT;
}
ecma_object_t *reject_func_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER,
@@ -390,6 +379,8 @@ done:
exit:
ecma_free_value (remaining);
ecma_deref_object (values_array_obj_p);
ecma_deref_object (resolve_func_p);
return ret_value;
} /* ecma_builtin_promise_perform */
@@ -411,41 +402,22 @@ ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */
return ECMA_VALUE_ERROR;
}
ecma_value_t resolve = ecma_op_object_get_by_magic_id (ecma_get_object_from_value (this_arg),
LIT_MAGIC_STRING_RESOLVE);
if (ECMA_IS_VALUE_ERROR (resolve))
{
resolve = ecma_builtin_promise_reject_abrupt (resolve, capability_obj_p);
ecma_deref_object (capability_obj_p);
return resolve;
}
if (!ecma_op_is_callable (resolve))
{
ecma_free_value (resolve);
ecma_raise_type_error (ECMA_ERR_MSG ("Resolve method must be callable"));
resolve = ecma_builtin_promise_reject_abrupt (ECMA_VALUE_ERROR, capability_obj_p);
ecma_deref_object (capability_obj_p);
return resolve;
}
ecma_value_t next_method;
ecma_value_t iterator = ecma_op_get_iterator (iterable, ECMA_VALUE_SYNC_ITERATOR, &next_method);
iterator = ecma_builtin_promise_reject_abrupt (iterator, capability_obj_p);
ecma_value_t ret = ECMA_VALUE_ERROR;
if (ECMA_IS_VALUE_ERROR (iterator))
if (ECMA_IS_VALUE_ERROR (ecma_op_if_abrupt_reject_promise (&iterator, capability_obj_p)))
{
ecma_free_value (next_method);
ecma_deref_object (capability_obj_p);
return iterator;
}
ecma_value_t ret = ECMA_VALUE_EMPTY;
bool is_done = false;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_RACE)
{
ret = ecma_builtin_promise_perform_race (iterator, next_method, capability_obj_p, this_arg, resolve, &is_done);
ret = ecma_builtin_promise_perform_race (iterator, next_method, capability_obj_p, this_arg, &is_done);
}
else
{
@@ -453,7 +425,6 @@ ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */
next_method,
capability_obj_p,
this_arg,
resolve,
builtin_routine_id,
&is_done);
}
@@ -465,12 +436,11 @@ ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */
ret = ecma_op_iterator_close (iterator);
}
ret = ecma_builtin_promise_reject_abrupt (ret, capability_obj_p);
ecma_op_if_abrupt_reject_promise (&ret, capability_obj_p);
}
ecma_free_value (iterator);
ecma_free_value (next_method);
ecma_free_value (resolve);
ecma_deref_object (capability_obj_p);
return ret;
@@ -701,6 +701,13 @@ BUILTIN (ECMA_BUILTIN_ID_ASYNC_ITERATOR_PROTOTYPE,
true,
async_iterator_prototype)
/* The %AsyncFromSyncIteratorPrototype% object (ECMA-262 v11, 25.1.4.2) */
BUILTIN (ECMA_BUILTIN_ID_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE,
ECMA_OBJECT_TYPE_BUILT_IN_GENERAL,
ECMA_BUILTIN_ID_ASYNC_ITERATOR_PROTOTYPE,
true,
async_from_sync_iterator_prototype)
/* The %(GeneratorFunction)% object */
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_GENERATOR_FUNCTION,
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION,