Skip to content

Commit 3fdc080

Browse files
committed
Introduce macro ECMA_STACK_USAGE_OVERFLOW to simplify the stack overflow check code
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent b4d17bb commit 3fdc080

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,14 +2044,14 @@ typedef enum
20442044
* Check the current stack usage. If the limit is reached a RangeError is raised.
20452045
* The macro argument specifies the return value which is usally ECMA_VALUE_ERROR or NULL.
20462046
*/
2047-
#define ECMA_CHECK_STACK_USAGE_RETURN(RETURN_VALUE) \
2048-
do \
2049-
{ \
2050-
if (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT) \
2051-
{ \
2052-
ecma_raise_maximum_callstack_error (); \
2053-
return RETURN_VALUE; \
2054-
} \
2047+
#define ECMA_CHECK_STACK_USAGE_RETURN(RETURN_VALUE) \
2048+
do \
2049+
{ \
2050+
if (JERRY_UNLIKELY (ECMA_STACK_USAGE_OVERFLOW (CONFIG_MEM_STACK_LIMIT))) \
2051+
{ \
2052+
ecma_raise_maximum_callstack_error (); \
2053+
return RETURN_VALUE; \
2054+
} \
20552055
} while (0)
20562056

20572057
/**

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ uint8_t *ecma_compiled_code_get_line_info (const ecma_compiled_code_t *bytecode_
492492
ecma_value_t ecma_get_source_name (const ecma_compiled_code_t *bytecode_p);
493493
#if (JERRY_STACK_LIMIT != 0)
494494
uintptr_t ecma_get_current_stack_usage (void);
495+
#define ECMA_STACK_USAGE_OVERFLOW(target) (ecma_get_current_stack_usage () > (target))
495496
#endif /* (JERRY_STACK_LIMIT != 0) */
496497

497498
/* ecma-helpers-external-pointers.c */

jerry-core/ecma/operations/ecma-regexp-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ ecma_regexp_run (ecma_regexp_ctx_t *re_ctx_p, /**< RegExp matcher context */
534534
const lit_utf8_byte_t *str_curr_p) /**< input string pointer */
535535
{
536536
#if (JERRY_STACK_LIMIT != 0)
537-
if (JERRY_UNLIKELY (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT))
537+
if (JERRY_UNLIKELY (ECMA_STACK_USAGE_OVERFLOW (CONFIG_MEM_STACK_LIMIT)))
538538
{
539539
return ECMA_RE_OUT_OF_STACK;
540540
}

jerry-core/parser/js/js-lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ lexer_construct_function_object (parser_context_t *context_p, /**< context */
27002700
uint32_t extra_status_flags) /**< extra status flags */
27012701
{
27022702
#if (JERRY_STACK_LIMIT != 0)
2703-
if (JERRY_UNLIKELY (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT))
2703+
if (JERRY_UNLIKELY (ECMA_STACK_USAGE_OVERFLOW (CONFIG_MEM_STACK_LIMIT)))
27042704
{
27052705
parser_raise_error (context_p, PARSER_ERR_STACK_OVERFLOW);
27062706
}

0 commit comments

Comments
 (0)