Rework the engine's internal recursion limit (#2969)

This patch unifies the recursion limit checking for RegExp, function call and JSON as well.
Until now the limit was only a counter which was increased/decreased at certain points.
This counter has been substituted with a numeric limit which allows to restrict the stack usage.

This patch fixes #2963 and resolves the closed #2258 issue.

Co-authored-by: Gabor Loki loki@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-07-23 15:31:37 +02:00
committed by GitHub
parent f53dba1a3a
commit 4a9e185840
20 changed files with 156 additions and 216 deletions
@@ -705,16 +705,7 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
|| ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION
|| !ecma_op_function_has_construct_flag (arguments_list_p));
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
if (JERRY_UNLIKELY (JERRY_CONTEXT (function_call_counter) == 0))
{
return ecma_raise_range_error (ECMA_ERR_MSG ("Maximum call stack size is exceeded."));
}
else
{
JERRY_CONTEXT (function_call_counter)--;
}
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
ECMA_CHECK_STACK_USAGE ();
switch (ecma_get_object_type (func_obj_p))
{
@@ -729,10 +720,6 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
arguments_list_p,
arguments_list_len);
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
JERRY_CONTEXT (function_call_counter)++;
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
return ret_value;
}
@@ -823,10 +810,6 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
ecma_free_value (this_binding);
}
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
JERRY_CONTEXT (function_call_counter)++;
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
return ret_value;
}
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
@@ -837,9 +820,6 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
this_arg_value,
arguments_list_p,
arguments_list_len);
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
JERRY_CONTEXT (function_call_counter)++;
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
if (JERRY_UNLIKELY (ecma_is_value_error_reference (ret_value)))
{
@@ -888,10 +868,6 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
ecma_deref_object (local_env_p);
}
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
JERRY_CONTEXT (function_call_counter)++;
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
return ret_value;
}
#endif /* ENABLED (JERRY_ES2015_ARROW_FUNCTION) */
@@ -902,10 +878,6 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
}
}
#if defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0)
JERRY_CONTEXT (function_call_counter)++;
#endif /* defined (JERRY_CALL_STACK_LIMIT) && (JERRY_CALL_STACK_LIMIT != 0) */
JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_DIRECT_EVAL;
ecma_extended_object_t *ext_function_p;