Skip to content

Commit 4ae83c9

Browse files
committed
update PR version 3
* change extended_object_t.class_prop struct * change accessor macro name JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang [email protected]
1 parent 3594dd9 commit 4ae83c9

File tree

60 files changed

+211
-289
lines changed

Some content is hidden

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

60 files changed

+211
-289
lines changed

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

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "re-compiler.h"
3232
#include "vm-defines.h"
3333
#include "vm-stack.h"
34-
#include "jmem-heap.h"
3534

3635
#define JERRY_INTERNAL
3736
#include "jerry-internal.h"
@@ -410,8 +409,6 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
410409
if (object_type == ECMA_OBJECT_TYPE_CLASS)
411410
{
412411
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
413-
bool is_contain_arraybuffer = false;
414-
ecma_length_t arraybuffer_length = 0;
415412

416413
switch (ext_object_p->u.class_prop.class_id)
417414
{
@@ -427,52 +424,46 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
427424
case LIT_MAGIC_STRING_STRING_UL:
428425
case LIT_MAGIC_STRING_NUMBER_UL:
429426
{
430-
ecma_free_value (ext_object_p->u.class_prop.value);
431-
break;
432-
}
433-
case LIT_MAGIC_STRING_ARRAY_BUFFER_UL:
434-
{
435-
arraybuffer_length = ecma_get_uint32_from_value (ext_object_p->u.class_prop.value);
436-
is_contain_arraybuffer = true;
437-
ecma_free_value (ext_object_p->u.class_prop.value);
427+
ecma_free_value (ext_object_p->u.class_prop.u.value);
438428
break;
439429
}
440430

441431
case LIT_MAGIC_STRING_DATE_UL:
442432
{
443433
ecma_number_t *num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
444-
ext_object_p->u.class_prop.value);
434+
ext_object_p->u.class_prop.u.value);
445435
ecma_dealloc_number (num_p);
446436
break;
447437
}
448438

449439
case LIT_MAGIC_STRING_REGEXP_UL:
450440
{
451441
ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
452-
ext_object_p->u.class_prop.value);
442+
ext_object_p->u.class_prop.u.value);
453443
if (bytecode_p != NULL)
454444
{
455445
ecma_bytecode_deref (bytecode_p);
456446
}
457447
break;
458448
}
459-
449+
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
450+
case LIT_MAGIC_STRING_ARRAY_BUFFER_UL:
451+
{
452+
ecma_length_t arraybuffer_length = ext_object_p->u.class_prop.u.length;
453+
size_t size = sizeof (ecma_extended_object_t) + arraybuffer_length;
454+
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p, size);
455+
return;
456+
}
457+
#endif /* CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
460458
default:
461459
{
462460
JERRY_UNREACHABLE ();
463461
break;
464462
}
465463
}
466-
size_t size;
467-
if (is_contain_arraybuffer)
468-
{
469-
size = sizeof (ecma_extended_object_t) + arraybuffer_length;
470-
}
471-
else
472-
{
473-
size = (ecma_get_object_is_builtin (object_p) ? sizeof (ecma_extended_built_in_object_t)
474-
: sizeof (ecma_extended_object_t));
475-
}
464+
465+
size_t size = (ecma_get_object_is_builtin (object_p) ? sizeof (ecma_extended_built_in_object_t)
466+
: sizeof (ecma_extended_object_t));
476467
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p, size);
477468
return;
478469
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,14 @@ typedef struct
626626
struct
627627
{
628628
uint16_t class_id; /**< class id of the object */
629-
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
629+
/*
630+
* Description of extra fields. These extra fields depends on the class_id.
631+
*/
632+
union
633+
{
634+
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
635+
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
636+
} u;
630637
} class_prop;
631638

632639
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ extern ecma_property_value_t *
282282
ecma_create_named_data_property (ecma_object_t *, ecma_string_t *, uint8_t, ecma_property_t **);
283283
extern ecma_property_value_t *
284284
ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *,
285-
ecma_object_t *, uint8_t, ecma_property_t **);
285+
ecma_object_t *, uint8_t, ecma_property_t **);
286286
extern ecma_property_t *
287287
ecma_find_named_property (ecma_object_t *, ecma_string_t *);
288288
extern ecma_property_value_t *

jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,5 @@ ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ecma_builtin_array_prototype_object_r
8383
#undef STRING_VALUE
8484
#undef OBJECT_VALUE
8585
#undef ROUTINE
86-
#undef ACCESSOR_VALUE
87-
#undef ACCESSOR_RO_VALUE
88-
#undef ACCESSOR_WO_VALUE
86+
#undef ACCESSOR_READ_WRITE
87+
#undef ACCESSOR_READ_ONLY

jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
6262
#undef STRING_VALUE
6363
#undef OBJECT_VALUE
6464
#undef ROUTINE
65-
#undef ACCESSOR_VALUE
66-
#undef ACCESSOR_RO_VALUE
67-
#undef ACCESSOR_WO_VALUE
65+
#undef ACCESSOR_READ_WRITE
66+
#undef ACCESSOR_READ_ONLY

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16-
#include "ecma-alloc.h"
17-
#include "ecma-array-object.h"
1816
#include "ecma-builtin-helpers.h"
1917
#include "ecma-builtins.h"
20-
#include "ecma-conversion.h"
2118
#include "ecma-exceptions.h"
22-
#include "ecma-function-object.h"
23-
#include "ecma-gc.h"
2419
#include "ecma-globals.h"
2520
#include "ecma-helpers.h"
2621
#include "ecma-objects.h"
@@ -29,8 +24,6 @@
2924
#include "jrt.h"
3025
#include "jrt-libc-includes.h"
3126

32-
33-
3427
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
3528

3629
#define ECMA_BUILTINS_INTERNAL
@@ -60,7 +53,7 @@
6053
* Returned value must be freed with ecma_free_value.
6154
*/
6255
static ecma_value_t
63-
ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg)
56+
ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */
6457
{
6558
if (ecma_is_value_object (this_arg))
6659
{
@@ -71,8 +64,8 @@ ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg)
7164

7265
return ecma_make_uint32_value (len);
7366
}
74-
7567
}
68+
7669
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a ArrayBuffer object."));
7770
} /* ecma_builtin_arraybuffer_prototype_bytelength_getter */
7871

@@ -114,11 +107,7 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
114107

115108
start = ecma_builtin_helper_array_index_normalize (start_num, len);
116109

