Skip to content

Commit 48ac53d

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 d66a705 commit 48ac53d

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,8 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
751751
{
752752
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
753753

754-
bytecode_data_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
754+
bytecode_data_p =
755+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
755756
}
756757
else if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION)
757758
{

jerry-core/api/jerryscript.c

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ jerry_parse_common (void *source_p, /**< script source */
454454
ecma_object_t *object_p = ecma_create_object (NULL, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS);
455455

456456
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
457-
ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_SCRIPT;
458-
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.cls.u3.value, bytecode_data_p);
457+
ext_object_p->u.cls.head.type = ECMA_OBJECT_CLASS_SCRIPT;
458+
ECMA_SET_INTERNAL_VALUE_POINTER (ecma_object_cls_general (ext_object_p)->value, bytecode_data_p);
459459

460460
return ecma_make_object_value (object_p);
461461
} /* jerry_parse_common */
@@ -542,7 +542,8 @@ jerry_run (const jerry_value_t script) /**< script or module to run */
542542
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
543543

544544
const ecma_compiled_code_t *bytecode_data_p;
545-
bytecode_data_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
545+
bytecode_data_p =
546+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
546547

547548
JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (bytecode_data_p->status_flags) == CBC_FUNCTION_SCRIPT);
548549

@@ -639,7 +640,7 @@ jerry_module_evaluate (const jerry_value_t module) /**< root module */
639640
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
640641
}
641642

642-
if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_LINKED)
643+
if (module_p->header.u.cls.module.state != JERRY_MODULE_STATE_LINKED)
643644
{
644645
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_MODULE_MUST_BE_IN_LINKED_STATE));
645646
}
@@ -671,7 +672,7 @@ jerry_module_state (const jerry_value_t module) /**< module object */
671672
return JERRY_MODULE_STATE_INVALID;
672673
}
673674

674-
return (jerry_module_state_t) module_p->header.u.cls.u1.module_state;
675+
return (jerry_module_state_t) module_p->header.u.cls.module.state;
675676
#else /* !JERRY_MODULE_SYSTEM */
676677
JERRY_UNUSED (module);
677678

@@ -819,8 +820,8 @@ jerry_module_namespace (const jerry_value_t module) /**< module */
819820
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
820821
}
821822

