From dafbaa742e4c34764eb74e1dcf86ad31bc830e46 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 8 Sep 2014 19:09:34 +0400 Subject: [PATCH] Adding configuration option for ECMA exception support. --- src/config.h | 5 +++ src/libcoreint/interpreter.c | 2 ++ src/libecmaobjects/ecma-globals.h | 2 ++ src/libecmaobjects/ecma-helpers-value.c | 42 +++++++++++++++++++------ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/config.h b/src/config.h index 5ddb6436f..7baea9905 100644 --- a/src/config.h +++ b/src/config.h @@ -99,4 +99,9 @@ #define CONFIG_ECMA_CHAR_ASCII // #define CONFIG_ECMA_CHAR_UTF16 +/** + * Enable ecma-exception support + */ +#define CONFIG_ECMA_EXCEPTION_SUPPORT + #endif /* !CONFIG_H */ diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 789e16553..08c3431bc 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -94,10 +94,12 @@ run_int (void) /* SyntaxError should be treated as an early error */ JERRY_UNREACHABLE (); } +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT case ECMA_COMPLETION_TYPE_THROW: { jerry_exit (ERR_UNHANDLED_EXCEPTION); } +#endif /* CONFIG_ECMA_EXCEPTION_SUPPORT */ } JERRY_UNREACHABLE (); diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 1c1f79c1a..261ee9277 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -103,7 +103,9 @@ typedef enum ECMA_COMPLETION_TYPE_RETURN, /**< block completed with return */ ECMA_COMPLETION_TYPE_BREAK, /**< block completed with break */ ECMA_COMPLETION_TYPE_CONTINUE, /**< block completed with continue */ +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT ECMA_COMPLETION_TYPE_THROW, /**< block completed with throw */ +#endif /* CONFIG_ECMA_EXCEPTION_SUPPORT */ ECMA_COMPLETION_TYPE_EXIT, /**< implementation-defined completion type for finishing script execution */ ECMA_COMPLETION_TYPE_META /**< implementation-defined completion type diff --git a/src/libecmaobjects/ecma-helpers-value.c b/src/libecmaobjects/ecma-helpers-value.c index b276d1815..f121622f5 100644 --- a/src/libecmaobjects/ecma-helpers-value.c +++ b/src/libecmaobjects/ecma-helpers-value.c @@ -287,12 +287,16 @@ ecma_completion_value_t ecma_make_completion_value (ecma_completion_type_t type, /**< type */ ecma_value_t value) /**< value */ { - JERRY_ASSERT (type == ECMA_COMPLETION_TYPE_NORMAL - || type == ECMA_COMPLETION_TYPE_THROW - || type == ECMA_COMPLETION_TYPE_RETURN - || type == ECMA_COMPLETION_TYPE_EXIT - || (type == ECMA_COMPLETION_TYPE_META - && ecma_is_value_empty (value))); + const bool is_type_ok = (type == ECMA_COMPLETION_TYPE_NORMAL +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT + || type == ECMA_COMPLETION_TYPE_THROW +#endif /* CONFIG_ECMA_EXCEPTION_SUPPORT */ + || type == ECMA_COMPLETION_TYPE_RETURN + || type == ECMA_COMPLETION_TYPE_EXIT + || (type == ECMA_COMPLETION_TYPE_META + && ecma_is_value_empty (value))); + + JERRY_ASSERT (is_type_ok); ecma_completion_value_t ret_value = (ecma_completion_value_t) { @@ -368,7 +372,13 @@ ecma_make_normal_completion_value (ecma_value_t value) /**< value */ ecma_completion_value_t ecma_make_throw_completion_value (ecma_value_t value) /**< value */ { +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT return ecma_make_completion_value (ECMA_COMPLETION_TYPE_THROW, value); +#else /* CONFIG_ECMA_EXCEPTION_SUPPORT */ + (void) value; + + jerry_exit (ERR_UNHANDLED_EXCEPTION); +#endif /* !CONFIG_ECMA_EXCEPTION_SUPPORT */ } /* ecma_make_throw_completion_value */ /** @@ -445,10 +455,14 @@ ecma_make_meta_completion_value (void) ecma_completion_value_t ecma_copy_completion_value (ecma_completion_value_t value) /**< completion value */ { - JERRY_ASSERT (value.type == ECMA_COMPLETION_TYPE_NORMAL - || value.type == ECMA_COMPLETION_TYPE_THROW - || value.type == ECMA_COMPLETION_TYPE_RETURN - || value.type == ECMA_COMPLETION_TYPE_EXIT); + const bool is_type_ok = (value.type == ECMA_COMPLETION_TYPE_NORMAL +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT + || value.type == ECMA_COMPLETION_TYPE_THROW +#endif /* CONFIG_ECMA_EXCEPTION_SUPPORT */ + || value.type == ECMA_COMPLETION_TYPE_RETURN + || value.type == ECMA_COMPLETION_TYPE_EXIT); + + JERRY_ASSERT (is_type_ok); return ecma_make_completion_value (value.type, ecma_copy_value (value.u.value, true)); @@ -463,7 +477,9 @@ ecma_free_completion_value (ecma_completion_value_t completion_value) /**< compl switch ((ecma_completion_type_t)completion_value.type) { case ECMA_COMPLETION_TYPE_NORMAL: +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT case ECMA_COMPLETION_TYPE_THROW: +#endif /* CONFIG_ECMA_EXCEPTION_SUPPORT */ case ECMA_COMPLETION_TYPE_RETURN: { ecma_free_value (completion_value.u.value, true); @@ -508,7 +524,13 @@ ecma_is_completion_value_normal (ecma_completion_value_t value) /**< completion bool ecma_is_completion_value_throw (ecma_completion_value_t value) /**< completion value */ { +#ifdef CONFIG_ECMA_EXCEPTION_SUPPORT return (value.type == ECMA_COMPLETION_TYPE_THROW); +#else /* CONFIG_ECMA_EXCEPTION_SUPPORT */ + (void) value; + + return false; +#endif /* !CONFIG_ECMA_EXCEPTION_SUPPORT */ } /* ecma_is_completion_value_throw */ /**