Skip to content

Commit 00db22d

Browse files
committed
Refactoring ecma_extended_object_t::cls:: to ease the coding about builtin object class
Currently all builtin class are sharing same union u1 u2 u3 in ecma_extended_object_t::cls::, that's complicated the things Now we split general object class into ecma_object_cls_general_t and can only access with ecma_object_cls_general, for others split it into separate struct, so when new builtin object class, bug-fixing, feature improving will be easier. JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent dfa9afb commit 00db22d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+708
-499
lines changed

jerry-core/api/jerry-snapshot.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
755755
{
756756
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
757757

758-
bytecode_data_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
758+
bytecode_data_p =
759+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
759760
}
760761
else if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
761762
{

jerry-core/api/jerryscript.c

+39-35
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ jerry_parse_common (void *source_p, /**< script source */
459459
ecma_object_t *object_p = ecma_create_object (NULL, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS);
460460

461461
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
462-
ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_SCRIPT;
463-
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.cls.u3.value, bytecode_data_p);
462+
ext_object_p->u.cls.head.type = ECMA_OBJECT_CLASS_SCRIPT;
463+
ECMA_SET_INTERNAL_VALUE_POINTER (ecma_object_cls_general (ext_object_p)->value, bytecode_data_p);
464464

465465
return ecma_make_object_value (object_p);
466466
} /* jerry_parse_common */
@@ -547,7 +547,8 @@ jerry_run (const jerry_value_t script) /**< script or module to run */
547547
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
548548

549549
const ecma_compiled_code_t *bytecode_data_p;
550-
bytecode_data_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
550+
bytecode_data_p =
551+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
551552

552553
JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_SCRIPT);
553554

@@ -644,7 +645,7 @@ jerry_module_evaluate (const jerry_value_t module) /**< root module */
644645
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
645646
}
646647

647-
if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_LINKED)
648+
if (module_p->header.u.cls.module.state != JERRY_MODULE_STATE_LINKED)
648649
{
649650
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE));
650651
}
@@ -676,7 +677,7 @@ jerry_module_state (const jerry_value_t module) /**< module object */
676677
return JERRY_MODULE_STATE_INVALID;
677678
}
678679

679-
return (jerry_module_state_t) module_p->header.u.cls.u1.module_state;
680+
return (jerry_module_state_t) module_p->header.u.cls.module.state;
680681
#else /* !JERRY_MODULE_SYSTEM */
681682
JERRY_UNUSED (module);
682683

@@ -824,8 +825,8 @@ jerry_module_namespace (const jerry_value_t module) /**< module */
824825
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
825826
}
826827