822-
if (module_p->header.u.cls.u1.module_state < JERRY_MODULE_STATE_LINKED
823-
|| module_p->header.u.cls.u1.module_state > JERRY_MODULE_STATE_EVALUATED)
823+
if (module_p->header.u.cls.module.state < JERRY_MODULE_STATE_LINKED
824+
|| module_p->header.u.cls.module.state > JERRY_MODULE_STATE_EVALUATED)
824825
{
825826
return jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_NAMESPACE_OBJECT_IS_NOT_AVAILABLE));
826827
}
@@ -953,7 +954,7 @@ jerry_native_module (jerry_native_module_evaluate_cb_t callback, /**< evaluation
953954

954955
ecma_module_t *module_p = ecma_module_create ();
955956

956-
module_p->header.u.cls.u2.module_flags |= ECMA_MODULE_IS_NATIVE;
957+
module_p->header.u.cls.module.flags |= ECMA_MODULE_IS_NATIVE;
957958
module_p->scope_p = scope_p;
958959
module_p->local_exports_p = local_exports_p;
959960
module_p->u.callback = callback;
@@ -994,7 +995,7 @@ jerry_native_module_get (const jerry_value_t native_module, /**< a native module
994995
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
995996
}
996997

997-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name))
998+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name))
998999
{
9991000
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_WRONG_ARGS_MSG));
10001001
}
@@ -1039,7 +1040,7 @@ jerry_native_module_set (jerry_value_t native_module, /**< a native module objec
10391040
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_NOT_MODULE));
10401041
}
10411042

1042-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name)
1043+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name)
10431044
|| ecma_is_value_exception (value))
10441045
{
10451046
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_WRONG_ARGS_MSG));
@@ -1535,8 +1536,8 @@ jerry_object_type (const jerry_value_t value) /**< input value to check */
15351536
case ECMA_OBJECT_TYPE_CLASS:
15361537
case ECMA_OBJECT_TYPE_BUILT_IN_CLASS:
15371538
{
1538-
JERRY_ASSERT (ext_obj_p->u.cls.type < ECMA_OBJECT_CLASS__MAX);
1539-
return jerry_class_object_type[ext_obj_p->u.cls.type];
1539+
JERRY_ASSERT (ext_obj_p->u.cls.head.type < ECMA_OBJECT_CLASS__MAX);
1540+
return jerry_class_object_type[ext_obj_p->u.cls.head.type];
15401541
}
15411542
case ECMA_OBJECT_TYPE_ARRAY:
15421543
case ECMA_OBJECT_TYPE_BUILT_IN_ARRAY:
@@ -1645,7 +1646,7 @@ jerry_iterator_type (const jerry_value_t value) /**< input value to check */
16451646

16461647
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_CLASS)
16471648
{
1648-
switch (ext_obj_p->u.cls.type)
1649+
switch (ext_obj_p->u.cls.head.type)
16491650
{
16501651
case ECMA_OBJECT_CLASS_ARRAY_ITERATOR:
16511652
{
@@ -3611,7 +3612,7 @@ jerry_object_set_internal (jerry_value_t object, /**< object value */
36113612
internal_object_p = ecma_create_object (NULL, sizeof (ecma_extended_object_t), ECMA_OBJECT_TYPE_CLASS);
36123613
{
36133614
ecma_extended_object_t *container_p = (ecma_extended_object_t *) internal_object_p;
3614-
container_p->u.cls.type = ECMA_OBJECT_CLASS_INTERNAL_OBJECT;
3615+
container_p->u.cls.head.type = ECMA_OBJECT_CLASS_INTERNAL_OBJECT;
36153616
}
36163617

36173618
value_p->value = ecma_make_object_value (internal_object_p);
@@ -4142,7 +4143,7 @@ jerry_object_is_valid_foreach (ecma_object_t *object_p) /**< object to test */
41424143
if (object_type == ECMA_OBJECT_TYPE_CLASS)
41434144
{
41444145
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
4145-
switch (ext_object_p->u.cls.type)
4146+
switch (ext_object_p->u.cls.head.type)
41464147
{
41474148
/* An object's internal property object should not be iterable by foreach. */
41484149
case ECMA_OBJECT_CLASS_INTERNAL_OBJECT:
@@ -5648,16 +5649,17 @@ jerry_source_info (const jerry_value_t value) /**< jerry api value */
56485649
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
56495650
const ecma_compiled_code_t *bytecode_p = NULL;
56505651

5651-
if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_SCRIPT)
5652+
if (ext_object_p->u.cls.head.type == ECMA_OBJECT_CLASS_SCRIPT)
56525653
{
5653-
bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ext_object_p->u.cls.u3.value);
5654+
bytecode_p =
5655+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, ecma_object_cls_general (ext_object_p)->value);
56545656
}
56555657
#if JERRY_MODULE_SYSTEM
5656-
else if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_MODULE)
5658+
else if (ext_object_p->u.cls.head.type == ECMA_OBJECT_CLASS_MODULE)
56575659
{
56585660
ecma_module_t *module_p = (ecma_module_t *) object_p;
56595661

5660-
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE))
5662+
if (!(module_p->header.u.cls.module.flags & ECMA_MODULE_IS_NATIVE))
56615663
{
56625664
bytecode_p = module_p->u.compiled_code_p;
56635665
}
@@ -5988,7 +5990,7 @@ jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by th
59885990

59895991
if (buffer_p != NULL)
59905992
{
5991-
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
5993+
arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
59925994
arraybuffer_pointer_p->buffer_p = buffer_p;
59935995
}
59945996
}
@@ -6076,7 +6078,7 @@ jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store use
60766078

