Implementing [[ThrowTypeError]] built-in Function object.

This commit is contained in:
Ruben Ayrapetyan
2014-10-30 17:14:06 +03:00
parent 4625d5b90a
commit ac710dd0b5
7 changed files with 141 additions and 18 deletions
@@ -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 */
/**
* @}
* @}
* @}
*/
@@ -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
@@ -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, \
+1
View File
@@ -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 */
+2 -15
View File
@@ -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 */
/**
* @}
* @}
@@ -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);
/**
* @}
* @}
@@ -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 ();