Add Promise Prototype Dispatcher (#4309)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
This commit is contained in:
@@ -21,6 +21,22 @@
|
|||||||
#define ECMA_BUILTINS_INTERNAL
|
#define ECMA_BUILTINS_INTERNAL
|
||||||
#include "ecma-builtins-internal.h"
|
#include "ecma-builtins-internal.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object has a custom dispatch function.
|
||||||
|
*/
|
||||||
|
#define BUILTIN_CUSTOM_DISPATCH
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of built-in routine identifiers.
|
||||||
|
*/
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ECMA_PROMISE_PROTOTYPE_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1,
|
||||||
|
ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN,
|
||||||
|
ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH,
|
||||||
|
ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY
|
||||||
|
};
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-promise-prototype.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-promise-prototype.inc.h"
|
||||||
#define BUILTIN_UNDERSCORED_ID promise_prototype
|
#define BUILTIN_UNDERSCORED_ID promise_prototype
|
||||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
@@ -36,54 +52,43 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promise routine: then.
|
* Dispatcher of the built-in's routines
|
||||||
*
|
*
|
||||||
* See also: 25.4.5.3
|
* @return ecma value
|
||||||
*
|
|
||||||
* @return ecma value of a new promise object.
|
|
||||||
* Returned value must be freed with ecma_free_value.
|
* Returned value must be freed with ecma_free_value.
|
||||||
*/
|
*/
|
||||||
static ecma_value_t
|
ecma_value_t
|
||||||
ecma_builtin_promise_prototype_then (ecma_value_t this_arg, /**< this argument */
|
ecma_builtin_promise_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
|
||||||
ecma_value_t on_fulfilled, /**< on_fulfilled function */
|
* identifier */
|
||||||
ecma_value_t on_rejected) /**< on_rejected function */
|
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 */
|
||||||
{
|
{
|
||||||
return ecma_promise_then (this_arg,
|
ecma_value_t arg_1 = (arguments_number > 0) ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
|
||||||
on_fulfilled,
|
|
||||||
on_rejected);
|
|
||||||
} /* ecma_builtin_promise_prototype_then */
|
|
||||||
|
|
||||||
/**
|
switch (builtin_routine_id)
|
||||||
* Promise routine: catch.
|
{
|
||||||
*
|
case ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN:
|
||||||
* See also: 25.4.5.1
|
{
|
||||||
*
|
ecma_value_t arg_2 = (arguments_number > 1) ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||||
* @return ecma value of a new promise object.
|
return ecma_promise_then (this_arg, arg_1, arg_2);
|
||||||
* Returned value must be freed with ecma_free_value.
|
}
|
||||||
*/
|
case ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH:
|
||||||
static ecma_value_t
|
{
|
||||||
ecma_builtin_promise_prototype_catch (ecma_value_t this_arg, /**< this argument */
|
ecma_value_t args[] = {ECMA_VALUE_UNDEFINED, arg_1};
|
||||||
ecma_value_t on_rejected) /**< on_rejected function */
|
return ecma_op_invoke_by_magic_id (this_arg, LIT_MAGIC_STRING_THEN, args, 2);
|
||||||
{
|
}
|
||||||
ecma_value_t args[] = {ECMA_VALUE_UNDEFINED, on_rejected};
|
case ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY:
|
||||||
return ecma_op_invoke_by_magic_id (this_arg, LIT_MAGIC_STRING_THEN, args, 2);
|
{
|
||||||
} /* ecma_builtin_promise_prototype_catch */
|
return ecma_promise_finally (this_arg, arg_1);
|
||||||
|
}
|
||||||
/**
|
default:
|
||||||
* Promise routine: finally.
|
{
|
||||||
*
|
JERRY_UNREACHABLE ();
|
||||||
* See also:
|
}
|
||||||
* ECMA-262 v11, 25.6.5.3
|
}
|
||||||
*
|
} /* ecma_builtin_promise_prototype_dispatch_routine */
|
||||||
* @return ecma value of a new promise object.
|
|
||||||
* Returned value must be freed with ecma_free_value.
|
|
||||||
*/
|
|
||||||
static ecma_value_t
|
|
||||||
ecma_builtin_promise_prototype_finally (ecma_value_t this_arg, /**< this argument */
|
|
||||||
ecma_value_t on_finally) /**< on_finally function */
|
|
||||||
{
|
|
||||||
return ecma_promise_finally (this_arg, on_finally);
|
|
||||||
} /* ecma_builtin_promise_prototype_finally */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
|||||||
LIT_MAGIC_STRING_PROMISE_UL,
|
LIT_MAGIC_STRING_PROMISE_UL,
|
||||||
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
ECMA_PROPERTY_FLAG_CONFIGURABLE)
|
||||||
|
|
||||||
ROUTINE (LIT_MAGIC_STRING_THEN, ecma_builtin_promise_prototype_then, 2, 2)
|
ROUTINE (LIT_MAGIC_STRING_THEN, ECMA_PROMISE_PROTOTYPE_ROUTINE_THEN, 2, 2)
|
||||||
ROUTINE (LIT_MAGIC_STRING_CATCH, ecma_builtin_promise_prototype_catch, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_CATCH, ECMA_PROMISE_PROTOTYPE_ROUTINE_CATCH, 1, 1)
|
||||||
ROUTINE (LIT_MAGIC_STRING_FINALLY, ecma_builtin_promise_prototype_finally, 1, 1)
|
ROUTINE (LIT_MAGIC_STRING_FINALLY, ECMA_PROMISE_PROTOTYPE_ROUTINE_FINALLY, 1, 1)
|
||||||
|
|
||||||
#endif /* ENABLED (JERRY_BUILTIN_PROMISE) */
|
#endif /* ENABLED (JERRY_BUILTIN_PROMISE) */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user