60776079
if (buffer_p != NULL)
60786080
{
6079-
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
6081+
shared_arraybuffer_pointer_p->extended_object.u.cls.arraybuffer.flags |= ECMA_ARRAYBUFFER_ALLOCATED;
60806082
shared_arraybuffer_pointer_p->buffer_p = buffer_p;
60816083
}
60826084
}
@@ -6524,7 +6526,7 @@ jerry_dataview_buffer (const jerry_value_t value, /**< DataView to get the array
65246526

65256527
if (byte_length != NULL)
65266528
{
6527-
*byte_length = dataview_p->header.u.cls.u3.length;
6529+
*byte_length = dataview_p->header.u.cls.dataview.length;
65286530
}
65296531

65306532
ecma_object_t *arraybuffer_p = dataview_p->buffer_p;
@@ -7025,7 +7027,7 @@ jerry_container_type (const jerry_value_t value) /**< the container object */
70257027

70267028
if (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_CONTAINER))
70277029
{
7028-
switch (((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id)
7030+
switch (((ecma_extended_object_t *) obj_p)->u.cls.container.id)
70297031
{
70307032
case LIT_MAGIC_STRING_MAP_UL:
70317033
{
@@ -7096,10 +7098,10 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
70967098

70977099
*is_key_value_p = false;
70987100

7099-
if (ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
7100-
|| ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
7101+
if (ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
7102+
|| ext_obj_p->u.cls.head.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
71017103
{
7102-
ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value;
7104+
ecma_value_t iterated_value = ext_obj_p->u.cls.iterator.value;
71037105

71047106
if (ecma_is_value_empty (iterated_value))
71057107
{
@@ -7108,27 +7110,29 @@ jerry_container_to_array (const jerry_value_t value, /**< the container or itera
71087110

71097111
ecma_extended_object_t *map_object_p = (ecma_extended_object_t *) (ecma_get_object_from_value (iterated_value));
71107112

7111-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.u3.value);
7113+
ecma_collection_t *container_p =
7114+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, map_object_p->u.cls.container.value);
71127115
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7113-
index = ext_obj_p->u.cls.u2.iterator_index;
7116+
index = ext_obj_p->u.cls.iterator.index;
71147117

7115-
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.u2.container_id);
7118+
entry_size = ecma_op_container_entry_size (map_object_p->u.cls.container.id);
71167119
start_p = ECMA_CONTAINER_START (container_p);
71177120

7118-
iterator_kind = ext_obj_p->u.cls.u1.iterator_kind;
7121+
iterator_kind = ext_obj_p->u.cls.iterator.kind;
71197122
}
71207123
else if (jerry_container_type (value) != JERRY_CONTAINER_TYPE_INVALID)
71217124
{
7122-
ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.u3.value);
7125+
ecma_collection_t *container_p =
7126+
ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.container.value);
71237127
entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
7124-
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.u2.container_id);
7128+
entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.container.id);
71257129

71267130
index = 0;
71277131
iterator_kind = ECMA_ITERATOR_KEYS;
71287132
start_p = ECMA_CONTAINER_START (container_p);
71297133

7130-
if (ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_MAP_UL
7131-
|| ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL)
7134+
if (ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_MAP_UL
7135+
|| ext_obj_p->u.cls.container.id == LIT_MAGIC_STRING_WEAKMAP_UL)
71327136
{
71337137
iterator_kind = ECMA_ITERATOR_ENTRIES;
71347138
}
@@ -7193,7 +7197,7 @@ jerry_container_op (jerry_container_op_t operation, /**< container operation */
71937197
{
71947198
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_CONTAINER_IS_NOT_A_CONTAINER_OBJECT));
71957199
}
7196-
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id;
7200+
uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.container.id;
71977201
ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type);
71987202

71997203
if (container_object_p == NULL)

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

Lines changed: 2 additions & 0 deletions
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)