/** * Free the named data property and values it references. */ static void ecma_free_named_data_property (ecma_object_t *object_p, /**< object the property belongs to */ ecma_property_t *property_p) /**< the property */ { JERRY_ASSERT (object_p != NULL); JERRY_ASSERT (property_p != NULL && ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA); ecma_value_t v = ecma_get_named_data_property_value (property_p); ecma_free_value_if_not_object (v); } /* ecma_free_named_data_property */
/** * Free property values and change their type to deleted. */ void ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to */ jmem_cpointer_t name_cp, /**< name of the property or ECMA_NULL_POINTER */ ecma_property_t *property_p) /**< property */ { JERRY_ASSERT (object_p != NULL && property_p != NULL); switch (ECMA_PROPERTY_GET_TYPE (*property_p)) { case ECMA_PROPERTY_TYPE_NAMEDDATA: { if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_STRING_CONTAINER_MAGIC_STRING) { if (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE || name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER) { ecma_free_native_pointer (property_p); break; } } ecma_free_value_if_not_object (ECMA_PROPERTY_VALUE_PTR (property_p)->value); break; } case ECMA_PROPERTY_TYPE_NAMEDACCESSOR: { #ifdef JERRY_CPOINTER_32_BIT ecma_getter_setter_pointers_t *getter_setter_pair_p; getter_setter_pair_p = ECMA_GET_POINTER (ecma_getter_setter_pointers_t, ECMA_PROPERTY_VALUE_PTR (property_p)->getter_setter_pair_cp); jmem_pools_free (getter_setter_pair_p, sizeof (ecma_getter_setter_pointers_t)); #endif /* JERRY_CPOINTER_32_BIT */ break; } default: { JERRY_UNREACHABLE (); return; } } if (ecma_is_property_lcached (property_p)) { ecma_lcache_invalidate (object_p, name_cp, property_p); } if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_PROPERTY_NAME_TYPE_STRING) { ecma_string_t *prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t, name_cp); ecma_deref_ecma_string (prop_name_p); } *property_p = ECMA_PROPERTY_TYPE_DELETED; } /* ecma_free_property */
/** * Free the collection of ecma values. */ void ecma_free_values_collection (ecma_collection_header_t *header_p, /**< collection's header */ bool do_deref_if_object) /**< if the value is object value, decrement reference counter of the object */ { JERRY_ASSERT (header_p != NULL); const size_t values_in_chunk = JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) / sizeof (ecma_value_t); ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t, header_p->first_chunk_cp); ecma_length_t value_index = 0; while (chunk_p != NULL) { JERRY_ASSERT (value_index < header_p->unit_number); ecma_value_t *cur_value_buf_iter_p = (ecma_value_t *) chunk_p->data; ecma_value_t *cur_value_buf_end_p = cur_value_buf_iter_p + values_in_chunk; while (cur_value_buf_iter_p != cur_value_buf_end_p && value_index < header_p->unit_number) { JERRY_ASSERT (cur_value_buf_iter_p < cur_value_buf_end_p); if (do_deref_if_object) { ecma_free_value (*cur_value_buf_iter_p); } else { ecma_free_value_if_not_object (*cur_value_buf_iter_p); } cur_value_buf_iter_p++; value_index++; } ecma_collection_chunk_t *next_chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t, chunk_p->next_chunk_cp); ecma_dealloc_collection_chunk (chunk_p); chunk_p = next_chunk_p; } ecma_dealloc_collection_header (header_p); } /* ecma_free_values_collection */
/** * Assign value to named data property * * Note: * value previously stored in the property is freed */ void ecma_named_data_property_assign_value (ecma_object_t *obj_p, /**< object */ ecma_property_t *prop_p, /**< property */ ecma_value_t value) /**< value to assign */ { JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA); ecma_assert_object_contains_the_property (obj_p, prop_p); if (ecma_is_value_number (value) && ecma_is_value_number (ecma_get_named_data_property_value (prop_p))) { const ecma_number_t *num_src_p = ecma_get_number_from_value (value); ecma_number_t *num_dst_p = ecma_get_number_from_value (ecma_get_named_data_property_value (prop_p)); *num_dst_p = *num_src_p; } else { ecma_value_t v = ecma_get_named_data_property_value (prop_p); ecma_free_value_if_not_object (v); ecma_set_named_data_property_value (prop_p, ecma_copy_value_if_not_object (value)); } } /* ecma_named_data_property_assign_value */
/** * Free the internal property and values it references. */ static void ecma_free_internal_property (ecma_property_t *property_p) /**< the property */ { JERRY_ASSERT (property_p != NULL && ECMA_PROPERTY_GET_TYPE (property_p) == ECMA_PROPERTY_TYPE_INTERNAL); uint32_t property_value = ECMA_PROPERTY_VALUE_PTR (property_p)->value; switch (ECMA_PROPERTY_GET_INTERNAL_PROPERTY_TYPE (property_p)) { case ECMA_INTERNAL_PROPERTY_ECMA_VALUE: /* ecma-value property except object */ { JERRY_ASSERT (!ecma_is_value_object (property_value)); ecma_free_value (property_value); break; } case ECMA_INTERNAL_PROPERTY_DATE_FLOAT: /* pointer to a ecma_number_t */ { ecma_number_t *num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, property_value); ecma_dealloc_number (num_p); break; } case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */ case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */ case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an external pointer */ { ecma_free_external_pointer_in_property (property_p); break; } case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */ case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */ case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */ case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */ case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */ case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */ case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */ case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION: { break; } case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS: { ecma_free_value_if_not_object (property_value); break; } case ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_ARGS: { if (property_value != ECMA_NULL_POINTER) { ecma_free_values_collection (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_header_t, property_value), false); } break; } case ECMA_INTERNAL_PROPERTY__COUNT: /* not a real internal property type, * but number of the real internal property types */ { JERRY_UNREACHABLE (); break; } case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */ { ecma_bytecode_deref (ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, property_value)); break; } case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE: /* compressed pointer to a regexp bytecode array */ { ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, property_value); if (bytecode_p != NULL) { ecma_bytecode_deref (bytecode_p); } break; } } } /* ecma_free_internal_property */