2020#include "ecma-objects.h"
2121#include "ecma-promise-object.h"
2222#include "jcontext.h"
23+ #include "opcodes.h"
2324
2425#if ENABLED (JERRY_BUILTIN_PROMISE )
2526
@@ -46,6 +47,16 @@ typedef struct
4647 ecma_value_t argument ; /**< argument for the reaction */
4748} ecma_job_promise_reaction_t ;
4849
50+ /**
51+ * Description of the PromiseAsyncReactionJob
52+ */
53+ typedef struct
54+ {
55+ ecma_job_queue_item_t header ; /**< job queue item header */
56+ ecma_value_t executable_object ; /**< executable object */
57+ ecma_value_t argument ; /**< argument for the reaction */
58+ } ecma_job_promise_async_reaction_t ;
59+
4960/**
5061 * Description of the PromiseResolveThenableJob
5162 */
@@ -103,6 +114,21 @@ ecma_free_promise_reaction_job (ecma_job_promise_reaction_t *job_p) /**< points
103114 jmem_heap_free_block (job_p , sizeof (ecma_job_promise_reaction_t ));
104115} /* ecma_free_promise_reaction_job */
105116
117+ /**
118+ * Free the heap and the member of the PromiseAsyncReactionJob.
119+ */
120+ static void
121+ ecma_free_promise_async_reaction_job (ecma_job_promise_async_reaction_t * job_p ) /**< points to the
122+ * PromiseAsyncReactionJob */
123+ {
124+ JERRY_ASSERT (job_p != NULL );
125+
126+ ecma_free_value (job_p -> executable_object );
127+ ecma_free_value (job_p -> argument );
128+
129+ jmem_heap_free_block (job_p , sizeof (ecma_job_promise_async_reaction_t ));
130+ } /* ecma_free_promise_async_reaction_job */
131+
106132/**
107133 * Free the heap and the member of the PromiseResolveThenableJob.
108134 */
@@ -196,6 +222,31 @@ ecma_process_promise_reaction_job (ecma_job_promise_reaction_t *job_p) /**< the
196222 return status ;
197223} /* ecma_process_promise_reaction_job */
198224
225+ /**
226+ * The processor for PromiseAsyncReactionJob.
227+ *
228+ * @return ecma value
229+ * Returned value must be freed with ecma_free_value
230+ */
231+ static ecma_value_t
232+ ecma_process_promise_async_reaction_job (ecma_job_promise_async_reaction_t * job_p ) /**< the job to be operated */
233+ {
234+ ecma_object_t * object_p = ecma_get_object_from_value (job_p -> executable_object );
235+ vm_executable_object_t * executable_object_p = (vm_executable_object_t * ) object_p ;
236+
237+ if (ecma_job_queue_get_type (& job_p -> header ) == ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED )
238+ {
239+ executable_object_p -> frame_ctx .byte_code_p = opfunc_resume_executable_object_with_throw ;
240+ }
241+
242+ ecma_value_t result = opfunc_resume_executable_object (executable_object_p , job_p -> argument );
243+ /* Argument reference is taken by opfunc_resume_executable_object. */
244+ job_p -> argument = ECMA_VALUE_UNDEFINED ;
245+ ecma_free_promise_async_reaction_job (job_p );
246+
247+ return result ;
248+ } /* ecma_process_promise_async_reaction_job */
249+
199250/**
200251 * Process the PromiseResolveThenableJob.
201252 *
@@ -273,7 +324,7 @@ ecma_enqueue_job (ecma_job_queue_item_t *job_p) /**< the job */
273324} /* ecma_enqueue_job */
274325
275326/**
276- * Enqueue a PromiseReactionJob into the jobqueue .
327+ * Enqueue a PromiseReactionJob into the job queue .
277328 */
278329void
279330ecma_enqueue_promise_reaction_job (ecma_value_t capability , /**< capability object */
@@ -291,7 +342,25 @@ ecma_enqueue_promise_reaction_job (ecma_value_t capability, /**< capability obje
291342} /* ecma_enqueue_promise_reaction_job */
292343
293344/**
294- * Enqueue a PromiseResolveThenableJob into the jobqueue.
345+ * Enqueue a PromiseAsyncReactionJob into the job queue.
346+ */
347+ void
348+ ecma_enqueue_promise_async_reaction_job (ecma_value_t executable_object , /**< executable object */
349+ ecma_value_t argument , /**< argument */
350+ bool is_rejected ) /**< is_fulfilled */
351+ {
352+ ecma_job_promise_async_reaction_t * job_p ;
353+ job_p = (ecma_job_promise_async_reaction_t * ) jmem_heap_alloc_block (sizeof (ecma_job_promise_async_reaction_t ));
354+ job_p -> header .next_and_type = (is_rejected ? ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED
355+ : ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED );
356+ job_p -> executable_object = ecma_copy_value (executable_object );
357+ job_p -> argument = ecma_copy_value (argument );
358+
359+ ecma_enqueue_job (& job_p -> header );
360+ } /* ecma_enqueue_promise_async_reaction_job */
361+
362+ /**
363+ * Enqueue a PromiseResolveThenableJob into the job queue.
295364 */
296365void
297366ecma_enqueue_promise_resolve_thenable_job (ecma_value_t promise , /**< promise to be resolved */
@@ -338,6 +407,12 @@ ecma_process_all_enqueued_jobs (void)
338407 ret = ecma_process_promise_reaction_job ((ecma_job_promise_reaction_t * ) job_p );
339408 break ;
340409 }
410+ case ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED :
411+ case ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED :
412+ {
413+ ret = ecma_process_promise_async_reaction_job ((ecma_job_promise_async_reaction_t * ) job_p );
414+ break ;
415+ }
341416 default :
342417 {
343418 JERRY_ASSERT (ecma_job_queue_get_type (job_p ) == ECMA_JOB_PROMISE_THENABLE );
@@ -369,6 +444,12 @@ ecma_free_all_enqueued_jobs (void)
369444 ecma_free_promise_reaction_job ((ecma_job_promise_reaction_t * ) job_p );
370445 break ;
371446 }
447+ case ECMA_JOB_PROMISE_ASYNC_REACTION_FULFILLED :
448+ case ECMA_JOB_PROMISE_ASYNC_REACTION_REJECTED :
449+ {
450+ ecma_free_promise_async_reaction_job ((ecma_job_promise_async_reaction_t * ) job_p );
451+ break ;
452+ }
372453 default :
373454 {
374455 JERRY_ASSERT (ecma_job_queue_get_type (job_p ) == ECMA_JOB_PROMISE_THENABLE );
0 commit comments