/** * Create named accessor property with given name, attributes, getter and setter. * * @return pointer to the newly created property value */ ecma_property_value_t * ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */ ecma_string_t *name_p, /**< property name */ ecma_object_t *get_p, /**< getter */ ecma_object_t *set_p, /**< setter */ uint8_t prop_attributes, /**< property attributes */ ecma_property_t **out_prop_p) /**< [out] the property is also returned * if this field is non-NULL */ { JERRY_ASSERT (object_p != NULL && name_p != NULL); JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); JERRY_ASSERT ((prop_attributes & ~ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE) == 0); uint8_t type_and_flags = ECMA_PROPERTY_TYPE_NAMEDACCESSOR | prop_attributes; ecma_property_value_t value; #ifdef JERRY_CPOINTER_32_BIT ecma_getter_setter_pointers_t *getter_setter_pair_p; getter_setter_pair_p = jmem_pools_alloc (sizeof (ecma_getter_setter_pointers_t)); ECMA_SET_POINTER (getter_setter_pair_p->getter_p, get_p); ECMA_SET_POINTER (getter_setter_pair_p->setter_p, set_p); ECMA_SET_POINTER (value.getter_setter_pair_cp, getter_setter_pair_p); #else /* !JERRY_CPOINTER_32_BIT */ ECMA_SET_POINTER (value.getter_setter_pair.getter_p, get_p); ECMA_SET_POINTER (value.getter_setter_pair.setter_p, set_p); #endif /* JERRY_CPOINTER_32_BIT */ return ecma_create_property (object_p, name_p, type_and_flags, value, out_prop_p); } /* ecma_create_named_accessor_property */
/** * Allocate memory for ecma-object * * @return pointer to allocated memory */ inline ecma_object_t * JERRY_ATTR_ALWAYS_INLINE ecma_alloc_object (void) { #ifdef JMEM_STATS jmem_stats_allocate_object_bytes (sizeof (ecma_object_t)); #endif /* JMEM_STATS */ return (ecma_object_t *) jmem_pools_alloc (sizeof (ecma_object_t)); } /* ecma_alloc_object */
int main () { TEST_INIT (); jmem_init (); for (uint32_t i = 0; i < test_iters; i++) { const size_t subiters = ((size_t) rand () % TEST_MAX_SUB_ITERS) + 1; for (size_t j = 0; j < subiters; j++) { ptrs[j] = (uint8_t *) jmem_pools_alloc (); if (ptrs[j] != NULL) { for (size_t k = 0; k < JMEM_POOL_CHUNK_SIZE; k++) { ptrs[j][k] = (uint8_t) (rand () % 256); } memcpy (data[j], ptrs[j], JMEM_POOL_CHUNK_SIZE); } } /* jmem_heap_print (false); */ for (size_t j = 0; j < subiters; j++) { if (rand () % 256 == 0) { jmem_pools_collect_empty (); } if (ptrs[j] != NULL) { JERRY_ASSERT (!memcmp (data[j], ptrs[j], JMEM_POOL_CHUNK_SIZE)); jmem_pools_free (ptrs[j]); } } } #ifdef JMEM_STATS jmem_pools_stats_print (); #endif /* JMEM_STATS */ jmem_finalize (false); return 0; } /* main */
/** * Allocate memory for ecma-number * * @return pointer to allocated memory */ ecma_number_t * ecma_alloc_number (void) { return (ecma_number_t *) jmem_pools_alloc (sizeof (ecma_number_t)); } /* ecma_alloc_number */