Skip to content

Commit c1ea60f

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 c1ea60f

Some content is hidden

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

50 files changed

+653
-472
lines changed

jerry-core/api/jerryscript.c

Lines changed: 37 additions & 34 deletions
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,16 @@ 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
{
56585659
bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
56595660
}
56605661
#if JERRY_MODULE_SYSTEM
5661-
else if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_MODULE)
5662+
else if (ext_object_p->u.cls.head.type == ECMA_OBJECT_CLASS_MODULE)
56625663
{
56635664
ecma_module_t *module_p = (ecma_module_t *) object_p;
56645665

5665-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE))
5666+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE))
56665667
{
56675668
bytecode_p = module_p->u.compiled_code_p;
56685669
}
@@ -5993,7 +5994,7 @@ jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by th
59935994

59945995
if (buffer_p != NULL)
59955996
{
5996-
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
5997+
arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
59975998
arraybuffer_pointer_p->buffer_p = buffer_p;
59985999
}
59996000
}
@@ -6081,7 +6082,7 @@ jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store use
60816082

60826083
if (buffer_p != NULL)
60836084
{
6084-
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
6085+
shared_arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
60856086
shared_arraybuffer_pointer_p->buffer_p = buffer_p;
60866087
}
60876088
}
@@ -6529,7 +6530,7 @@ jerry_dataview_buffer (const jerry_value_t value, /**< DataView to get the array
65296530

65306531
if (byte_length != NULL)
65316532
{
6532-
*byte_length = dataview_p->header.u.cls.u3.length;
6533+
*byte_length = dataview_p->header.u.cls.dataview.length;
65336534
}
65346535

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

70337034
if (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_CONTAINER))
70347035
{
7035-
switch (((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id)
7036+
switch (((ecma_extended_object_t *) obj_p)->u.cls.container.id)
70367037
{
70377038
case LIT_MAGIC_STRING_MAP_UL:
70387039
{
@@ -7103,10 +7104,10 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
71037104

71047105
*is_key_value_p = false;
71057106

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)
7107+
if (ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
7108+
|| ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
71087109
{
7109-
ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value;
7110+
ecma_value_t iterated_value = ext_obj_p->u.cls.iterator.value;
71107111

71117112
if (ecma_is_value_empty (iterated_value))
71127113
{
@@ -7115,27 +7116,29 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
71157116

71167117
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) (ecma_get_object_from_value (iterated_value));
71177118

7118-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value);
7119+
ecma_collection_t *container_p =
7120+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.container.value);
71197121
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7120-
index = ext_obj_p->u.cls.u2.iterator_index;
7122+
index = ext_obj_p->u.cls.iterator.index;
71217123

7122-
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.u2.container_id);
7124+
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.container.id);
71237125
start_p = ECMA_CONTAINER_START (container_p);
71247126

7125-
iterator_kind = ext_obj_p->u.cls.u1.iterator_kind;
7127+
iterator_kind = ext_obj_p->u.cls.iterator.kind;
71267128
}
71277129
else if (jerry_container_type (value) != JERRY_CONTAINER_TYPE_INVALID)
71287130
{
7129-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.u3.value);
7131+
ecma_collection_t *container_p =
7132+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.container.value);
71307133
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7131-
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.u2.container_id);
7134+
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.container.id);
71327135

71337136
index = 0;
71347137
iterator_kind = ECMA_ITERATOR_KEYS;
71357138
start_p = ECMA_CONTAINER_START (container_p);
71367139

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)
7140+
if (ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_MAP_UL
7141+
|| ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_WEAKMAP_UL)
71397142
{
71407143
iterator_kind = ECMA_ITERATOR_ENTRIES;
71417144
}
@@ -7200,7 +7203,7 @@ jerry_container_op (jerry_container_op_t operation, /**< container operation */
72007203
{
72017204
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT));
72027205
}
7203-
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id;
7206+
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.container.id;
72047207
ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type);
72057208

72067209
if (container_object_p == NULL)

0 commit comments

Comments
 (0)