Skip to content

Introducing internal properties. #2485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions jerry-core/ecma/base/ecma-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
{
case ECMA_PROPERTY_TYPE_NAMEDDATA:
{
if (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
&& property_pair_p->names_cp[index] >= LIT_NEED_MARK_MAGIC_STRING__COUNT)
{
break;
}

ecma_value_t value = property_pair_p->values[index].value;

if (ecma_is_value_object (value))
Expand Down Expand Up @@ -195,6 +189,12 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
}
break;
}
case ECMA_PROPERTY_TYPE_INTERNAL:
{
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
&& property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
break;
}
default:
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_SPECIAL);
Expand Down Expand Up @@ -422,6 +422,8 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p) /**< property */
free_cb (native_pointer_p->data_p);
}
}

jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
} /* ecma_gc_free_native_pointer */

/**
Expand Down Expand Up @@ -468,8 +470,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
{
ecma_gc_free_native_pointer (property_p);
}

if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
else if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
{
ecma_free_property (object_p, name_cp, property_p);
}
Expand Down
25 changes: 11 additions & 14 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ typedef enum
*/
typedef enum
{
ECMA_PROPERTY_TYPE_SPECIAL, /**< internal property */
ECMA_PROPERTY_TYPE_SPECIAL, /**< special purpose property (deleted / hashmap) */
ECMA_PROPERTY_TYPE_NAMEDDATA, /**< property is named data */
ECMA_PROPERTY_TYPE_NAMEDACCESSOR, /**< property is named accessor */
ECMA_PROPERTY_TYPE_VIRTUAL, /**< property is virtual */
ECMA_PROPERTY_TYPE_INTERNAL, /**< internal property with custom data field */
ECMA_PROPERTY_TYPE_VIRTUAL = ECMA_PROPERTY_TYPE_INTERNAL, /**< property is virtual data property */

ECMA_PROPERTY_TYPE__MAX = ECMA_PROPERTY_TYPE_VIRTUAL, /**< highest value for property types. */
} ecma_property_types_t;
Expand Down Expand Up @@ -391,6 +392,12 @@ typedef enum
*/
#define ECMA_PROPERTY_NAME_TYPE_SHIFT (ECMA_PROPERTY_FLAG_SHIFT + 4)

/**
* Convert data property to internal property.
*/
#define ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY(property_p) \
*(property_p) = (uint8_t) (*(property_p) + (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))

/**
* Special property identifiers.
*/
Expand All @@ -402,7 +409,7 @@ typedef enum
ECMA_SPECIAL_PROPERTY_DELETED, /**< deleted property */

ECMA_SPECIAL_PROPERTY__COUNT /**< Number of special property types */
} ecma_internal_property_id_t;
} ecma_special_property_id_t;

/**
* Define special property type.
Expand All @@ -420,15 +427,6 @@ typedef enum
*/
#define ECMA_PROPERTY_TYPE_HASHMAP ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_HASHMAP)

/**
* Name constant of a deleted property.
*/
#ifdef JERRY_CPOINTER_32_BIT
#define ECMA_PROPERTY_DELETED_NAME 0xffffffffu
#else /* !JERRY_CPOINTER_32_BIT */
#define ECMA_PROPERTY_DELETED_NAME 0xffffu
#endif /* JERRY_CPOINTER_32_BIT */

