Implementing [[Get]] routine for function objects.

This commit is contained in:
Ruben Ayrapetyan
2014-09-02 22:34:38 +04:00
parent 57058c30ef
commit d45748a001
3 changed files with 74 additions and 8 deletions
@@ -23,6 +23,7 @@
#include "ecma-lex-env.h"
#include "ecma-magic-strings.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-try-catch-macro.h"
#include "globals.h"
@@ -287,6 +288,61 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f
return f;
} /* ecma_op_create_function_object */
/**
* [[Get]] function object's operation
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
* ECMA-262 v5, 15.3.5.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_function_object_get (ecma_object_t *obj_p, /**< the function object */
ecma_string_t *property_name_p) /**< property name */
{
JERRY_ASSERT(obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
JERRY_ASSERT(property_name_p != NULL);
ecma_completion_value_t ret_value;
ecma_property_t *code_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CODE);
uint32_t code_prop_value = code_prop_p->u.internal_property.value;
bool is_strict;
ecma_unpack_code_internal_property_value (code_prop_value, &is_strict);
if (!is_strict)
{
ret_value = ecma_op_general_object_get (obj_p, property_name_p);
}
else
{
ECMA_TRY_CATCH (general_get_completion,
ecma_op_general_object_get (obj_p,
property_name_p),
ret_value);
ecma_string_t *caller_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER);
if (ecma_compare_ecma_strings (property_name_p, caller_magic_string_p))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ret_value = ecma_copy_completion_value (general_get_completion);
}
ecma_deref_ecma_string (caller_magic_string_p);
ECMA_FINALIZE (general_get_completion);
}
return ret_value;
} /* ecma_op_function_object_get */
/**
* Setup variables for arguments listed in formal parameter list.
*
+12 -7
View File
@@ -36,14 +36,19 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[],
bool is_strict,
opcode_counter_t first_opcode_idx);
extern ecma_completion_value_t ecma_op_function_call (ecma_object_t *func_obj_p,
ecma_value_t this_arg_value,
ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_object_get (ecma_object_t *obj_p, ecma_string_t *property_name_p);
extern ecma_completion_value_t ecma_op_function_construct (ecma_object_t *func_obj_p,
ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_call (ecma_object_t *func_obj_p,
ecma_value_t this_arg_value,
ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_construct (ecma_object_t *func_obj_p,
ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p,
+6 -1
View File
@@ -15,6 +15,7 @@
#include "ecma-exceptions.h"
#include "ecma-globals.h"
#include "ecma-function-object.h"
#include "ecma-objects-arguments.h"
#include "ecma-objects-general.h"
#include "ecma-objects.h"
@@ -49,7 +50,6 @@ ecma_op_object_get (ecma_object_t *obj_p, /**< the object */
{
case ECMA_OBJECT_TYPE_GENERAL:
case ECMA_OBJECT_TYPE_ARRAY:
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
case ECMA_OBJECT_TYPE_STRING:
{
return ecma_op_general_object_get (obj_p, property_name_p);
@@ -60,7 +60,12 @@ ecma_op_object_get (ecma_object_t *obj_p, /**< the object */
return ecma_op_arguments_object_get (obj_p, property_name_p);
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
case ECMA_OBJECT_TYPE_FUNCTION:
{
return ecma_op_function_object_get (obj_p, property_name_p);
}
case ECMA_OBJECT_TYPE_HOST:
{
JERRY_UNIMPLEMENTED();