Skip to content

Commit f044955

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 300e40b commit f044955

File tree

8 files changed

+47
-62
lines changed

8 files changed

+47
-62
lines changed

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

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

174168
if (ecma_is_value_object (value))
@@ -196,6 +190,13 @@ ecma_gc_mark_property (ecma_property_pair_t *property_pair_p, /**< property pair
196190
}
197191
break;
198192
}
193+
case ECMA_PROPERTY_TYPE_INTERNAL:
194+
{
195+
JERRY_ASSERT (ECMA_PROPERTY_GET_NAME_TYPE (property) == ECMA_DIRECT_STRING_MAGIC
196+
&& (property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE
197+
|| property_pair_p->names_cp[index] == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER));
198+
break;
199+
}
199200
default:
200201
{
201202
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (property) == ECMA_PROPERTY_TYPE_SPECIAL);
@@ -437,6 +438,8 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p, /**< property */
437438
}
438439
}
439440
}
441+
442+
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
440443
} /* ecma_gc_free_native_pointer */
441444

442445
/**
@@ -484,8 +487,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
484487
{
485488
ecma_gc_free_native_pointer (property_p, (lit_magic_string_id_t) name_cp);
486489
}
487-
488-
if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
490+
else if (prop_iter_p->types[i] != ECMA_PROPERTY_TYPE_DELETED)
489491
{
490492
ecma_free_property (object_p, name_cp, property_p);
491493
}

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,11 @@ typedef enum
336336
*/
337337
typedef enum
338338
{
339-
ECMA_PROPERTY_TYPE_SPECIAL, /**< internal property */
339+
ECMA_PROPERTY_TYPE_SPECIAL, /**< special purpose property (deleted / hashmap) */
340340
ECMA_PROPERTY_TYPE_NAMEDDATA, /**< property is named data */
341341
ECMA_PROPERTY_TYPE_NAMEDACCESSOR, /**< property is named accessor */
342-
ECMA_PROPERTY_TYPE_VIRTUAL, /**< property is virtual */
342+
ECMA_PROPERTY_TYPE_INTERNAL, /**< internal property with custom data field */
343+
ECMA_PROPERTY_TYPE_VIRTUAL = ECMA_PROPERTY_TYPE_INTERNAL, /**< property is virtual data property */
343344

344345
ECMA_PROPERTY_TYPE__MAX = ECMA_PROPERTY_TYPE_VIRTUAL, /**< highest value for property types. */
345346
} ecma_property_types_t;
@@ -400,6 +401,12 @@ typedef enum
400401
*/
401402
#define ECMA_PROPERTY_NAME_TYPE_SHIFT (ECMA_PROPERTY_FLAG_SHIFT + 4)
402403

404+
/**
405+
* Convert data property to internal property.
406+
*/
407+
#define ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY(property_p) \
408+
*(property_p) = (uint8_t) (*(property_p) + (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))
409+
403410
/**
404411
* Special property identifiers.
405412
*/
@@ -411,7 +418,7 @@ typedef enum
411418
ECMA_SPECIAL_PROPERTY_DELETED, /**< deleted property */
412419

413420
ECMA_SPECIAL_PROPERTY__COUNT /**< Number of special property types */
414-
} ecma_internal_property_id_t;
421+
} ecma_special_property_id_t;
415422

416423
/**
417424
* Define special property type.
@@ -429,15 +436,6 @@ typedef enum
429436
*/
430437
#define ECMA_PROPERTY_TYPE_HASHMAP ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_HASHMAP)
431438

