1 /* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "ecma-alloc.h" 17 #include "ecma-builtins.h" 18 #include "ecma-conversion.h" 19 #include "ecma-exceptions.h" 20 #include "ecma-gc.h" 21 #include "ecma-globals.h" 22 #include "ecma-helpers.h" 23 #include "ecma-builtin-helpers.h" 24 #include "ecma-objects.h" 25 #include "ecma-try-catch-macro.h" 26 #include "jrt.h" 27 28 /** \addtogroup ecma ECMA 29 * @{ 30 * 31 * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations 32 * @{ 33 */ 34 35 /** 36 * Handle calling [[Call]] of a built-in error object 37 * 38 * @return ecma value 39 */ 40 ecma_value_t ecma_builtin_helper_error_dispatch_call(ecma_standard_error_t error_type,const ecma_value_t * arguments_list_p,ecma_length_t arguments_list_len)41ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**< native error type */ 42 const ecma_value_t *arguments_list_p, /**< arguments list */ 43 ecma_length_t arguments_list_len) /**< number of arguments */ 44 { 45 JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); 46 47 if (arguments_list_len != 0 48 && !ecma_is_value_undefined (arguments_list_p[0])) 49 { 50 ecma_string_t *message_string_p = ecma_op_to_string (arguments_list_p[0]); 51 52 if (JERRY_UNLIKELY (message_string_p == NULL)) 53 { 54 return ECMA_VALUE_ERROR; 55 } 56 57 ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type, 58 message_string_p); 59 60 ecma_deref_ecma_string (message_string_p); 61 return ecma_make_object_value (new_error_object_p); 62 } 63 64 ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type); 65 66 return ecma_make_object_value (new_error_object_p); 67 } /* ecma_builtin_helper_error_dispatch_call */ 68 69 /** 70 * @} 71 * @} 72 */ 73