117-
if (ecma_is_value_undefined (arg2))
118-
{
119-
end = len;
120-
}
121-
else
110+
if (!ecma_is_value_undefined (arg2))
122111
{
123112
ECMA_OP_TO_NUMBER_TRY_CATCH (end_num,
124113
arg2,

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@
2929
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
3030
#endif /* !ROUTINE */
3131

32-
#ifndef ACCESSOR_VALUE
33-
# define ACCESSOR_VALUE(name, c_getter_func_name, c_setter_func_name, prop_attributes)
32+
#ifndef ACCESSOR_READ_WRITE
33+
# define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes)
3434
#endif /* !ROUTINE */
3535

36-
#ifndef ACCESSOR_RO_VALUE
37-
# define ACCESSOR_RO_VALUE(name, c_getter_func_name, prop_attributes)
38-
#endif /* !ACCESSOR_RO_VALUE */
39-
40-
#ifndef ACCESSOR_WO_VALUE
41-
# define ACCESSOR_WO_VALUE(name, c_setter_func_name, prop_attributes)
42-
#endif /* !ACCESSOR_WO_VALUE */
36+
#ifndef ACCESSOR_READ_ONLY
37+
# define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes)
38+
#endif /* !ACCESSOR_READ_ONLY */
4339

4440
/* Object identifier */
4541
OBJECT_ID (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE)
@@ -51,23 +47,20 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
5147
ECMA_BUILTIN_ID_ARRAYBUFFER,
5248
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
5349

54-
50+
/* Readonly accessor properties */
51+
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
52+
ecma_builtin_arraybuffer_prototype_bytelength_getter,
53+
ECMA_PROPERTY_FIXED)
5554

5655
/* Routine properties:
5756
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
5857
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, 2, 2)
5958

60-
/* readonly accessor properties */
61-
ACCESSOR_RO_VALUE (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
62-
ecma_builtin_arraybuffer_prototype_bytelength_getter,
63-
ECMA_PROPERTY_FIXED)
64-
6559
#undef OBJECT_ID
6660
#undef SIMPLE_VALUE
6761
#undef NUMBER_VALUE
6862
#undef STRING_VALUE
6963
#undef OBJECT_VALUE
7064
#undef ROUTINE
71-
#undef ACCESSOR_VALUE
72-
#undef ACCESSOR_RO_VALUE
73-
#undef ACCESSOR_WO_VALUE
65+
#undef ACCESSOR_READ_WRITE
66+
#undef ACCESSOR_READ_ONLY

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313
* limitations under the License.
1414
*/
1515

16-
#include "ecma-alloc.h"
1716
#include "ecma-builtins.h"
18-
#include "ecma-conversion.h"
1917
#include "ecma-exceptions.h"
2018
#include "ecma-gc.h"
2119
#include "ecma-globals.h"
2220
#include "ecma-helpers.h"
23-
#include "ecma-objects.h"
2421
#include "ecma-arraybuffer-object.h"
2522
#include "ecma-try-catch-macro.h"
2623
#include "jrt.h"
2724

2825
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
2926

30-
3127
#define ECMA_BUILTINS_INTERNAL
3228
#include "ecma-builtins-internal.h"
3329

@@ -56,13 +52,13 @@
5652
*/
5753
static ecma_value_t
5854
ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */
59-
ecma_value_t arg) /**< argument 1 */
55+
ecma_value_t arg) /**< argument 1 */
6056
{
6157
JERRY_UNUSED (this_arg);
62-
if (ecma_is_value_object (arg))
63-
{
64-
/* TODO: if arg has [[ViewArrayBuffer]], return true */
65-
}
58+
JERRY_UNUSED (arg);
59+
60+
/* TODO: if arg has [[ViewArrayBuffer]], return true */
61+
6662
return ecma_make_boolean_value (false);
6763
} /* ecma_builtin_arraybuffer_object_is_view */
6864

@@ -77,9 +73,10 @@ ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argu
7773
*/
7874
ecma_value_t
7975
ecma_builtin_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
80-
ecma_length_t arguments_list_len) /**< number of arguments */
76+
ecma_length_t arguments_list_len) /**< number of arguments */
8177
{
8278
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
79+
8380
return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor ArrayBuffer requires 'new'"));
8481
} /* ecma_builtin_arraybuffer_dispatch_call */
8582

@@ -90,7 +87,7 @@ ecma_builtin_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /*
9087
*/
9188
ecma_value_t
9289
ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
93-
ecma_length_t arguments_list_len) /**< number of arguments */
90+
ecma_length_t arguments_list_len) /**< number of arguments */
9491
{
9592
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
9693

@@ -103,5 +100,4 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_
103100
* @}
104101
*/
105102

106-
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
107-
*/
103+
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
5252

5353
/* Routine properties:
5454
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
55-
// ES2015 24.1.3.1
55+
56+
/* ES2015 24.1.3.1 */
5657
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
5758

5859
#undef OBJECT_ID
@@ -61,6 +62,5 @@ ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1
6162
#undef STRING_VALUE
6263
#undef OBJECT_VALUE
6364
#undef ROUTINE
64-
#undef ACCESSOR_VALUE
65-
#undef ACCESSOR_RO_VALUE
66-
#undef ACCESSOR_WO_VALUE
65+
#undef ACCESSOR_READ_WRITE
66+
#undef ACCESSOR_READ_ONLY

jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this
106106
{
107107
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
108108

109-
JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.value));
109+
JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.u.value));
110110

111-
return ext_object_p->u.class_prop.value;
111+
return ext_object_p->u.class_prop.u.value;
112112
}
113113
}
114114

0 commit comments

Comments
 (0)