Skip to content

Commit 49a5a6f

Browse files
committed
Introducing internal properties.
Native handle and pointer are moved to internal properties. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent b934dd8 commit 49a5a6f

File tree

8 files changed

+46
-62
lines changed

8 files changed

+46
-62
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
162162
{
163163
case ECMA_PROPERTY_TYPE_NAMEDDATA:
164164
{
165-
if (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
166-
&& property_pair_p->names_cp[index] >= LIT_NEED_MARK_MAGIC_STRING__COUNT)
167-
{
168-
break;
169-
}
170-
171165
ecma_value_t value = property_pair_p->values[index].value;
172166

173167
if (ecma_is_value_object (value))
@@ -195,6 +189,12 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
195189
}
196190
break;
197191
}
192+
case ECMA_PROPERTY_TYPE_INTERNAL:
193+
{
194+
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
195+
&& property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
196+
break;
197+
}
198198
default:
199199
{
200200
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_SPECIAL);
@@ -422,6 +422,8 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p) /**< property */
422422
free_cb (native_pointer_p->data_p);
423423
}
424424
}
425+
426+
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
425427
} /* ecma_gc_free_native_pointer */
426428

427429
/**
@@ -468,8 +470,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
468470
{
469471
ecma_gc_free_native_pointer (property_p);
470472
}
471-
472-
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
473+
else if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
473474
{
474475
ecma_free_property (object_p, name_cp, property_p);
475476
}

jerry-core/ecma/base/ecma-globals.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ typedef enum
327327
*/
328328
typedef enum
329329
{
330-
ECMA_PROPERTY_TYPE_SPECIAL, /**< internal property */
330+
ECMA_PROPERTY_TYPE_SPECIAL, /**< special purpose property (deleted / hashmap) */
331331
ECMA_PROPERTY_TYPE_NAMEDDATA, /**< property is named data */
332332
ECMA_PROPERTY_TYPE_NAMEDACCESSOR, /**< property is named accessor */
333-
ECMA_PROPERTY_TYPE_VIRTUAL, /**< property is virtual */
333+
ECMA_PROPERTY_TYPE_INTERNAL, /**< internal property with custom data field */
334+
ECMA_PROPERTY_TYPE_VIRTUAL = ECMA_PROPERTY_TYPE_INTERNAL, /**< property is virtual data property */
334335

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

395+
/**
396+
* Convert data property to internal property.
397+
*/
398+
#define ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY(property_p) \
399+
*(property_p) = (uint8_t) (*(property_p) + (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))
400+
394401
/**
395402
* Special property identifiers.
396403
*/
@@ -402,7 +409,7 @@ typedef enum
402409
ECMA_SPECIAL_PROPERTY_DELETED, /**< deleted property */
403410

404411
ECMA_SPECIAL_PROPERTY__COUNT /**< Number of special property types */
405-
} ecma_internal_property_id_t;
412+
} ecma_special_property_id_t;
406413

407414
/**
408415
* Define special property type.
@@ -420,15 +427,6 @@ typedef enum
420427
*/
421428
#define ECMA_PROPERTY_TYPE_HASHMAP ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_HASHMAP)
422429

