diff --git a/src/libecmabuiltins/ecma-builtin-type-error-thrower.c b/src/libecmabuiltins/ecma-builtin-type-error-thrower.c new file mode 100644 index 000000000..cbbc571d2 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-type-error-thrower.c @@ -0,0 +1,84 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * 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-objects.h" +#include "ecma-try-catch-macro.h" +#include "globals.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-type-error-thrower.inc.h" +#define BUILTIN_UNDERSCORED_ID type_error_thrower +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup type_error_thrower ECMA [[ThrowTypeError]] object built-in + * @{ + */ + +/** + * Handle calling [[Call]] of built-in [[ThrowTypeError]] object + * + * See also: + * ECMA-262 v5, 13.2.3 + * + * @return completion-value + */ +ecma_completion_value_t +ecma_builtin_type_error_thrower_dispatch_call (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); + + /* The object should throw TypeError */ + return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); +} /* ecma_builtin_type_error_thrower_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in [[ThrowTypeError]] object + * + * See also: + * ECMA-262 v5, 13.2.3 + * + * @return completion-value + */ +ecma_completion_value_t +ecma_builtin_type_error_thrower_dispatch_construct (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); + + /* The object is not a constructor */ + return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); +} /* ecma_builtin_type_error_thrower_dispatch_construct */ + +/** + * @} + * @} + * @} + */ diff --git a/src/libecmabuiltins/ecma-builtin-type-error-thrower.inc.h b/src/libecmabuiltins/ecma-builtin-type-error-thrower.inc.h new file mode 100644 index 000000000..7fde56465 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-type-error-thrower.inc.h @@ -0,0 +1,48 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/* + * [[ThrowTypeError]] description + * + * See also: ECMA-262 v5, 13.2.3 + */ + +#ifndef OBJECT_ID +# define OBJECT_ID(builtin_object_id) +#endif /* !OBJECT_ID */ + +#ifndef NUMBER_VALUE +# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable) +#endif /* !NUMBER_VALUE */ + +/* Object identifier */ +OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER) + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH, + 0, + ECMA_PROPERTY_NOT_WRITABLE, + ECMA_PROPERTY_NOT_ENUMERABLE, + ECMA_PROPERTY_NOT_CONFIGURABLE) + +#undef OBJECT_ID +#undef SIMPLE_VALUE +#undef NUMBER_VALUE +#undef STRING_VALUE +#undef OBJECT_VALUE +#undef CP_UNIMPLEMENTED_VALUE +#undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtins-internal.h b/src/libecmabuiltins/ecma-builtins-internal.h index fe17d5ea2..9e9e05048 100644 --- a/src/libecmabuiltins/ecma-builtins-internal.h +++ b/src/libecmabuiltins/ecma-builtins-internal.h @@ -195,6 +195,11 @@ ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id ERROR_UL, \ ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE, \ uri_error) \ + macro (TYPE_ERROR_THROWER, \ + TYPE_FUNCTION, \ + FUNCTION_UL, \ + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ + type_error_thrower) \ macro (COMPACT_PROFILE_ERROR, \ TYPE_FUNCTION, \ COMPACT_PROFILE_ERROR_UL, \ diff --git a/src/libecmabuiltins/ecma-builtins.h b/src/libecmabuiltins/ecma-builtins.h index 47e65afc2..0cd525e32 100644 --- a/src/libecmabuiltins/ecma-builtins.h +++ b/src/libecmabuiltins/ecma-builtins.h @@ -55,6 +55,7 @@ typedef enum ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE, /**< the URIError.prototype object (15.11.6.6) */ ECMA_BUILTIN_ID_MATH, /**< the Math object (15.8) */ ECMA_BUILTIN_ID_JSON, /**< the JSON object (15.12) */ + ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, /**< the [[ThrowTypeError]] object (13.2.3) */ #ifdef CONFIG_ECMA_COMPACT_PROFILE ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR, /**< CompactProfileError object defined in the Compact Profile */ #endif /* CONFIG_ECMA_COMPACT_PROFILE */ diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 26c43560e..e557bacc8 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -252,7 +252,7 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f // 19. if (is_strict) { - ecma_object_t *thrower_p = ecma_op_get_throw_type_error (); + ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER); prop_desc = ecma_make_empty_property_descriptor (); { @@ -269,7 +269,7 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f prop_desc.set_p = thrower_p; } - ecma_string_t *magic_string_caller_p =ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER) ; + ecma_string_t *magic_string_caller_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER); ecma_op_object_define_own_property (f, magic_string_caller_p, prop_desc, @@ -769,19 +769,6 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment return ret_value; } /* ecma_op_function_declaration */ -/** - * Get [[ThrowTypeError]] Function Object - * - * @return pointer to unique [[ThrowTypeError]] Function Object - */ -ecma_object_t* -ecma_op_get_throw_type_error (void) -{ - TODO(Create [[ThrowTypeError]] during engine initialization and return it from here); - - JERRY_UNIMPLEMENTED("Type error thrower is not implemented."); -} /* ecma_op_get_throw_type_error */ - /** * @} * @} diff --git a/src/libecmaoperations/ecma-function-object.h b/src/libecmaoperations/ecma-function-object.h index ef59962e1..81aa510ec 100644 --- a/src/libecmaoperations/ecma-function-object.h +++ b/src/libecmaoperations/ecma-function-object.h @@ -60,8 +60,6 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, bool is_strict, bool is_configurable_bindings); -extern ecma_object_t* ecma_op_get_throw_type_error (void); - /** * @} * @} diff --git a/src/libecmaoperations/ecma-objects-arguments.c b/src/libecmaoperations/ecma-objects-arguments.c index 6f9616ad8..1841e8fd7 100644 --- a/src/libecmaoperations/ecma-objects-arguments.c +++ b/src/libecmaoperations/ecma-objects-arguments.c @@ -229,7 +229,7 @@ ecma_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function */ } else { - ecma_object_t *thrower_p = ecma_op_get_throw_type_error (); + ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER); // 14. prop_desc = ecma_make_empty_property_descriptor ();