Fix error handling in scanner when in case of OOM (#3793)

This patch fixes #3786 and fixes #3788.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-05-27 14:40:43 +02:00
committed by GitHub
parent 8f76a1f382
commit 69f8e78c2f
+16 -12
View File
@@ -3159,12 +3159,6 @@ scan_completed:
} }
PARSER_CATCH PARSER_CATCH
{ {
/* Ignore the errors thrown by the lexer. */
if (context_p->error != PARSER_ERR_OUT_OF_MEMORY)
{
context_p->error = PARSER_ERR_NO_ERROR;
}
#if ENABLED (JERRY_ES2015) #if ENABLED (JERRY_ES2015)
while (scanner_context.active_binding_list_p != NULL) while (scanner_context.active_binding_list_p != NULL)
{ {
@@ -3172,6 +3166,11 @@ scan_completed:
} }
#endif /* ENABLED (JERRY_ES2015) */ #endif /* ENABLED (JERRY_ES2015) */
if (JERRY_UNLIKELY (context_p->error != PARSER_ERR_OUT_OF_MEMORY))
{
/* Ignore the errors thrown by the lexer. */
context_p->error = PARSER_ERR_NO_ERROR;
/* The following code may allocate memory, so it is enclosed in a try/catch. */ /* The following code may allocate memory, so it is enclosed in a try/catch. */
PARSER_TRY (context_p->try_buffer) PARSER_TRY (context_p->try_buffer)
{ {
@@ -3193,8 +3192,15 @@ scan_completed:
} }
PARSER_CATCH PARSER_CATCH
{ {
JERRY_ASSERT (context_p->error == PARSER_ERR_NO_ERROR); JERRY_ASSERT (context_p->error == PARSER_ERR_OUT_OF_MEMORY);
}
PARSER_TRY_END
}
JERRY_ASSERT (context_p->error == PARSER_ERR_NO_ERROR || context_p->error == PARSER_ERR_OUT_OF_MEMORY);
if (context_p->error == PARSER_ERR_OUT_OF_MEMORY)
{
while (scanner_context.active_literal_pool_p != NULL) while (scanner_context.active_literal_pool_p != NULL)
{ {
scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p; scanner_literal_pool_t *literal_pool_p = scanner_context.active_literal_pool_p;
@@ -3204,12 +3210,10 @@ scan_completed:
parser_list_free (&literal_pool_p->literal_pool); parser_list_free (&literal_pool_p->literal_pool);
scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t)); scanner_free (literal_pool_p, sizeof (scanner_literal_pool_t));
} }
}
PARSER_TRY_END
#if ENABLED (JERRY_ES2015) parser_stack_free (context_p);
context_p->status_flags &= (uint32_t) ~PARSER_IS_GENERATOR_FUNCTION; return;
#endif /* ENABLED (JERRY_ES2015) */ }
} }
PARSER_TRY_END PARSER_TRY_END