423-
/**
424-
* Name constant of a deleted property.
425-
*/
426-
#ifdef JERRY_CPOINTER_32_BIT
427-
#define ECMA_PROPERTY_DELETED_NAME 0xffffffffu
428-
#else /* !JERRY_CPOINTER_32_BIT */
429-
#define ECMA_PROPERTY_DELETED_NAME 0xffffu
430-
#endif /* JERRY_CPOINTER_32_BIT */
431-
432430
/**
433431
* Type of property not found.
434432
*/
@@ -531,8 +529,7 @@ typedef struct
531529
* Returns true if the property pointer is a property pair.
532530
*/
533531
#define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) \
534-
(ECMA_PROPERTY_GET_TYPE ((property_header_p)->types[0]) != ECMA_PROPERTY_TYPE_VIRTUAL \
535-
&& (property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
532+
((property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
536533

537534
/**
538535
* Returns true if the property is named property.

jerry-core/ecma/base/ecma-helpers-external-pointers.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ ecma_create_native_pointer_property (ecma_object_t *obj_p, /**< object to create
4545
if (is_new)
4646
{
4747
ecma_property_value_t *value_p;
48-
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL);
48+
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p);
49+
50+
ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p);
4951

5052
native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
5153

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

94-
/**
95-
* Free the allocated native package struct.
96-
*/
97-
void
98-
ecma_free_native_pointer (ecma_property_t *prop_p) /**< native property */
99-
{
100-
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (prop_p);
101-
102-
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
103-
value_p->value);
104-
105-
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
106-
} /* ecma_free_native_pointer */
107-
10895
/**
10996
* @}
11097
* @}

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ JERRY_STATIC_ASSERT ((ECMA_OBJECT_MAX_REF | (ECMA_OBJECT_REF_ONE - 1)) == UINT16
6060
JERRY_STATIC_ASSERT (ECMA_PROPERTY_TYPE_DELETED == (ECMA_DIRECT_STRING_MAGIC << ECMA_PROPERTY_NAME_TYPE_SHIFT),
6161
ecma_property_type_deleted_must_have_magic_string_name_type);
6262

63-
JERRY_STATIC_ASSERT (ECMA_PROPERTY_DELETED_NAME >= LIT_MAGIC_STRING__COUNT,
64-
ecma_property_deleted_name_must_not_be_valid_maigc_string_id);
65-
6663
/**
6764
* Create an object with specified prototype object
6865
* (or NULL prototype if there is not prototype for the object)
@@ -468,7 +465,7 @@ ecma_create_property (ecma_object_t *object_p, /**< the object */
468465
/* Just copy the previous value (no need to decompress, compress). */
469466
first_property_pair_p->header.next_property_cp = *property_list_head_p;
470467
first_property_pair_p->header.types[0] = ECMA_PROPERTY_TYPE_DELETED;
471-
first_property_pair_p->names_cp[0] = ECMA_PROPERTY_DELETED_NAME;
468+
first_property_pair_p->names_cp[0] = LIT_INTERNAL_MAGIC_STRING_DELETED;
472469

473470
if (name_p == NULL)
474471
{
@@ -743,19 +740,11 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
743740
{
744741
case ECMA_PROPERTY_TYPE_NAMEDDATA:
745742
{
746-
if (ECMA_PROPERTY_GET_NAME_TYPE (*property_p) == ECMA_DIRECT_STRING_MAGIC
747-
&& (name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER))
748-
{
749-
ecma_free_native_pointer (property_p);
750-
break;
751-
}
752-
753743
ecma_free_value_if_not_object (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
754744
break;
755745
}
756-
default:
746+
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
757747
{
758-
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
759748
#ifdef JERRY_CPOINTER_32_BIT
760749
ecma_getter_setter_pointers_t *getter_setter_pair_p;
761750
getter_setter_pair_p = ECMA_GET_POINTER (ecma_getter_setter_pointers_t,
@@ -764,6 +753,13 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
764753
#endif /* JERRY_CPOINTER_32_BIT */
765754
break;
766755
}
756+
default:
757+
{
758+
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);
759+
760+
/* Currently no internal property can reach this point. */
761+
JERRY_UNREACHABLE ();
762+
}
767763
}
768764

769765
if (ecma_is_property_lcached (property_p))
@@ -821,7 +817,7 @@ ecma_delete_property (ecma_object_t *object_p, /**< object */
821817

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

826822
JERRY_ASSERT (ECMA_PROPERTY_PAIR_ITEM_COUNT == 2);
827823

@@ -963,7 +959,7 @@ ecma_delete_array_properties (ecma_object_t *object_p, /**< object */
963959

964960
ecma_free_property (object_p, prop_pair_p->names_cp[i], current_prop_p->types + i);
965961
current_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED;
966-
prop_pair_p->names_cp[i] = ECMA_PROPERTY_DELETED_NAME;
962+
prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED;
967963
}
968964
}
969965
}
@@ -1254,7 +1250,8 @@ inline bool JERRY_ATTR_ALWAYS_INLINE
12541250
ecma_is_property_lcached (ecma_property_t *property_p) /**< property */
12551251
{
12561252
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
1257-
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
1253+
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
1254+
|| ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_INTERNAL);
12581255

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

12721270
if (is_lcached)
12731271
{

jerry-core/ecma/base/ecma-helpers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
357357
/* ecma-helpers-external-pointers.c */
358358
bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p);
359359
ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p);
360-
void ecma_free_native_pointer (ecma_property_t *prop_p);
361360

362361
/* ecma-helpers-conversion.c */
363362
ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size);

jerry-core/ecma/base/ecma-lcache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
7474
JERRY_ASSERT (object_p != NULL);
7575
JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p));
7676
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
77-
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
77+
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
78+
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_INTERNAL);
7879

7980
#ifndef CONFIG_ECMA_LCACHE_DISABLE
8081
jmem_cpointer_t object_cp;

jerry-core/ecma/base/ecma-property-hashmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
9999
{
100100
ecma_property_types_t type = ECMA_PROPERTY_GET_TYPE (prop_iter_p->types[i]);
101101

102-
if (type == ECMA_PROPERTY_TYPE_NAMEDDATA || type == ECMA_PROPERTY_TYPE_NAMEDACCESSOR)
102+
if (type != ECMA_PROPERTY_TYPE_SPECIAL)
103103
{
104104
named_property_count++;
105105
}

jerry-core/lit/lit-magic-strings.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ typedef enum
3737
LIT_INTERNAL_MAGIC_STRING_ALREADY_RESOLVED, /**< [[AlreadyResolved]] of promise reject or resolve functions */
3838
LIT_INTERNAL_MAGIC_STRING_RESOLVE_FUNCTION, /**< the resolve funtion of the promise object */
3939
LIT_INTERNAL_MAGIC_STRING_REJECT_FUNCTION, /**< the reject function of the promise object */
40-
LIT_NEED_MARK_MAGIC_STRING__COUNT, /**< number of internal magic strings which will be used as properties' names,
41-
* and the properties need to be marked during gc. */
42-
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER = LIT_NEED_MARK_MAGIC_STRING__COUNT, /**< native pointer info associated
43-
* with an object */
40+
LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< number of internal magic strings which will be used as
41+
* property names, and their values need to be marked during gc. */
42+
LIT_INTERNAL_MAGIC_STRING_DELETED = LIT_GC_MARK_REQUIRED_MAGIC_STRING__COUNT, /**< special value for
43+
* deleted properties */
44+
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< native pointer info associated with an object */
4445
LIT_MAGIC_STRING__COUNT /**< number of magic strings */
4546
} lit_magic_string_id_t;
4647

0 commit comments

Comments
 (0)