Add ecma_free_all_enqueued_jobs function (#2265)

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
This commit is contained in:
Daniel Balla
2018-04-05 09:49:25 +02:00
committed by László Langó
parent 634d9d38da
commit f06d637238
3 changed files with 21 additions and 0 deletions
+3
View File
@@ -222,6 +222,9 @@ jerry_cleanup (void)
jmem_heap_free_block (this_p, sizeof (jerry_context_data_header_t) + this_p->manager_p->bytes_needed);
}
#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN
ecma_free_all_enqueued_jobs ();
#endif /* CONFIG_DISABLE_ES2015_PROMISE_BUILTIN */
ecma_finalize ();
jmem_finalize ();
jerry_make_api_unavailable ();
@@ -346,6 +346,23 @@ ecma_process_all_enqueued_jobs (void)
return ret;
} /* ecma_process_all_enqueued_jobs */
/**
* Release enqueued Promise jobs.
*/
void
ecma_free_all_enqueued_jobs (void)
{
while (JERRY_CONTEXT (job_queue_head_p) != NULL)
{
ecma_job_queueitem_t *item_p = JERRY_CONTEXT (job_queue_head_p);
JERRY_CONTEXT (job_queue_head_p) = item_p->next_p;
void *job_p = item_p->job_p;
jmem_heap_free_block (item_p, sizeof (ecma_job_queueitem_t));
ecma_free_promise_reaction_job (job_p);
}
} /* ecma_free_all_enqueued_jobs */
/**
* @}
* @}
@@ -44,6 +44,7 @@ void ecma_job_queue_init (void);
void ecma_enqueue_promise_reaction_job (ecma_value_t reaction, ecma_value_t argument);
void ecma_enqueue_promise_resolve_thenable_job (ecma_value_t promise, ecma_value_t thenable, ecma_value_t then);
void ecma_free_all_enqueued_jobs (void);
ecma_value_t ecma_process_all_enqueued_jobs (void);