diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-error.c b/jerry-core/ecma/builtin-objects/ecma-builtin-error.c index c50543f0a..097a2e3b2 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-error.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-error.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_COMMON, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_COMMON); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_COMMON, arguments_list_p, arguments_list_len); } /* ecma_builtin_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c index 279ba6789..ddf95003a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_eval_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_EVAL, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_EVAL); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_EVAL, arguments_list_p, arguments_list_len); } /* ecma_builtin_eval_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c new file mode 100644 index 000000000..a3af39279 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c @@ -0,0 +1,81 @@ +/* Copyright 2016 Samsung Electronics Co., Ltd. + * Copyright 2016 University of Szeged + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-alloc.h" +#include "ecma-builtins.h" +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" +#include "ecma-objects.h" +#include "ecma-try-catch-macro.h" +#include "jrt.h" + +#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltinhelpers + * @{ + */ + +/** + * Handle calling [[Call]] of a built-in error object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**< native error type */ + const ecma_value_t *arguments_list_p, /**< arguments list */ + ecma_length_t arguments_list_len) /**< number of arguments */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + if (arguments_list_len != 0 + && !ecma_is_value_undefined (arguments_list_p[0])) + { + ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); + + ECMA_TRY_CATCH (msg_str_value, + ecma_op_to_string (arguments_list_p[0]), + ret_value); + + ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); + ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type, + message_string_p); + ret_value = ecma_make_object_value (new_error_object_p); + + ECMA_FINALIZE (msg_str_value); + + return ret_value; + } + else + { + ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type); + + return ecma_make_object_value (new_error_object_p); + } +} /* ecma_builtin_helper_error_dispatch_call */ + +/** + * @} + * @} + */ + +#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h index feca31c0d..d27eec501 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h @@ -18,6 +18,7 @@ #define ECMA_BUILTIN_HELPERS_H #include "ecma-globals.h" +#include "ecma-exceptions.h" /** \addtogroup ecma ECMA * @{ @@ -165,6 +166,15 @@ ecma_builtin_helper_json_create_formatted_json (ecma_string_t *, ecma_string_t * extern ecma_value_t ecma_builtin_helper_json_create_non_formatted_json (ecma_string_t *, ecma_string_t *, ecma_collection_header_t *); +/* ecma-builtin-helper-error.c */ + +#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS + +extern ecma_value_t +ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t, const ecma_value_t *, ecma_length_t); + +#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */ + /** * @} * @} diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c index 6530d9052..ee62da6ac 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_range_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_RANGE, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_RANGE); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_RANGE, arguments_list_p, arguments_list_len); } /* ecma_builtin_range_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c index 294f078e6..6684dbe7c 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_reference_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_REFERENCE, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_REFERENCE); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_REFERENCE, arguments_list_p, arguments_list_len); } /* ecma_builtin_reference_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c index b658e154a..2cb89b4a1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_syntax_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_SYNTAX, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_SYNTAX); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_SYNTAX, arguments_list_p, arguments_list_len); } /* ecma_builtin_syntax_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c index f37de16c9..3ec7053d8 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_type_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_TYPE, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_TYPE); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_TYPE, arguments_list_p, arguments_list_len); } /* ecma_builtin_type_error_dispatch_call */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c index 654a40eaa..7e87d3654 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c @@ -20,6 +20,7 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" +#include "ecma-builtin-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jrt.h" @@ -52,32 +53,7 @@ ecma_value_t ecma_builtin_uri_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */ ecma_length_t arguments_list_len) /**< number of arguments */ { - JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); - - if (arguments_list_len != 0 - && !ecma_is_value_undefined (arguments_list_p[0])) - { - ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); - - ECMA_TRY_CATCH (msg_str_value, - ecma_op_to_string (arguments_list_p[0]), - ret_value); - - ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value); - ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_URI, - message_string_p); - ret_value = ecma_make_object_value (new_error_object_p); - - ECMA_FINALIZE (msg_str_value); - - return ret_value; - } - else - { - ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_URI); - - return ecma_make_object_value (new_error_object_p); - } + return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_URI, arguments_list_p, arguments_list_len); } /* ecma_builtin_uri_error_dispatch_call */ /**