432-
/**
433-
* Name constant of a deleted property.
434-
*/
435-
#ifdef JERRY_CPOINTER_32_BIT
436-
#define ECMA_PROPERTY_DELETED_NAME 0xffffffffu
437-
#else /* !JERRY_CPOINTER_32_BIT */
438-
#define ECMA_PROPERTY_DELETED_NAME 0xffffu
439-
#endif /* JERRY_CPOINTER_32_BIT */
440-
441439
/**
442440
* Type of property not found.
443441
*/
@@ -540,8 +538,7 @@ typedef struct
540538
* Returns true if the property pointer is a property pair.
541539
*/
542540
#define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) \
543-
(ECMA_PROPERTY_GET_TYPE ((property_header_p)->types[0]) != ECMA_PROPERTY_TYPE_VIRTUAL \
544-
&& (property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
541+
((property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
545542

546543
/**
547544
* Returns true if the property is named property.

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ ecma_create_native_property (ecma_object_t *obj_p, /**< object to create propert
5555
if (is_new)
5656
{
5757
ecma_property_value_t *value_p;
58-
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, NULL);
58+
value_p = ecma_create_named_data_property (obj_p, name_p, ECMA_PROPERTY_FLAG_WRITABLE, &property_p);
59+
60+
ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY (property_p);
5961

6062
native_pointer_p = jmem_heap_alloc_block (sizeof (ecma_native_pointer_t));
6163

@@ -139,20 +141,6 @@ ecma_get_native_pointer_value (ecma_object_t *obj_p, /**< object to get property
139141
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t, value_p->value);
140142
} /* ecma_get_native_pointer_value */
141143

142-
/**
143-
* Free the allocated native package struct.
144-
*/
145-
void
146-
ecma_free_native_pointer (ecma_property_t *prop_p) /**< native property */
147-
{
148-
ecma_property_value_t *value_p = ECMA_PROPERTY_VALUE_PTR (prop_p);
149-
150-
ecma_native_pointer_t *native_pointer_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_native_pointer_t,
151-
value_p->value);
152-
153-
jmem_heap_free_block (native_pointer_p, sizeof (ecma_native_pointer_t));
154-
} /* ecma_free_native_pointer */
155-
156144
/**
157145
* @}
158146
* @}

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

Lines changed: 15 additions & 18 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,20 +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_HANDLE
748-
|| name_cp == LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER))
749-
{
750-
ecma_free_native_pointer (property_p);
751-
break;
752-
}
753-
754743
ecma_free_value_if_not_object (ECMA_PROPERTY_VALUE_PTR (property_p)->value);
755744
break;
756745
}
757-
default:
746+
case ECMA_PROPERTY_TYPE_NAMEDACCESSOR:
758747
{
759-
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
760748
#ifdef JERRY_CPOINTER_32_BIT
761749
ecma_getter_setter_pointers_t *getter_setter_pair_p;
762750
getter_setter_pair_p = ECMA_GET_POINTER (ecma_getter_setter_pointers_t,
@@ -765,6 +753,13 @@ ecma_free_property (ecma_object_t *object_p, /**< object the property belongs to
765753
#endif /* JERRY_CPOINTER_32_BIT */
766754
break;
767755
}
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+
}
768763
}
769764

770765
if (ecma_is_property_lcached (property_p))
@@ -822,7 +817,7 @@ ecma_delete_property (ecma_object_t *object_p, /**< object */
822817

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

827822
JERRY_ASSERT (ECMA_PROPERTY_PAIR_ITEM_COUNT == 2);
828823

@@ -964,7 +959,7 @@ ecma_delete_array_properties (ecma_object_t *object_p, /**< object */
964959

965960
ecma_free_property (object_p, prop_pair_p->names_cp[i], current_prop_p->types + i);
966961
current_prop_p->types[i] = ECMA_PROPERTY_TYPE_DELETED;
967-
prop_pair_p->names_cp[i] = ECMA_PROPERTY_DELETED_NAME;
962+
prop_pair_p->names_cp[i] = LIT_INTERNAL_MAGIC_STRING_DELETED;
968963
}
969964
}
970965
}
@@ -1255,7 +1250,8 @@ inline bool JERRY_ATTR_ALWAYS_INLINE
12551250
ecma_is_property_lcached (ecma_property_t *property_p) /**< property */
12561251
{
12571252
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
1258-
|| 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);
12591255

12601256
return (*property_p & ECMA_PROPERTY_FLAG_LCACHED) != 0;
12611257
} /* ecma_is_property_lcached */
@@ -1268,7 +1264,8 @@ ecma_set_property_lcached (ecma_property_t *property_p, /**< property */
12681264
bool is_lcached) /**< new value for lcached flag */
12691265
{
12701266
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*property_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
1271-
|| 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);
12721269

12731270
if (is_lcached)
12741271
{

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
bool ecma_create_native_handle_property (ecma_object_t *obj_p, void *handle_p, void *free_cb);
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, lit_magic_string_id_t id);
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
@@ -87,7 +87,8 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
8787
JERRY_ASSERT (object_p != NULL);
8888
JERRY_ASSERT (prop_p != NULL && !ecma_is_property_lcached (prop_p));
8989
JERRY_ASSERT (ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDDATA
90-
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR);
90+
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_NAMEDACCESSOR
91+
|| ECMA_PROPERTY_GET_TYPE (*prop_p) == ECMA_PROPERTY_TYPE_INTERNAL);
9192

9293
#ifndef CONFIG_ECMA_LCACHE_DISABLE
9394
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_HANDLE = LIT_NEED_MARK_MAGIC_STRING__COUNT, /**< native handle package
43-
* associated 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_HANDLE, /**< native handle package associated with an object */
4445
LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< native pointer package associated with an object */
4546
LIT_MAGIC_STRING__COUNT /**< number of magic strings */
4647
} lit_magic_string_id_t;

0 commit comments

Comments
 (0)