Skip to content

Commit e94bffc

Browse files
author
Daniel Balla
committed
Add ecma_free_all_enqueued_jobs function
This function releases any remaining promise job that wasn't completed. Also added this function to `jerry_cleanup ()`, therefore it will be automatically run. JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
1 parent a0e3157 commit e94bffc

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

jerry-core/api/jerry.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ jerry_cleanup (void)
222222
jmem_heap_free_block (this_p, sizeof (jerry_context_data_header_t) + this_p->manager_p->bytes_needed);
223223
}
224224

225+
ecma_free_all_enqueued_jobs();
225226
ecma_finalize ();
226227
jmem_finalize ();
227228
jerry_make_api_unavailable ();

jerry-core/ecma/operations/ecma-jobqueue.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,23 @@ ecma_process_all_enqueued_jobs (void)
346346
return ret;
347347
} /* ecma_process_all_enqueued_jobs */
348348

349+
/**
350+
* Release enqueued Promise jobs.
351+
*/
352+
void
353+
ecma_free_all_enqueued_jobs (void)
354+
{
355+
while (JERRY_CONTEXT (job_queue_head_p) != NULL)
356+
{
357+
ecma_job_queueitem_t *item_p = JERRY_CONTEXT (job_queue_head_p);
358+
JERRY_CONTEXT (job_queue_head_p) = JERRY_CONTEXT (job_queue_head_p)->next_p;
359+
void *job_p = item_p->job_p;
360+
jmem_heap_free_block (item_p, sizeof (ecma_job_queueitem_t));
361+
362+
ecma_free_promise_reaction_job (job_p);
363+
}
364+
} /* ecma_free_all_enqueued_jobs */
365+
349366
/**
350367
* @}
351368
* @}

jerry-core/ecma/operations/ecma-jobqueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void ecma_job_queue_init (void);
4444

4545
void ecma_enqueue_promise_reaction_job (ecma_value_t reaction, ecma_value_t argument);
4646
void ecma_enqueue_promise_resolve_thenable_job (ecma_value_t promise, ecma_value_t thenable, ecma_value_t then);
47+
void ecma_free_all_enqueued_jobs (void);
4748

4849
ecma_value_t ecma_process_all_enqueued_jobs (void);
4950

0 commit comments

Comments
 (0)