Implement Promise.any and AggregateError Object (#4623)

JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis kisbg@inf.u-szeged.hu
This commit is contained in:
kisbg
2021-03-22 12:42:20 +01:00
committed by GitHub
parent edd2f20397
commit 22ebb00a4c
25 changed files with 744 additions and 174 deletions
+4
View File
@@ -145,6 +145,8 @@ set(SOURCE_CORE_FILES
ecma/base/ecma-literal-storage.c
ecma/base/ecma-module.c
ecma/base/ecma-property-hashmap.c
ecma/builtin-objects/ecma-builtin-aggregateerror.c
ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.c
ecma/builtin-objects/ecma-builtin-array-iterator-prototype.c
ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.c
ecma/builtin-objects/ecma-builtin-array-prototype.c
@@ -333,6 +335,8 @@ if(ENABLE_AMALGAM)
ecma/base/ecma-literal-storage.h
ecma/base/ecma-module.h
ecma/base/ecma-property-hashmap.h
ecma/builtin-objects/ecma-builtin-aggregateerror-prototype.inc.h
ecma/builtin-objects/ecma-builtin-aggregateerror.inc.h
ecma/builtin-objects/ecma-builtin-array-iterator-prototype.inc.h
ecma/builtin-objects/ecma-builtin-array-prototype-unscopables.inc.h
ecma/builtin-objects/ecma-builtin-array-prototype.inc.h
+4
View File
@@ -62,6 +62,10 @@ JERRY_STATIC_ASSERT ((int) ECMA_ERROR_NONE == (int) JERRY_ERROR_NONE
&& (int) ECMA_ERROR_TYPE == (int) JERRY_ERROR_TYPE
&& (int) ECMA_ERROR_URI == (int) JERRY_ERROR_URI,
ecma_standard_error_t_must_be_equal_to_jerry_error_t);
#if JERRY_BUILTIN_PROMISE
JERRY_STATIC_ASSERT ((int) ECMA_ERROR_AGGREGATE == (int) JERRY_ERROR_AGGREGATE,
ecma_standard_error_t_must_be_equal_to_jerry_error_t);
#endif /* JERRY_BUILTIN_PROMISE */
JERRY_STATIC_ASSERT ((int) ECMA_INIT_EMPTY == (int) JERRY_INIT_EMPTY
&& (int) ECMA_INIT_SHOW_OPCODES == (int) JERRY_INIT_SHOW_OPCODES
+1
View File
@@ -610,6 +610,7 @@
|| (JERRY_BUILTIN_PROMISE == 1) \
|| (JERRY_BUILTIN_PROXY == 1) \
|| (JERRY_BUILTIN_REFLECT == 1) \
|| (JERRY_BUILTIN_PROMISE == 1) \
|| (JERRY_BUILTIN_TYPEDARRAY == 1))
# error "JERRY_ESNEXT should be enabled too to enable JERRY_BUILTIN_xxxxx macro."
#endif
+7
View File
@@ -1457,6 +1457,13 @@ jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**
string_id = LIT_MAGIC_STRING_TYPE_ERROR_UL;
break;
}
#if JERRY_BUILTIN_PROMISE
case ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE:
{
string_id = LIT_MAGIC_STRING_AGGREGATE_ERROR_UL;
break;
}
#endif /* JERRY_BUILTIN_PROMISE */
case ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE:
{
string_id = LIT_MAGIC_STRING_URI_ERROR_UL;
+3 -2
View File
@@ -2136,7 +2136,7 @@ typedef struct
ecma_extended_object_t header; /**< object header */
ecma_value_t remaining_elements; /**< [[Remaining elements]] internal slot */
ecma_value_t capability; /**< [[Capabilities]] internal slot */
ecma_value_t values; /**< [[Values]] internal slot */
ecma_value_t values; /**< [[Values]] or [[Errors]] internal slot */
uint32_t index; /**< [[Index]] and [[AlreadyCalled]] internal slot
* 0 - if the element has been resolved
* real index + 1 in the [[Values]] list - otherwise */
@@ -2150,7 +2150,8 @@ typedef enum
ECMA_PROMISE_ALL_RESOLVE, /**< promise.all resolve */
ECMA_PROMISE_ALLSETTLED_RESOLVE, /**< promise.allSettled resolve */
ECMA_PROMISE_ALLSETTLED_REJECT, /**< promise.allSettled reject */
} ecma_promise_helper;
ECMA_PROMISE_ANY_REJECT, /**< promise.any reject */
} ecma_promise_all_exector_type_t;
#endif /* JERRY_ESNEXT */
@@ -0,0 +1,36 @@
/* 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "jrt.h"
#if JERRY_BUILTIN_PROMISE
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID aggregate_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* JERRY_BUILTIN_PROMISE */
@@ -0,0 +1,44 @@
/* 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.
*/
/*
* AggregateError.prototype built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if JERRY_BUILTIN_PROMISE
/* Object properties:
* (property name, object pointer getter) */
/* ECMA-262 v5, 15.11.7.8 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_AGGREGATE_ERROR,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
/* ECMA-262 v5, 15.11.7.9 */
STRING_VALUE (LIT_MAGIC_STRING_NAME,
LIT_MAGIC_STRING_AGGREGATE_ERROR_UL,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
/* ECMA-262 v5, 15.11.7.10 */
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
LIT_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#endif /* JERRY_BUILTIN_PROMISE */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -0,0 +1,112 @@
/* 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-builtin-helpers.h"
#include "ecma-objects.h"
#include "ecma-function-object.h"
#include "ecma-iterator-object.h"
#include "ecma-array-object.h"
#include "jrt.h"
#include "jcontext.h"
#if JERRY_BUILTIN_PROMISE
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-aggregateerror.inc.h"
#define BUILTIN_UNDERSCORED_ID aggregate_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup aggregateerror ECMA AggregateError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in AggregateError object
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_aggregate_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
uint32_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_value_t message_val = ECMA_VALUE_UNDEFINED;
ecma_value_t error_val = ECMA_VALUE_UNDEFINED;
if (arguments_list_len > 0)
{
error_val = arguments_list_p[0];
if (arguments_list_len > 1)
{
message_val = arguments_list_p[1];
}
}
return ecma_new_aggregate_error (error_val, message_val);
} /* ecma_builtin_aggregate_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in AggregateError object
*
* @return ecma value
*/
ecma_value_t
ecma_builtin_aggregate_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
uint32_t arguments_list_len) /**< number of arguments */
{
ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p),
ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE);
if (proto_p == NULL)
{
return ECMA_VALUE_ERROR;
}
ecma_value_t result = ecma_builtin_aggregate_error_dispatch_call (arguments_list_p, arguments_list_len);
if (!ECMA_IS_VALUE_ERROR (result))
{
ecma_object_t *object_p = ecma_get_object_from_value (result);
ECMA_SET_NON_NULL_POINTER (object_p->u2.prototype_cp, proto_p);
}
ecma_deref_object (proto_p);
return result;
} /* ecma_builtin_aggregate_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* JERRY_BUILTIN_PROMISE */
@@ -0,0 +1,45 @@
/* 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.
*/
/*
* AggregateError built-in description
*/
#include "ecma-builtin-helpers-macro-defines.inc.h"
#if JERRY_BUILTIN_PROMISE
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
2,
ECMA_PROPERTY_FLAG_DEFAULT_LENGTH)
/* Object properties:
* (property name, object pointer getter) */
/* ECMA-262 v5, 15.11.3.1 */
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE,
ECMA_PROPERTY_FIXED)
STRING_VALUE (LIT_MAGIC_STRING_NAME,
LIT_MAGIC_STRING_AGGREGATE_ERROR_UL,
ECMA_PROPERTY_FLAG_CONFIGURABLE)
#endif /* JERRY_BUILTIN_PROMISE */
#include "ecma-builtin-helpers-macro-undefs.inc.h"
@@ -127,6 +127,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_TYPE_ERROR_UL,
ECMA_BUILTIN_ID_TYPE_ERROR,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#if JERRY_BUILTIN_PROMISE
OBJECT_VALUE (LIT_MAGIC_STRING_AGGREGATE_ERROR_UL,
ECMA_BUILTIN_ID_AGGREGATE_ERROR,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#endif /* JERRY_BUILTIN_PROMISE */
/* ECMA-262 v5, 15.1.4.15 */
OBJECT_VALUE (LIT_MAGIC_STRING_URI_ERROR_UL,
ECMA_BUILTIN_ID_URI_ERROR,
@@ -47,6 +47,7 @@ enum
ECMA_PROMISE_ROUTINE_RACE,
ECMA_PROMISE_ROUTINE_ALL,
ECMA_PROMISE_ROUTINE_ALLSETTLED,
ECMA_PROMISE_ROUTINE_ANY,
ECMA_PROMISE_ROUTINE_SPECIES_GET
};
@@ -187,7 +188,7 @@ exit:
} /* ecma_builtin_promise_perform_race */
/**
* Runtime Semantics: PerformPromise all or allSettled.
* Runtime Semantics: Perform Promise all, allSettled or any.
*
* See also:
* ES2020 25.6.4.1.1
@@ -196,14 +197,13 @@ exit:
* Returned value must be freed with ecma_free_value.
*/
static inline ecma_value_t
ecma_builtin_promise_perform_all_or_all_settled (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]] */
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]] */
{
/* 1. - 2. */
JERRY_ASSERT (ecma_object_class_is (capability_obj_p, LIT_INTERNAL_MAGIC_PROMISE_CAPABILITY));
@@ -240,6 +240,12 @@ ecma_builtin_promise_perform_all_or_all_settled (ecma_value_t iterator, /**< ite
/* ii. - iii. */
if (ecma_promise_remaining_inc_or_dec (remaining, false) == 0)
{
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ANY)
{
ret_value = ecma_raise_aggregate_error (values_array, ECMA_VALUE_UNDEFINED);
goto done;
}
/* 2. */
ecma_value_t resolve_result = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve),
ECMA_VALUE_UNDEFINED,
@@ -291,38 +297,56 @@ ecma_builtin_promise_perform_all_or_all_settled (ecma_value_t iterator, /**< ite
goto exit;
}
/* k. */
ecma_object_t *executor_func_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER,
sizeof (ecma_promise_all_executor_t));
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) executor_func_p;
/* m. + t. */
executor_p->index = ++idx;
/* n. */
executor_p->values = values_array;
/* o. */
executor_p->capability = ecma_make_object_value (capability_obj_p);
/* p. */
executor_p->remaining_elements = remaining;
executor_p->header.u.class_prop.extra_info = ECMA_PROMISE_ALL_RESOLVE;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ALLSETTLED)
{
executor_p->header.u.class_prop.extra_info = ECMA_PROMISE_ALLSETTLED_RESOLVE;
}
idx++;
ecma_value_t args[2];
args[0] = ecma_make_object_value (executor_func_p);
ecma_object_t *executor_func_p = NULL;
if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ANY)
{
/* k. */
executor_func_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER,
sizeof (ecma_promise_all_executor_t));
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) executor_func_p;
/* m. + t. */
executor_p->index = idx;
/* n. */
executor_p->values = values_array;
/* o. */
executor_p->capability = ecma_make_object_value (capability_obj_p);
/* p. */
executor_p->remaining_elements = remaining;
executor_p->header.u.class_prop.extra_info = ECMA_PROMISE_ALL_RESOLVE;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ALLSETTLED)
{
executor_p->header.u.class_prop.extra_info = ECMA_PROMISE_ALLSETTLED_RESOLVE;
}
args[0] = ecma_make_object_value (executor_func_p);
}
else
{
args[0] = capability_p->resolve;
}
/* q. */
ecma_promise_remaining_inc_or_dec (remaining, true);
ecma_value_t result;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ALLSETTLED)
if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ALL)
{
ecma_promise_all_exector_type_t type = ECMA_PROMISE_ALLSETTLED_REJECT;
if (builtin_routine_id == ECMA_PROMISE_ROUTINE_ANY)
{
type = ECMA_PROMISE_ANY_REJECT;
}
ecma_object_t *reject_func_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER,
sizeof (ecma_promise_all_executor_t));
@@ -331,18 +355,21 @@ ecma_builtin_promise_perform_all_or_all_settled (ecma_value_t iterator, /**< ite
reject_p->values = values_array;
reject_p->capability = ecma_make_object_value (capability_obj_p);
reject_p->remaining_elements = remaining;
reject_p->header.u.class_prop.extra_info = ECMA_PROMISE_ALLSETTLED_REJECT;
reject_p->header.u.class_prop.extra_info = (uint16_t) type;
args[1] = ecma_make_object_value (reject_func_p);
result = ecma_op_invoke_by_magic_id (next_promise, LIT_MAGIC_STRING_THEN, args, 2);
ecma_free_value (next_promise);
ecma_deref_object (executor_func_p);
ecma_deref_object (reject_func_p);
}
else
{
args[1] = capability_p->reject;
result = ecma_op_invoke_by_magic_id (next_promise, LIT_MAGIC_STRING_THEN, args, 2);
ecma_free_value (next_promise);
}
ecma_free_value (next_promise);
if (builtin_routine_id != ECMA_PROMISE_ROUTINE_ANY)
{
ecma_deref_object (executor_func_p);
}
@@ -361,10 +388,10 @@ exit:
ecma_free_value (remaining);
ecma_deref_object (values_array_obj_p);
return ret_value;
} /* ecma_builtin_promise_perform_all_or_all_settled */
} /* ecma_builtin_promise_perform */
/**
* The common function for Promise.race, Promise.all and Promise.allSettled.
* The common function for Promise.race, Promise.all, Promise.any and Promise.allSettled.
*
* @return ecma value of the new promise.
* Returned value must be freed with ecma_free_value.
@@ -372,8 +399,7 @@ exit:
static ecma_value_t
ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */
ecma_value_t iterable, /**< the items to be resolved */
uint8_t builtin_routine_id) /**< built-in wide routine
* identifier */
uint8_t builtin_routine_id) /**< built-in wide routine identifier */
{
ecma_object_t *capability_obj_p = ecma_promise_new_capability (this_arg, ECMA_VALUE_UNDEFINED);
@@ -420,8 +446,13 @@ ecma_builtin_promise_helper (ecma_value_t this_arg, /**< 'this' argument */
}
else
{
ret = ecma_builtin_promise_perform_all_or_all_settled (iterator, next_method, capability_obj_p, this_arg, resolve,
builtin_routine_id, &is_done);
ret = ecma_builtin_promise_perform (iterator,
next_method,
capability_obj_p,
this_arg,
resolve,
builtin_routine_id,
&is_done);
}
if (ECMA_IS_VALUE_ERROR (ret))
@@ -508,6 +539,7 @@ ecma_builtin_promise_dispatch_routine (uint8_t builtin_routine_id, /**< built-in
case ECMA_PROMISE_ROUTINE_RACE:
case ECMA_PROMISE_ROUTINE_ALL:
case ECMA_PROMISE_ROUTINE_ALLSETTLED:
case ECMA_PROMISE_ROUTINE_ANY:
{
return ecma_builtin_promise_helper (this_arg, argument, builtin_routine_id);
}
@@ -46,6 +46,7 @@ ROUTINE (LIT_MAGIC_STRING_RESOLVE, ECMA_PROMISE_ROUTINE_RESOLVE, 1, 1)
ROUTINE (LIT_MAGIC_STRING_RACE, ECMA_PROMISE_ROUTINE_RACE, 1, 1)
ROUTINE (LIT_MAGIC_STRING_ALL, ECMA_PROMISE_ROUTINE_ALL, 1, 1)
ROUTINE (LIT_MAGIC_STRING_ALLSETTLED, ECMA_PROMISE_ROUTINE_ALLSETTLED, 1, 1)
ROUTINE (LIT_MAGIC_STRING_ANY, ECMA_PROMISE_ROUTINE_ANY, 1, 1)
/* ES2015 25.4.4.6 */
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
@@ -283,6 +283,22 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPE_ERROR,
true,
type_error)
#if JERRY_BUILTIN_PROMISE
/* The AggregateError.prototype object (15.11.6.5) */
BUILTIN (ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
aggregate_error_prototype)
/* The AggregateError object (15.11.6.5) */
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_AGGREGATE_ERROR,
ECMA_OBJECT_TYPE_NATIVE_FUNCTION,
ECMA_BUILTIN_NATIVE_ERROR_PROTOTYPE_ID,
true,
aggregate_error)
#endif /* JERRY_BUILTIN_PROMISE */
/* The URIError.prototype object (15.11.6.6) */
BUILTIN (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
@@ -22,6 +22,8 @@
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-symbol-object.h"
#include "ecma-iterator-object.h"
#include "ecma-array-object.h"
#include "jcontext.h"
#include "jrt.h"
@@ -60,6 +62,9 @@ const ecma_error_mapping_t ecma_error_mappings[] =
ERROR_ELEMENT (ECMA_ERROR_TYPE, ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE),
ERROR_ELEMENT (ECMA_ERROR_URI, ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE),
ERROR_ELEMENT (ECMA_ERROR_SYNTAX, ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE),
#if JERRY_BUILTIN_PROMISE
ERROR_ELEMENT (ECMA_ERROR_AGGREGATE, ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE),
#endif /* JERRY_BUILTIN_PROMISE */
#endif /* JERRY_BUILTIN_ERRORS */
#undef ERROR_ELEMENT
@@ -111,6 +116,13 @@ ecma_new_standard_error (ecma_standard_error_t error_type, /**< native error typ
break;
}
#if JERRY_BUILTIN_PROMISE
case ECMA_ERROR_AGGREGATE:
{
prototype_id = ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE;
break;
}
#endif /* JERRY_BUILTIN_PROMISE */
case ECMA_ERROR_URI:
{
prototype_id = ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE;
@@ -187,6 +199,112 @@ ecma_new_standard_error (ecma_standard_error_t error_type, /**< native error typ
return new_error_obj_p;
} /* ecma_new_standard_error */
#if JERRY_BUILTIN_PROMISE
/**
* aggregate-error object constructor.
*
* @return newly constructed aggregate errors
*/
ecma_value_t
ecma_new_aggregate_error (ecma_value_t error_list_val, /**< errors list */
ecma_value_t message_val) /**< message string */
{
ecma_object_t *new_error_object_p;
if (!ecma_is_value_undefined (message_val))
{
ecma_string_t *message_string_p = ecma_op_to_string (message_val);
if (JERRY_UNLIKELY (message_string_p == NULL))
{
return ECMA_VALUE_ERROR;
}
new_error_object_p = ecma_new_standard_error (ECMA_ERROR_AGGREGATE, message_string_p);
ecma_deref_ecma_string (message_string_p);
}
else
{
new_error_object_p = ecma_new_standard_error (ECMA_ERROR_AGGREGATE, NULL);
}
ecma_value_t using_iterator = ecma_op_get_method_by_symbol_id (error_list_val, LIT_GLOBAL_SYMBOL_ITERATOR);
if (ECMA_IS_VALUE_ERROR (using_iterator))
{
ecma_deref_object (new_error_object_p);
return using_iterator;
}
if (!ecma_is_value_undefined (using_iterator))
{
ecma_value_t next_method;
ecma_value_t iterator = ecma_op_get_iterator (error_list_val, using_iterator, &next_method);
ecma_free_value (using_iterator);
if (ECMA_IS_VALUE_ERROR (iterator))
{
ecma_deref_object (new_error_object_p);
return iterator;
}
ecma_collection_t *error_list_p = ecma_new_collection ();
ecma_value_t result = ECMA_VALUE_ERROR;
while (true)
{
ecma_value_t next = ecma_op_iterator_step (iterator, next_method);
if (ECMA_IS_VALUE_ERROR (next))
{
break;
}
if (next == ECMA_VALUE_FALSE)
{
result = ECMA_VALUE_UNDEFINED;
break;
}
/* 8.e.iii */
ecma_value_t next_error = ecma_op_iterator_value (next);
ecma_free_value (next);
if (ECMA_IS_VALUE_ERROR (next_error))
{
break;
}
ecma_collection_push_back (error_list_p, next_error);
}
ecma_free_value (iterator);
ecma_free_value (next_method);
if (ECMA_IS_VALUE_ERROR (result))
{
ecma_collection_free (error_list_p);
ecma_deref_object (new_error_object_p);
return result;
}
JERRY_ASSERT (ecma_is_value_undefined (result));
ecma_value_t error_list_arr = ecma_op_new_array_object_from_collection (error_list_p, true);
ecma_property_value_t *prop_value_p;
prop_value_p = ecma_create_named_data_property (new_error_object_p,
ecma_get_magic_string (LIT_MAGIC_STRING_ERRORS_UL),
ECMA_PROPERTY_CONFIGURABLE_WRITABLE,
NULL);
prop_value_p->value = error_list_arr;
ecma_free_value (error_list_arr);
}
return ecma_make_object_value (new_error_object_p);
} /* ecma_new_aggregate_error */
#endif /* JERRY_BUILTIN_PROMISE */
/**
* Return the error type for an Error object.
*
@@ -414,6 +532,26 @@ ecma_raise_uri_error (const char *msg_p) /**< error message */
return ecma_raise_standard_error (ECMA_ERROR_URI, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_uri_error */
#if JERRY_BUILTIN_PROMISE
/**
* Raise a AggregateError with the given errors and message.
*
* @return ecma value
* Returned value must be freed with ecma_free_value
*/
ecma_value_t
ecma_raise_aggregate_error (ecma_value_t error_list_val, /**< errors list */
ecma_value_t message_val) /**< error message */
{
ecma_value_t aggre_val = ecma_new_aggregate_error (error_list_val, message_val);
jcontext_raise_exception (aggre_val);
return ECMA_VALUE_ERROR;
} /* ecma_raise_aggregate_error */
#endif /* JERRY_BUILTIN_PROMISE */
/**
* @}
* @}
+8 -1
View File
@@ -47,7 +47,10 @@ typedef enum
ECMA_ERROR_REFERENCE, /**< ReferenceError */
ECMA_ERROR_SYNTAX, /**< SyntaxError */
ECMA_ERROR_TYPE, /**< TypeError */
ECMA_ERROR_URI /**< URIError */
ECMA_ERROR_URI, /**< URIError */
#if JERRY_BUILTIN_PROMISE
ECMA_ERROR_AGGREGATE, /**< AggregateError */
#endif /* JERRY_BUILTIN_PROMISE */
} ecma_standard_error_t;
ecma_standard_error_t ecma_get_error_type (ecma_object_t *error_object);
@@ -61,6 +64,10 @@ ecma_value_t ecma_raise_reference_error (const char *msg_p);
ecma_value_t ecma_raise_syntax_error (const char *msg_p);
ecma_value_t ecma_raise_type_error (const char *msg_p);
ecma_value_t ecma_raise_uri_error (const char *msg_p);
#if JERRY_BUILTIN_PROMISE
ecma_value_t ecma_new_aggregate_error (ecma_value_t error_list_val, ecma_value_t message_val);
ecma_value_t ecma_raise_aggregate_error (ecma_value_t error_list_val, ecma_value_t message_val);
#endif /* JERRY_BUILTIN_PROMISE */
/**
* @}
@@ -2626,6 +2626,7 @@ ecma_object_check_class_name_is_object (ecma_object_t *obj_p) /**< object */
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_GENERATOR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_AGGREGATE_ERROR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ERROR_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_DATE_PROTOTYPE)
@@ -600,8 +600,8 @@ ecma_promise_remaining_inc_or_dec (ecma_value_t remaining, /**< the remaining co
*/
ecma_value_t
ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**< function object */
const ecma_value_t args_p[], /**< argument list */
const uint32_t args_count) /**< argument number */
const ecma_value_t args_p[], /**< argument list */
const uint32_t args_count) /**< argument number */
{
JERRY_UNUSED (args_count);
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) function_obj_p;
@@ -613,7 +613,7 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**<
return ECMA_VALUE_UNDEFINED;
}
if (promise_type == ECMA_PROMISE_ALL_RESOLVE)
if (promise_type == ECMA_PROMISE_ALL_RESOLVE || promise_type == ECMA_PROMISE_ANY_REJECT)
{
/* 8. */
ecma_op_object_put_by_index (ecma_get_object_from_value (executor_p->values),
@@ -669,10 +669,22 @@ ecma_promise_all_or_all_settled_handler_cb (ecma_object_t *function_obj_p, /**<
{
ecma_value_t capability = executor_p->capability;
ecma_promise_capabality_t *capability_p = (ecma_promise_capabality_t *) ecma_get_object_from_value (capability);
ret = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve),
ECMA_VALUE_UNDEFINED,
&executor_p->values,
1);
if (promise_type == ECMA_PROMISE_ANY_REJECT)
{
ecma_value_t error_val = ecma_new_aggregate_error (executor_p->values, ECMA_VALUE_UNDEFINED);
ret = ecma_op_function_call (ecma_get_object_from_value (capability_p->reject),
ECMA_VALUE_UNDEFINED,
&error_val,
1);
ecma_free_value (error_val);
}
else
{
ret = ecma_op_function_call (ecma_get_object_from_value (capability_p->resolve),
ECMA_VALUE_UNDEFINED,
&executor_p->values,
1);
}
}
return ret;
+2 -1
View File
@@ -72,7 +72,8 @@ typedef enum
JERRY_ERROR_REFERENCE, /**< ReferenceError */
JERRY_ERROR_SYNTAX, /**< SyntaxError */
JERRY_ERROR_TYPE, /**< TypeError */
JERRY_ERROR_URI /**< URIError */
JERRY_ERROR_URI, /**< URIError */
JERRY_ERROR_AGGREGATE /**< AggregateError */
} jerry_error_t;
/**
+10 -1
View File
@@ -71,6 +71,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ADD, "add")
#endif
#if JERRY_BUILTIN_PROMISE
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ALL, "all")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ANY, "any")
#endif
#if JERRY_BUILTIN_MATH
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COS, "cos")
@@ -360,6 +361,9 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DELETE, "delete")
#if JERRY_BUILTIN_REGEXP && JERRY_ESNEXT
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DOTALL, "dotAll")
#endif
#if JERRY_BUILTIN_PROMISE
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ERRORS_UL, "errors")
#endif
#if JERRY_BUILTIN_ANNEXB
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ESCAPE, "escape")
#endif
@@ -917,6 +921,9 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, "setUTCSeconds")
#if JERRY_BUILTIN_NUMBER
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_EXPONENTIAL_UL, "toExponential")
#endif
#if JERRY_BUILTIN_PROMISE
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_AGGREGATE_ERROR_UL, "AggregateError")
#endif
#if JERRY_ESNEXT
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_ITERATOR_UL, "Array Iterator")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASYNC_GENERATOR_UL, "AsyncGenerator")
@@ -1137,7 +1144,9 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (13, LIT_MAGIC_STRING_GET_UTC_MINUTES_UL
#else
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (13, LIT_MAGIC_STRING_IS_PROTOTYPE_OF_UL)
#endif
#if JERRY_ESNEXT
#if JERRY_BUILTIN_PROMISE
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (14, LIT_MAGIC_STRING_AGGREGATE_ERROR_UL)
#elif JERRY_ESNEXT
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (14, LIT_MAGIC_STRING_ARRAY_ITERATOR_UL)
#elif JERRY_BUILTIN_BIGINT && JERRY_BUILTIN_TYPEDARRAY
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (14, LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL)
+3
View File
@@ -40,6 +40,7 @@ LIT_MAGIC_STRING_UTC_U = "UTC"
LIT_MAGIC_STRING_ABS = "abs"
LIT_MAGIC_STRING_ADD = "add"
LIT_MAGIC_STRING_ALL = "all"
LIT_MAGIC_STRING_ANY = "any"
LIT_MAGIC_STRING_COS = "cos"
LIT_MAGIC_STRING_EXP = "exp"
LIT_MAGIC_STRING_FOR = "for"
@@ -136,6 +137,7 @@ LIT_MAGIC_STRING_TRUNC = "trunc"
LIT_MAGIC_STRING_VALUE = "value"
LIT_MAGIC_STRING_RESOURCE_EVAL = "<eval>"
LIT_MAGIC_STRING_BIGINT_UL = "BigInt"
LIT_MAGIC_STRING_ERRORS_UL = "errors"
LIT_MAGIC_STRING_LOG10E_U = "LOG10E"
LIT_MAGIC_STRING_MODULE_UL = "Module"
LIT_MAGIC_STRING_NUMBER_UL = "Number"
@@ -362,6 +364,7 @@ LIT_MAGIC_STRING_LOCALE_COMPARE_UL = "localeCompare"
LIT_MAGIC_STRING_SET_UTC_MINUTES_UL = "setUTCMinutes"
LIT_MAGIC_STRING_SET_UTC_SECONDS_UL = "setUTCSeconds"
LIT_MAGIC_STRING_TO_EXPONENTIAL_UL = "toExponential"
LIT_MAGIC_STRING_AGGREGATE_ERROR_UL = "AggregateError"
LIT_MAGIC_STRING_ARRAY_ITERATOR_UL = "Array Iterator"
LIT_MAGIC_STRING_ASYNC_GENERATOR_UL = "AsyncGenerator"
LIT_MAGIC_STRING_BIGUINT64_ARRAY_UL = "BigUint64Array"