From b059212e326ebc11ee3cbf83e64994aea6eeb326 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 30 Jul 2014 17:48:28 +0400 Subject: [PATCH] Implementing IsCallable operation. --- src/libecmaoperations/ecma-function-object.c | 31 ++++++++++++++++---- src/libecmaoperations/ecma-function-object.h | 2 ++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 6e703a558..b48e43867 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -25,6 +25,30 @@ * @{ */ +/** + * IsCallable operation. + * + * See also: ECMA-262 v5, 9.11 + * + * @return true, if value is callable object; + * false - otherwise. + */ +bool +ecma_op_is_callable( ecma_value_t value) /**< ecma-value */ +{ + if ( value.value_type != ECMA_TYPE_OBJECT ) + { + return false; + } + + ecma_object_t *obj_p = ecma_get_pointer( value.value); + + JERRY_ASSERT( obj_p != NULL ); + JERRY_ASSERT( !obj_p->is_lexical_environment ); + + return true; +} /* ecma_op_is_callable */ + /** * Function object creation operation. * @@ -44,9 +68,9 @@ ecma_op_create_function_object( const ecma_char_t* formal_parameter_list_p[], /* ecma_object_t *f = ecma_create_object( NULL, true, ECMA_OBJECT_TYPE_FUNCTION); - // 2., 8 + // 2., 6., 7., 8. /* - * We don't setup [[Get]], [[HasInstance]] for each function object. + * We don't setup [[Get]], [[Call]], [[Construct]], [[HasInstance]] for each function object. * Instead we set the object's type to ECMA_OBJECT_TYPE_FUNCTION * that defines which version of [[Get]] routine should be used on demand. */ @@ -55,9 +79,6 @@ ecma_op_create_function_object( const ecma_char_t* formal_parameter_list_p[], /* ecma_property_t *class_prop_p = ecma_create_internal_property( f, ECMA_INTERNAL_PROPERTY_CLASS); class_prop_p->u.internal_property.value = ECMA_OBJECT_CLASS_FUNCTION; - // 6., 7. - TODO( Decide how to setup [[Call]] and [[Construct]] ); - // 9. ecma_ref_object( scope_p); diff --git a/src/libecmaoperations/ecma-function-object.h b/src/libecmaoperations/ecma-function-object.h index a57019a22..76b492b8c 100644 --- a/src/libecmaoperations/ecma-function-object.h +++ b/src/libecmaoperations/ecma-function-object.h @@ -26,6 +26,8 @@ * @{ */ +extern bool ecma_op_is_callable( ecma_value_t value); + extern ecma_object_t* ecma_op_create_function_object( const ecma_char_t* formal_parameter_list_p[], size_t formal_parameters_number,