Implementing dispatcher for calling native handlers associated with external function objects; implementing interface for unified storage of native pointers in ecma objects.

This commit is contained in:
Ruben Ayrapetyan
2015-04-03 23:14:55 +03:00
parent 5611c16117
commit 83730cd6bb
16 changed files with 464 additions and 217 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ extern ecma_external_pointer_t *ecma_alloc_external_pointer (void);
/**
* Dealloc memory from external pointer
*/
extern void ecma_dealloc_external_pointer (ecma_external_pointer_t *ptr_p);
extern void ecma_dealloc_external_pointer (ecma_external_pointer_t *external_pointer_p);
#endif /* JERRY_ECMA_ALLOC_H */
+1
View File
@@ -318,6 +318,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID: /* an integer */
case ECMA_INTERNAL_PROPERTY_EXTENSION_ID: /* an integer */
+7 -6
View File
@@ -204,6 +204,7 @@ typedef enum
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
ECMA_INTERNAL_PROPERTY_CODE, /**< [[Code]] */
ECMA_INTERNAL_PROPERTY_NATIVE_CODE, /**< native handler location descriptor */
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE, /**< [[Primitive value]] for String objects */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE, /**< [[Primitive value]] for Number objects */
@@ -372,8 +373,7 @@ typedef enum
and not host objects */
ECMA_OBJECT_TYPE_STRING, /**< String objects (15.5) */
ECMA_OBJECT_TYPE_FUNCTION, /**< Function objects (15.3), created through 13.2 routine */
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION, /**< Function object (15.3), created through 13.2 routine
but [[Code]] is in external handler. */
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION, /**< External (host) function object */
ECMA_OBJECT_TYPE_BOUND_FUNCTION, /**< Function objects (15.3), created through 15.3.4.5 routine */
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, /** One of built-in functions described in section 15
of ECMA-262 v5 specification */
@@ -381,8 +381,7 @@ typedef enum
ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */
ECMA_OBJECT_TYPE_EXTENSION, /**< Extension (implementation-defined) object
* See also: ecma_extension_instantiate */
// ECMA_OBJECT_TYPE_HOST, /**< Host object */
ECMA_OBJECT_TYPE__COUNT /**< number of object types */
// ECMA_OBJECT_TYPE_HOST /**< Host object */
} ecma_object_type_t;
/**
@@ -444,7 +443,7 @@ typedef struct ecma_object_t
*/
#define ECMA_OBJECT_OBJ_TYPE_POS (ECMA_OBJECT_OBJ_EXTENSIBLE_POS + \
ECMA_OBJECT_OBJ_EXTENSIBLE_WIDTH)
#define ECMA_OBJECT_OBJ_TYPE_WIDTH (3)
#define ECMA_OBJECT_OBJ_TYPE_WIDTH (4)
/**
* Compressed pointer to prototype object (ecma_object_t)
@@ -812,7 +811,9 @@ typedef struct ecma_string_t
} u;
} ecma_string_t;
/**
* Representation for native external pointer
*/
typedef uintptr_t ecma_external_pointer_t;
/**
@@ -0,0 +1,117 @@
/* Copyright 2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
* @{
*/
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
/**
* Create internal property with specified identifier and store external pointer in the property.
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE
*/
void
ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to create property in */
ecma_internal_property_id_t id, /**< identifier of internal
* property to create */
ecma_external_pointer_t ptr_value) /**< value to store in the property */
{
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_CODE);
ecma_property_t *prop_p = ecma_create_internal_property (obj_p, id);
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (prop_p->u.internal_property.value));
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
{
prop_p->u.internal_property.value = (uint32_t) ptr_value;
}
else
{
ecma_external_pointer_t *handler_p = ecma_alloc_external_pointer ();
*handler_p = ptr_value;
ECMA_SET_NON_NULL_POINTER (prop_p->u.internal_property.value, handler_p);
}
} /* ecma_create_external_pointer_property */
/**
* Get value of external pointer stored in the object's property with specified identifier
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE
*
* @return value of the external pointer
*/
ecma_external_pointer_t
ecma_get_external_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
ecma_internal_property_id_t id) /**< identifier of internal property
* to get value from */
{
JERRY_ASSERT (id == ECMA_INTERNAL_PROPERTY_NATIVE_CODE);
ecma_property_t* prop_p = ecma_get_internal_property (obj_p, id);
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (prop_p->u.internal_property.value));
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
{
return (ecma_external_pointer_t) prop_p->u.internal_property.value;
}
else
{
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
prop_p->u.internal_property.value);
return *handler_p;
}
} /* ecma_get_external_pointer_value */
/**
* Free memory associated with external pointer stored in the property
*
* Note:
* property identifier should be one of the following:
* - ECMA_INTERNAL_PROPERTY_NATIVE_CODE
*/
void
ecma_free_external_pointer_in_property (ecma_property_t *prop_p) /**< internal property */
{
JERRY_ASSERT (prop_p->u.internal_property.type == ECMA_INTERNAL_PROPERTY_NATIVE_CODE);
if (sizeof (ecma_external_pointer_t) == sizeof (uint32_t))
{
/* no additional memory was allocated for the pointer storage */
}
else
{
ecma_external_pointer_t *handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
prop_p->u.internal_property.value);
ecma_dealloc_external_pointer (handler_p);
}
} /* ecma_free_external_pointer_in_property */
/**
* @}
* @}
*/
+7
View File
@@ -778,6 +778,13 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
break;
}
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
{
ecma_free_external_pointer_in_property (property_p);
break;
}
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
+11
View File
@@ -308,6 +308,17 @@ extern void ecma_set_property_lcached (ecma_property_t *prop_p,
extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
/* ecma-helpers-external-pointers.c */
extern void
ecma_create_external_pointer_property (ecma_object_t *obj_p,
ecma_internal_property_id_t id,
ecma_external_pointer_t ptr_value);
extern ecma_external_pointer_t
ecma_get_external_pointer_value (ecma_object_t *obj_p,
ecma_internal_property_id_t id);
extern void
ecma_free_external_pointer_in_property (ecma_property_t *prop_p);
/* ecma-helpers-conversion.c */
extern ecma_number_t ecma_zt_string_to_number (const ecma_char_t *str_p);
extern ssize_t ecma_uint32_to_string (uint32_t value, ecma_char_t *out_buffer_p, ssize_t buffer_size);