Small improvements for type property support. (#1724)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -354,7 +354,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
} /* ecma_gc_mark */
|
||||
|
||||
/**
|
||||
* Free the native handle/pointer by calling its free callback
|
||||
* Free the native handle/pointer by calling its free callback.
|
||||
*/
|
||||
static void
|
||||
ecma_gc_free_native_pointer (ecma_property_t *property_p, /**< property */
|
||||
@@ -366,36 +366,32 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p, /**< property */
|
||||
|| id == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
ecma_external_pointer_t native_p;
|
||||
ecma_external_pointer_t free_cb;
|
||||
void *package_p;
|
||||
ecma_native_pointer_t *native_pointer_p;
|
||||
|
||||
package_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, value_p->value);
|
||||
native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
|
||||
value_p->value);
|
||||
|
||||
if (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE)
|
||||
{
|
||||
native_p = ((ecma_native_handle_package_t *) package_p)->handle_p;
|
||||
free_cb = ((ecma_native_handle_package_t *) package_p)->free_cb;
|
||||
|
||||
if ((jerry_object_free_callback_t) free_cb != NULL)
|
||||
if (native_pointer_p->info_p != NULL)
|
||||
{
|
||||
((jerry_object_free_callback_t) free_cb) ((uintptr_t) native_p);
|
||||
ecma_external_pointer_t freecb_p = (ecma_external_pointer_t) native_pointer_p->info_p;
|
||||
((jerry_object_free_callback_t) freecb_p) ((uintptr_t) native_pointer_p->data_p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
native_p = ((ecma_native_pointer_package_t *) package_p)->native_p;
|
||||
free_cb = *(ecma_external_pointer_t *) (((ecma_native_pointer_package_t *) package_p)->info_p);
|
||||
|
||||
if ((jerry_object_native_free_callback_t) free_cb != NULL)
|
||||
if (native_pointer_p->info_p != NULL)
|
||||
{
|
||||
((jerry_object_native_free_callback_t) free_cb) ((void *) native_p);
|
||||
const jerry_object_native_info_t *native_info_p = (const jerry_object_native_info_t *) native_pointer_p->info_p;
|
||||
|
||||
native_info_p->free_cb (native_pointer_p->data_p);
|
||||
}
|
||||
}
|
||||
} /* ecma_gc_free_native_pointer */
|
||||
|
||||
/**
|
||||
* Free specified object
|
||||
* Free specified object.
|
||||
*/
|
||||
void
|
||||
ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
|
||||
|
||||
@@ -196,26 +196,13 @@ typedef int32_t ecma_integer_value_t;
|
||||
typedef uintptr_t ecma_external_pointer_t;
|
||||
|
||||
/**
|
||||
* Representation for native handle package.
|
||||
*
|
||||
* Note: It is for the deprecated api:
|
||||
* jerry_get_object_native_handle and jerry_set_object_native_handle
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ecma_external_pointer_t handle_p; /**< points to the external native object */
|
||||
ecma_external_pointer_t free_cb; /**< free callback of the native handle */
|
||||
} ecma_native_handle_package_t;
|
||||
|
||||
/**
|
||||
* Representation of the native pointer package.
|
||||
* Representation for native pointer data.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_external_pointer_t native_p; /**< points to the external native object */
|
||||
ecma_external_pointer_t info_p; /**< type info of the native pointer */
|
||||
} ecma_native_pointer_package_t;
|
||||
void *data_p; /**< points to the data of the object */
|
||||
void *info_p; /**< free info or callback */
|
||||
} ecma_native_pointer_t;
|
||||
|
||||
/**
|
||||
* Special property identifiers.
|
||||
|
||||
@@ -39,7 +39,8 @@ static bool
|
||||
ecma_create_native_property (ecma_object_t *obj_p, /**< object to create property in */
|
||||
lit_magic_string_id_t id, /**< identifier of internal
|
||||
* property to create */
|
||||
void *package_p) /**< value to store in the property */
|
||||
void *data_p, /**< native pointer data */
|
||||
void *info_p) /**< native pointer's info */
|
||||
{
|
||||
JERRY_ASSERT (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
|| id == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
@@ -49,24 +50,29 @@ ecma_create_native_property (ecma_object_t *obj_p, /**< object to create propert
|
||||
|
||||
ecma_property_t *property_p = ecma_find_named_property (obj_p, &name);
|
||||
bool is_new = (property_p == NULL);
|
||||
ecma_property_value_t *value_p;
|
||||
|
||||
ecma_native_pointer_t *native_pointer_p;
|
||||
|
||||
if (is_new)
|
||||
{
|
||||
ecma_property_value_t *value_p;
|
||||
value_p = ecma_create_named_data_property (obj_p, &name, ECMA_PROPERTY_FLAG_WRITABLE, NULL);
|
||||
|
||||
native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, native_pointer_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
ecma_free_native_package_property (property_p, id);
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (&name));
|
||||
|
||||
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (value_p->value),
|
||||
size_of_internal_property_value_must_be_greater_than_or_equal_to_4_bytes);
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (value_p->value, package_p);
|
||||
native_pointer_p->data_p = data_p;
|
||||
native_pointer_p->info_p = info_p;
|
||||
|
||||
return is_new;
|
||||
} /* ecma_create_native_property */
|
||||
@@ -79,17 +85,13 @@ ecma_create_native_property (ecma_object_t *obj_p, /**< object to create propert
|
||||
*/
|
||||
bool
|
||||
ecma_create_native_handle_property (ecma_object_t *obj_p, /**< object to create property in */
|
||||
ecma_external_pointer_t handle_p, /**< native handle */
|
||||
ecma_external_pointer_t free_cb) /**< native handle's free callback*/
|
||||
void *handle_p, /**< native handle */
|
||||
void *free_cb) /**< native handle's free callback*/
|
||||
{
|
||||
ecma_native_handle_package_t *package_p;
|
||||
package_p = jmem_heap_alloc_block (sizeof (ecma_native_handle_package_t));
|
||||
package_p->handle_p = handle_p;
|
||||
package_p->free_cb = free_cb;
|
||||
|
||||
return ecma_create_native_property (obj_p,
|
||||
LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE,
|
||||
package_p);
|
||||
handle_p,
|
||||
free_cb);
|
||||
} /* ecma_create_native_handle_property */
|
||||
|
||||
/**
|
||||
@@ -100,17 +102,13 @@ ecma_create_native_handle_property (ecma_object_t *obj_p, /**< object to create
|
||||
*/
|
||||
bool
|
||||
ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create property in */
|
||||
ecma_external_pointer_t native_p, /**< native pointer */
|
||||
ecma_external_pointer_t info_p) /**< native pointer's type info */
|
||||
void *native_p, /**< native pointer */
|
||||
void *info_p) /**< native pointer's type info */
|
||||
{
|
||||
ecma_native_pointer_package_t *package_p;
|
||||
package_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_package_t));
|
||||
package_p->native_p = native_p;
|
||||
package_p->info_p = info_p;
|
||||
|
||||
return ecma_create_native_property (obj_p,
|
||||
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER,
|
||||
package_p);
|
||||
native_p,
|
||||
info_p);
|
||||
} /* ecma_create_native_pointer_property */
|
||||
|
||||
/**
|
||||
@@ -121,14 +119,13 @@ ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create
|
||||
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER
|
||||
*
|
||||
* @return true - if property exists and it's value is returned through out_pointer_p,
|
||||
* false - otherwise (value returned through out_pointer_p is NULL)
|
||||
* @return native pointer data if property exists
|
||||
* NULL otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_get_native_package_value (ecma_object_t *obj_p, /**< object to get property value from */
|
||||
lit_magic_string_id_t id, /**< identifier of internal property
|
||||
ecma_native_pointer_t *
|
||||
ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property value from */
|
||||
lit_magic_string_id_t id) /**< identifier of internal property
|
||||
* to get value from */
|
||||
void **out_pointer_p) /**< [out] value of the native package */
|
||||
{
|
||||
JERRY_ASSERT (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
|| id == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
@@ -142,46 +139,27 @@ ecma_get_native_package_value (ecma_object_t *obj_p, /**< object to get property
|
||||
|
||||
if (property_p == NULL)
|
||||
{
|
||||
*out_pointer_p = NULL;
|
||||
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
|
||||
|
||||
*out_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, value_p->value);
|
||||
|
||||
return true;
|
||||
} /* ecma_get_native_package_value */
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
|
||||
} /* ecma_get_native_pointer_value */
|
||||
|
||||
/**
|
||||
* Free the allocated native package struct.
|
||||
*
|
||||
* Note:
|
||||
* property identifier should be one of the following:
|
||||
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER
|
||||
*/
|
||||
void
|
||||
ecma_free_native_package_property (ecma_property_t *prop_p, /**< native property */
|
||||
lit_magic_string_id_t id) /**< identifier of internal */
|
||||
ecma_free_native_pointer (ecma_property_t *prop_p) /**< native property */
|
||||
{
|
||||
JERRY_ASSERT (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
|| id == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
|
||||
|
||||
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (prop_p);
|
||||
void *package_p;
|
||||
|
||||
package_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, value_p->value);
|
||||
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
|
||||
value_p->value);
|
||||
|
||||
if (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE)
|
||||
{
|
||||
jmem_heap_free_block (package_p, sizeof (ecma_native_handle_package_t));
|
||||
return;
|
||||
}
|
||||
|
||||
jmem_heap_free_block (package_p, sizeof (ecma_native_pointer_package_t));
|
||||
} /* ecma_free_native_package_property */
|
||||
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
|
||||
} /* ecma_free_native_pointer */
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -733,7 +733,7 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
|
||||
if (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
|
||||
|| name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER)
|
||||
{
|
||||
ecma_free_native_package_property (property_p, (lit_magic_string_id_t) name_cp);
|
||||
ecma_free_native_pointer (property_p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,17 +341,10 @@ void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
|
||||
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
|
||||
|
||||
/* ecma-helpers-external-pointers.c */
|
||||
bool ecma_create_native_handle_property (ecma_object_t *obj_p,
|
||||
ecma_external_pointer_t handle_p,
|
||||
ecma_external_pointer_t free_cb);
|
||||
bool ecma_create_native_pointer_property (ecma_object_t *obj_p,
|
||||
ecma_external_pointer_t native_p,
|
||||
ecma_external_pointer_t info_p);
|
||||
bool ecma_get_native_package_value (ecma_object_t *obj_p,
|
||||
lit_magic_string_id_t id,
|
||||
void **out_pointer_p);
|
||||
void ecma_free_native_package_property (ecma_property_t *prop_p,
|
||||
lit_magic_string_id_t id);
|
||||
bool ecma_create_native_handle_property (ecma_object_t *obj_p, void *handle_p, void *free_cb);
|
||||
bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p);
|
||||
ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p, lit_magic_string_id_t id);
|
||||
void ecma_free_native_pointer (ecma_property_t *prop_p);
|
||||
|
||||
/* ecma-helpers-conversion.c */
|
||||
ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size);
|
||||
|
||||
Reference in New Issue
Block a user