Skip to content

Commit 0a40f55

Browse files
zherczegrobertsipka
authored andcommitted
Introducing internal properties. (#2485)
Native handle and pointer are moved to internal properties. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 30b7a72 commit 0a40f55

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
@@ -165,12 +165,6 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
165165
{
166166
case ECMA_PROPERTY_TYPE_NAMEDDATA:
167167
{
168-
if (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
169-
&& property_pair_p->names_cp[index] >= LIT_NEED_MARK_MAGIC_STRING__COUNT)
170-
{
171-
break;
172-
}
173-
174168
ecma_value_t value = property_pair_p->values[index].value;
175169

176170
if (ecma_is_value_object (value))
@@ -198,6 +192,12 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
198192
}
199193
break;
200194
}
195+
case ECMA_PROPERTY_TYPE_INTERNAL:
196+
{
197+
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
198+
&& property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER);
199+
break;
200+
}
201201
default:
202202
{
203203
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_SPECIAL);
@@ -497,6 +497,8 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p) /**< property */
497497
free_cb (native_pointer_p->data_p);
498498
}
499499
}
500+
501+
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
500502
} /* ecma_gc_free_native_pointer */
501503

502504
/**
@@ -543,8 +545,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
543545
{
544546
ecma_gc_free_native_pointer (property_p);
545547
}
546-
547-
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
548+
else if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
548549
{
549550
ecma_free_property (object_p, name_cp, property_p);
550551
}

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

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

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

394+
/**
395+
* Convert data property to internal property.
396+
*/
397+
#define ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY(property_p) \
398+
*(property_p) = (uint8_t) (*(property_p) + (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))
399+
393400
/**
394401
* Special property identifiers.
395402
*/
@@ -401,7 +408,7 @@ typedef enum
401408
ECMA_SPECIAL_PROPERTY_DELETED, /**< deleted property */
402409

403410
ECMA_SPECIAL_PROPERTY__COUNT /**< Number of special property types */
404-
} ecma_internal_property_id_t;
411+
} ecma_special_property_id_t;
405412

406413
/**
407414
* Define special property type.
@@ -419,15 +426,6 @@ typedef enum
419426
*/
420427
#define ECMA_PROPERTY_TYPE_HASHMAP ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_HASHMAP)
421428

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

536533
/**
537534
* 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
@@ -358,7 +358,6 @@ void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
358358
/* ecma-helpers-external-pointers.c */
359359
bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p);
360360
ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p);
361-
void ecma_free_native_pointer (ecma_property_t *prop_p);
362361

363362
/* ecma-helpers-conversion.c */
364363
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)