827-
if (module_p->header.u.cls.u1.module_state < JERRY_MODULE_STATE_LINKED
828-
|| module_p->header.u.cls.u1.module_state > JERRY_MODULE_STATE_EVALUATED)
828+
if (module_p->header.u.cls.module.state < JERRY_MODULE_STATE_LINKED
829+
|| module_p->header.u.cls.module.state > JERRY_MODULE_STATE_EVALUATED)
829830
{
830831
return jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE));
831832
}
@@ -958,7 +959,7 @@ jerry_native_module (jerry_native_module_evaluate_cb_t callback, /**< evaluation
958959

959960
ecma_module_t *module_p = ecma_module_create ();
960961

961-
module_p->header.u.cls.u2.module_flags |= ECMA_MODULE_IS_NATIVE;
962+
module_p->header.u.cls.module.flags |= ECMA_MODULE_IS_NATIVE;
962963
module_p->scope_p = scope_p;
963964
module_p->local_exports_p = local_exports_p;
964965
module_p->u.callback = callback;
@@ -999,7 +1000,7 @@ jerry_native_module_get (const jerry_value_t native_module, /**< a native module
9991000
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
10001001
}
10011002

1002-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name))
1003+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name))
10031004
{
10041005
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_WRONG_ARGS_MSG));
10051006
}
@@ -1044,7 +1045,7 @@ jerry_native_module_set (jerry_value_t native_module, /**< a native module objec
10441045
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
10451046
}
10461047

1047-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name)
1048+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name)
10481049
|| ecma_is_value_exception (value))
10491050
{
10501051
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_WRONG_ARGS_MSG));
@@ -1540,8 +1541,8 @@ jerry_object_type (const jerry_value_t value) /**< input value to check */
15401541
case ECMA_OBJECT_TYPE_CLASS:
15411542
case ECMA_OBJECT_TYPE_BUILT_IN_CLASS:
15421543
{
1543-
JERRY_ASSERT (ext_obj_p->u.cls.type < ECMA_OBJECT_CLASS__MAX);
1544-
return jerry_class_object_type[ext_obj_p->u.cls.type];
1544+
JERRY_ASSERT (ext_obj_p->u.cls.head.type < ECMA_OBJECT_CLASS__MAX);
1545+
return jerry_class_object_type[ext_obj_p->u.cls.head.type];
15451546
}
15461547
case ECMA_OBJECT_TYPE_ARRAY:
15471548
case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY:
@@ -1650,7 +1651,7 @@ jerry_iterator_type (const jerry_value_t value) /**< input value to check */
16501651

16511652
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_CLASS)
16521653
{
1653-
switch (ext_obj_p->u.cls.type)
1654+
switch (ext_obj_p->u.cls.head.type)
16541655
{
16551656
case ECMA_OBJECT_CLASS_ARRAY_ITERATOR:
16561657
{
@@ -3616,7 +3617,7 @@ jerry_object_set_internal (jerry_value_t object, /**< object value */
36163617
internal_object_p = ecma_create_object (NULL, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS);
36173618
{
36183619
ecma_extended_object_t *container_p = (ecma_extended_object_t *) internal_object_p;
3619-
container_p->u.cls.type = ECMA_OBJECT_CLASS_INTERNAL_OBJECT;
3620+
container_p->u.cls.head.type = ECMA_OBJECT_CLASS_INTERNAL_OBJECT;
36203621
}
36213622

36223623
value_p->value = ecma_make_object_value (internal_object_p);
@@ -4147,7 +4148,7 @@ jerry_object_is_valid_foreach (ecma_object_t *object_p) /**< object to test */
41474148
if (object_type == ECMA_OBJECT_TYPE_CLASS)
41484149
{
41494150
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
4150-
switch (ext_object_p->u.cls.type)
4151+
switch (ext_object_p->u.cls.head.type)
41514152
{
41524153
/* An object's internal property object should not be iterable by foreach. */
41534154
case ECMA_OBJECT_CLASS_INTERNAL_OBJECT:
@@ -5653,16 +5654,17 @@ jerry_source_info (const jerry_value_t value) /**< jerry api value */
56535654
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
56545655
const ecma_compiled_code_t *bytecode_p = NULL;
56555656

5656-
if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_SCRIPT)
5657+
if (ext_object_p->u.cls.head.type == ECMA_OBJECT_CLASS_SCRIPT)
56575658
{
5658-
bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
5659+
bytecode_p =
5660+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
56595661
}
56605662
#if JERRY_MODULE_SYSTEM
5661-
else if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_MODULE)
5663+
else if (ext_object_p->u.cls.head.type == ECMA_OBJECT_CLASS_MODULE)
56625664
{
56635665
ecma_module_t *module_p = (ecma_module_t *) object_p;
56645666

5665-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE))
5667+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE))
56665668
{
56675669
bytecode_p = module_p->u.compiled_code_p;
56685670
}
@@ -5993,7 +5995,7 @@ jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by th
59935995

59945996
if (buffer_p != NULL)
59955997
{
5996-
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
5998+
arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
59975999
arraybuffer_pointer_p->buffer_p = buffer_p;
59986000
}
59996001
}
@@ -6081,7 +6083,7 @@ jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store use
60816083