/**
* Type of property not found.
*/
Expand Down Expand Up @@ -531,8 +529,7 @@ typedef struct
* Returns true if the property pointer is a property pair.
*/
#define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) \
(ECMA_PROPERTY_GET_TYPE ((property_header_p)->types[0]) != ECMA_PROPERTY_TYPE_VIRTUAL \
&& (property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
((property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)

/**
* Returns true if the property is named property.
Expand Down
19 changes: 3 additions & 16 deletions jerry-core/ecma/base/ecma-helpers-external-pointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create
if (is_new)
{
ecma_property_value_t *value_p;
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL);
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p);

ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p);

native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));

Expand All @@ -69,7 +71,6 @@ ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create
*
* Note:
* property identifier should be one of the following:
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
* - LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER
*
* @return native pointer data if property exists
Expand All @@ -91,20 +92,6 @@ ecma_get_native_pointer_value (ecma_object_t *obj_p) /**< object to get property
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
} /* ecma_get_native_pointer_value */

/**
* Free the allocated native package struct.
*/
void
ecma_free_native_pointer (ecma_property_t *prop_p) /**< native property */
{
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (prop_p);

ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
value_p->value);

jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
} /* ecma_free_native_pointer */

/**
* @}
* @}
Expand Down
32 changes: 15 additions & 17 deletions jerry-core/ecma/base/ecma-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ JERRY_STATIC_ASSERT ((ECMA_OBJECT_MAX_REF | (ECMA_OBJECT_REF_ONE - 1)) == UINT16
JERRY_STATIC_ASSERT (ECMA_PROPERTY_TYPE_DELETED == (ECMA_DIRECT_STRING_MAGIC << ECMA_PROPERTY_NAME_TYPE_SHIFT),
ecma_property_type_deleted_must_have_magic_string_name_type);

JERRY_STATIC_ASSERT (ECMA_PROPERTY_DELETED_NAME >= LIT_MAGIC_STRING__COUNT,
ecma_property_deleted_name_must_not_be_valid_maigc_string_id);

/**
* Create an object with specified prototype object
* (or NULL prototype if there is not prototype for the object)
Expand Down Expand Up @@ -468,7 +465,7 @@ ecma_create_property (ecma_object_t *object_p, /**< the object */
/* Just copy the previous value (no need to decompress, compress). */
first_property_pair_p->header.next_property_cp = *property_list_head_p;
first_property_pair_p->header.types[0] = ECMA_PROPERTY_TYPE_DELETED;
first_property_pair_p->names_cp[0] = ECMA_PROPERTY_DELETED_NAME;
first_property_pair_p->names_cp[0] = LIT_INTERNAL_MAGIC_STRING_DELETED;

if (name_p == NULL)
{
Expand Down Expand Up @@ -743,19 +740,11 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
{
case ECMA_PROPERTY_TYPE_NAMEDDATA:
{
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
&& (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;
}
default:
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == 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,
Expand All @@ -764,6 +753,13 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
#endif /* JERRY_CPOINTER_32_BIT */
break;
}
default:
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);

/* Currently no internal property can reach this point. */
JERRY_UNREACHABLE ();
}
}

if (ecma_is_property_lcached (property_p))
Expand Down Expand Up @@ -821,7 +817,7 @@ ecma_delete_property (ecma_object_t *object_p, /**< object */

ecma_free_property (object_p, prop_pair_p->names_cp[i], cur_prop_p->types + i);
cur_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED;
prop_pair_p->names_cp[i] = ECMA_PROPERTY_DELETED_NAME;
prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED;

JERRY_ASSERT (ECMA_PROPERTY_PAIR_ITEM_COUNT == 2);

Expand Down Expand Up @@ -963,7 +959,7 @@ ecma_delete_array_properties (ecma_object_t *object_p, /**< object */

ecma_free_property (object_p, prop_pair_p->names_cp[i], current_prop_p->types + i);
current_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED;
prop_pair_p->names_cp[i] = ECMA_PROPERTY_DELETED_NAME;
prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED;
}
}
}
Expand Down Expand Up @@ -1254,7 +1250,8 @@ inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_is_property_lcached (ecma_property_t *property_p) /**< property */
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);

return (*property_p & ECMA_PROPERTY_FLAG_LCACHED) != 0;
} /* ecma_is_property_lcached */
Expand All @@ -1267,7 +1264,8 @@ ecma_set_property_lcached (ecma_property_t *property_p, /**< property */
bool is_lcached) /**< new value for lcached flag */
{
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);

if (is_lcached)
{
Expand Down
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
/* ecma-helpers-external-pointers.c */
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);
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);
Expand Down
3 changes: 2 additions & 1 deletion jerry-core/ecma/base/ecma-lcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p));
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_INTERNAL);

#ifndef CONFIG_ECMA_LCACHE_DISABLE
jmem_cpointer_t object_cp;
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/base/ecma-property-hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
{
ecma_property_types_t type = ECMA_PROPERTY_GET_TYPE (prop_iter_p->types[i]);

if (type == ECMA_PROPERTY_TYPE_NAMEDDATA || type == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
if (type != ECMA_PROPERTY_TYPE_SPECIAL)
{
named_property_count++;
}
Expand Down
9 changes: 5 additions & 4 deletions jerry-core/lit/lit-magic-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ typedef enum
LIT_INTERNAL_MAGIC_STRING_ALREADY_RESOLVED, /**< [[AlreadyResolved]] of promise reject or resolve functions */
LIT_INTERNAL_MAGIC_STRING_RESOLVE_FUNCTION, /**< the resolve funtion of the promise object */
LIT_INTERNAL_MAGIC_STRING_REJECT_FUNCTION, /**< the reject function of the promise object */
LIT_NEED_MARK_MAGIC_STRING__COUNT, /**< number of internal magic strings which will be used as properties' names,
* and the properties need to be marked during gc. */
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER = LIT_NEED_MARK_MAGIC_STRING__COUNT, /**< native pointer info associated
* with an object */
LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< number of internal magic strings which will be used as
* property names, and their values need to be marked during gc. */
LIT_INTERNAL_MAGIC_STRING_DELETED = LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< special value for
* deleted properties */
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< native pointer info associated with an object */
LIT_MAGIC_STRING__COUNT /**< number of magic strings */
} lit_magic_string_id_t;

Expand Down