Default handlers should count as resolvers (#4611)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -115,18 +115,14 @@ ecma_promise_set_state (ecma_object_t *obj_p, /**< points to promise object */
|
|||||||
* Take a collection of Reactions and enqueue a new PromiseReactionJob for each Reaction.
|
* Take a collection of Reactions and enqueue a new PromiseReactionJob for each Reaction.
|
||||||
*
|
*
|
||||||
* See also: ES2015 25.4.1.8
|
* See also: ES2015 25.4.1.8
|
||||||
*
|
|
||||||
* @return true - if JERRY_PROMISE_CALLBACK define is 1, and at least one handler is found
|
|
||||||
* false - otherwise
|
|
||||||
*/
|
*/
|
||||||
static bool
|
static void
|
||||||
ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reactions */
|
ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reactions */
|
||||||
ecma_value_t value, /**< value for resolve or reject */
|
ecma_value_t value, /**< value for resolve or reject */
|
||||||
bool is_reject) /**< true if promise is rejected, false otherwise */
|
bool is_reject) /**< true if promise is rejected, false otherwise */
|
||||||
{
|
{
|
||||||
ecma_value_t *buffer_p = reactions->buffer_p;
|
ecma_value_t *buffer_p = reactions->buffer_p;
|
||||||
ecma_value_t *buffer_end_p = buffer_p + reactions->item_count;
|
ecma_value_t *buffer_end_p = buffer_p + reactions->item_count;
|
||||||
bool handler_found = false;
|
|
||||||
|
|
||||||
while (buffer_p < buffer_end_p)
|
while (buffer_p < buffer_end_p)
|
||||||
{
|
{
|
||||||
@@ -137,9 +133,6 @@ ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reac
|
|||||||
if (JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (object_with_tag))
|
if (JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (object_with_tag))
|
||||||
{
|
{
|
||||||
ecma_enqueue_promise_async_reaction_job (object, value, is_reject);
|
ecma_enqueue_promise_async_reaction_job (object, value, is_reject);
|
||||||
#if JERRY_PROMISE_CALLBACK
|
|
||||||
handler_found = true;
|
|
||||||
#endif /* JERRY_PROMISE_CALLBACK */
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,9 +143,6 @@ ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reac
|
|||||||
if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (object_with_tag))
|
if (JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (object_with_tag))
|
||||||
{
|
{
|
||||||
handler = *buffer_p++;
|
handler = *buffer_p++;
|
||||||
#if JERRY_PROMISE_CALLBACK
|
|
||||||
handler_found = true;
|
|
||||||
#endif /* JERRY_PROMISE_CALLBACK */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_enqueue_promise_reaction_job (object, handler, value);
|
ecma_enqueue_promise_reaction_job (object, handler, value);
|
||||||
@@ -169,9 +159,6 @@ ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reac
|
|||||||
if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (object_with_tag))
|
if (JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (object_with_tag))
|
||||||
{
|
{
|
||||||
handler = *buffer_p++;
|
handler = *buffer_p++;
|
||||||
#if JERRY_PROMISE_CALLBACK
|
|
||||||
handler_found = true;
|
|
||||||
#endif /* JERRY_PROMISE_CALLBACK */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_enqueue_promise_reaction_job (object, handler, value);
|
ecma_enqueue_promise_reaction_job (object, handler, value);
|
||||||
@@ -181,8 +168,6 @@ ecma_promise_trigger_reactions (ecma_collection_t *reactions, /**< lists of reac
|
|||||||
buffer_p++;
|
buffer_p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler_found;
|
|
||||||
} /* ecma_promise_trigger_reactions */
|
} /* ecma_promise_trigger_reactions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,8 +231,10 @@ ecma_reject_promise (ecma_value_t promise, /**< promise */
|
|||||||
ecma_collection_t *reactions = promise_p->reactions;
|
ecma_collection_t *reactions = promise_p->reactions;
|
||||||
|
|
||||||
/* Fulfill reactions will never be triggered. */
|
/* Fulfill reactions will never be triggered. */
|
||||||
|
ecma_promise_trigger_reactions (reactions, reason, true);
|
||||||
|
|
||||||
#if JERRY_PROMISE_CALLBACK
|
#if JERRY_PROMISE_CALLBACK
|
||||||
if (!ecma_promise_trigger_reactions (reactions, reason, true))
|
if (reactions->item_count == 0)
|
||||||
{
|
{
|
||||||
((ecma_extended_object_t *) obj_p)->u.class_prop.extra_info |= ECMA_PROMISE_UNHANDLED_REJECT;
|
((ecma_extended_object_t *) obj_p)->u.class_prop.extra_info |= ECMA_PROMISE_UNHANDLED_REJECT;
|
||||||
|
|
||||||
@@ -260,8 +247,6 @@ ecma_reject_promise (ecma_value_t promise, /**< promise */
|
|||||||
JERRY_CONTEXT (promise_callback_user_p));
|
JERRY_CONTEXT (promise_callback_user_p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* !JERRY_PROMISE_CALLBACK */
|
|
||||||
ecma_promise_trigger_reactions (reactions, reason, true);
|
|
||||||
#endif /* JERRY_PROMISE_CALLBACK */
|
#endif /* JERRY_PROMISE_CALLBACK */
|
||||||
|
|
||||||
promise_p->reactions = ecma_new_collection ();
|
promise_p->reactions = ecma_new_collection ();
|
||||||
@@ -946,8 +931,7 @@ ecma_promise_do_then (ecma_value_t promise, /**< the promise which call 'then' *
|
|||||||
ecma_free_value (reason);
|
ecma_free_value (reason);
|
||||||
|
|
||||||
#if JERRY_PROMISE_CALLBACK
|
#if JERRY_PROMISE_CALLBACK
|
||||||
if (on_rejected != ECMA_VALUE_FALSE
|
if (ecma_promise_get_flags (promise_obj_p) & ECMA_PROMISE_UNHANDLED_REJECT)
|
||||||
&& ecma_promise_get_flags (promise_obj_p) & ECMA_PROMISE_UNHANDLED_REJECT)
|
|
||||||
{
|
{
|
||||||
promise_p->header.u.class_prop.extra_info &= (uint16_t) ~ECMA_PROMISE_UNHANDLED_REJECT;
|
promise_p->header.u.class_prop.extra_info &= (uint16_t) ~ECMA_PROMISE_UNHANDLED_REJECT;
|
||||||
|
|
||||||
|
|||||||
@@ -335,12 +335,20 @@ main (void)
|
|||||||
"async function f(p) { try { await p; } catch(e) { await p; } }"
|
"async function f(p) { try { await p; } catch(e) { await p; } }"
|
||||||
"f(Promise.reject(4))\n");
|
"f(Promise.reject(4))\n");
|
||||||
|
|
||||||
|
/* Test chained then. */
|
||||||
|
static uint8_t events23[] = { C, RJ, RWH, CP, CHA, CP, BR, RJ, AR, BR, RS, AR, E };
|
||||||
|
|
||||||
|
run_eval (events23,
|
||||||
|
"'use strict'\n"
|
||||||
|
"var p = Promise.reject(0)\n"
|
||||||
|
"p.then(() => {}).catch(() => {})\n");
|
||||||
|
|
||||||
/* Test disabled filters. */
|
/* Test disabled filters. */
|
||||||
jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_DISABLE, promise_callback, (void *) &user);
|
jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_DISABLE, promise_callback, (void *) &user);
|
||||||
|
|
||||||
static uint8_t events23[] = { E };
|
static uint8_t events24[] = { E };
|
||||||
|
|
||||||
run_eval (events23,
|
run_eval (events24,
|
||||||
"'use strict'\n"
|
"'use strict'\n"
|
||||||
"async function f(p) { await p }"
|
"async function f(p) { await p }"
|
||||||
"f(Promise.resolve(1))\n");
|
"f(Promise.resolve(1))\n");
|
||||||
@@ -349,9 +357,9 @@ main (void)
|
|||||||
filters = JERRY_PROMISE_EVENT_FILTER_REACTION_JOB | JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB;
|
filters = JERRY_PROMISE_EVENT_FILTER_REACTION_JOB | JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB;
|
||||||
jerry_promise_set_callback (filters, promise_callback, (void *) &user);
|
jerry_promise_set_callback (filters, promise_callback, (void *) &user);
|
||||||
|
|
||||||
static uint8_t events24[] = { BR, AR, BRS, ARS, E };
|
static uint8_t events25[] = { BR, AR, BRS, ARS, E };
|
||||||
|
|
||||||
run_eval (events24,
|
run_eval (events25,
|
||||||
"'use strict'\n"
|
"'use strict'\n"
|
||||||
"async function f(p) { await p }"
|
"async function f(p) { await p }"
|
||||||
"f(Promise.resolve(1).then(() => {}))\n");
|
"f(Promise.resolve(1).then(() => {}))\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user