60826084
if (buffer_p != NULL)
60836085
{
6084-
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
6086+
shared_arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
60856087
shared_arraybuffer_pointer_p->buffer_p = buffer_p;
60866088
}
60876089
}
@@ -6529,7 +6531,7 @@ jerry_dataview_buffer (const jerry_value_t value, /**< DataView to get the array
65296531

65306532
if (byte_length != NULL)
65316533
{
6532-
*byte_length = dataview_p->header.u.cls.u3.length;
6534+
*byte_length = dataview_p->header.u.cls.dataview.length;
65336535
}
65346536

65356537
ecma_object_t *arraybuffer_p = dataview_p->buffer_p;
@@ -7032,7 +7034,7 @@ jerry_container_type (const jerry_value_t value) /**< the container object */
70327034

70337035
if (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_CONTAINER))
70347036
{
7035-
switch (((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id)
7037+
switch (((ecma_extended_object_t *) obj_p)->u.cls.container.id)
70367038
{
70377039
case LIT_MAGIC_STRING_MAP_UL:
70387040
{
@@ -7103,10 +7105,10 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
71037105

71047106
*is_key_value_p = false;
71057107

7106-
if (ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
7107-
|| ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
7108+
if (ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
7109+
|| ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
71087110
{
7109-
ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value;
7111+
ecma_value_t iterated_value = ext_obj_p->u.cls.iterator.value;
71107112

71117113
if (ecma_is_value_empty (iterated_value))
71127114
{
@@ -7115,27 +7117,29 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
71157117

71167118
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) (ecma_get_object_from_value (iterated_value));
71177119

7118-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value);
7120+
ecma_collection_t *container_p =
7121+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.container.value);
71197122
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7120-
index = ext_obj_p->u.cls.u2.iterator_index;
7123+
index = ext_obj_p->u.cls.iterator.index;
71217124

7122-
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.u2.container_id);
7125+
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.container.id);
71237126
start_p = ECMA_CONTAINER_START (container_p);
71247127

7125-
iterator_kind = ext_obj_p->u.cls.u1.iterator_kind;
7128+
iterator_kind = ext_obj_p->u.cls.iterator.kind;
71267129
}
71277130
else if (jerry_container_type (value) != JERRY_CONTAINER_TYPE_INVALID)
71287131
{
7129-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.u3.value);
7132+
ecma_collection_t *container_p =
7133+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.container.value);
71307134
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7131-
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.u2.container_id);
7135+
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.container.id);
71327136

71337137
index = 0;
71347138
iterator_kind = ECMA_ITERATOR_KEYS;
71357139
start_p = ECMA_CONTAINER_START (container_p);
71367140

7137-
if (ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_MAP_UL
7138-
|| ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL)
7141+
if (ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_MAP_UL
7142+
|| ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_WEAKMAP_UL)
71397143
{
71407144
iterator_kind = ECMA_ITERATOR_ENTRIES;
71417145
}
@@ -7200,7 +7204,7 @@ jerry_container_op (jerry_container_op_t operation, /**< container operation */
72007204
{
72017205
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT));
72027206
}
7203-
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id;
7207+
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.container.id;
72047208
ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type);
72057209

72067210
if (container_object_p == NULL)

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

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ JERRY_STATIC_ASSERT (((sizeof (ecma_property_value_t) - 1) & sizeof (ecma_proper
2929
JERRY_STATIC_ASSERT (sizeof (ecma_extended_object_t) - sizeof (ecma_object_t) <= sizeof (uint64_t),
3030
size_of_ecma_extended_object_part_must_be_less_than_or_equal_to_8_bytes);
3131

32+
JERRY_STATIC_ASSERT (sizeof (ecma_object_cls_t) == 8, size_of_ecma_object_cls_t_should_be_8_bytes);
33+
3234
/** \addtogroup ecma ECMA
3335
* @{
3436
*

0 commit comments

Comments
 (0)