Skip to content

Commit c2bd4ac

Browse files
committedNov 8, 2021
Add custom dispatcher to Arraybuffer & Arraybuffer_prototype
JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag [email protected]
1 parent 8077779 commit c2bd4ac

4 files changed

+104
-31
lines changed
 

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

+55-17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
#define ECMA_BUILTINS_INTERNAL
3333
#include "ecma-builtins-internal.h"
3434

35+
/**
36+
* This object has a custom dispatch function.
37+
*/
38+
#define BUILTIN_CUSTOM_DISPATCH
39+
40+
/**
41+
* List of built-in routine identifiers.
42+
*/
43+
enum
44+
{
45+
ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_ROUTINE_START = 0,
46+
ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER,
47+
ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE,
48+
};
49+
3550
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer-prototype.inc.h"
3651
#define BUILTIN_UNDERSCORED_ID arraybuffer_prototype
3752
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -56,25 +71,18 @@
5671
* Returned value must be freed with ecma_free_value.
5772
*/
5873
static ecma_value_t
59-
ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */
74+
ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg, /**< this argument */
75+
ecma_object_t *object_p) /**< object value*/
6076
{
61-
if (ecma_is_value_object (this_arg))
77+
JERRY_UNUSED (this_arg);
78+
if (ecma_arraybuffer_is_detached (object_p))
6279
{
63-
ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
64-
65-
if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER))
66-
{
67-
if (ecma_arraybuffer_is_detached (object_p))
68-
{
69-
return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached));
70-
}
71-
uint32_t len = ecma_arraybuffer_get_length (object_p);
72-
73-
return ecma_make_uint32_value (len);
74-
}
80+
return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached));
7581
}
82+
uint32_t len = ecma_arraybuffer_get_length (object_p);
83+
84+
return ecma_make_uint32_value (len);
7685

77-
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a ArrayBuffer object"));
7886
} /* ecma_builtin_arraybuffer_prototype_bytelength_getter */
7987

8088
/**
@@ -90,6 +98,22 @@ static ecma_value_t
9098
ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */
9199
const ecma_value_t *argument_list_p, /**< arguments list */
92100
uint32_t arguments_number) /**< number of arguments */
101+
{
102+
return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number);
103+
} /* ecma_builtin_arraybuffer_prototype_object_slice */
104+
105+
/**
106+
* Dispatcher of the built-in's routines
107+
*
108+
* @return ecma value
109+
* Returned value must be freed with ecma_free_value.
110+
*/
111+
ecma_value_t
112+
ecma_builtin_arraybuffer_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in routine identifier */
113+
ecma_value_t this_arg, /**< 'this' argument value */
114+
const ecma_value_t arguments_list_p[], /**< list of arguments
115+
* passed to routine */
116+
uint32_t arguments_number) /**< length of arguments' list */
93117
{
94118
if (!ecma_is_value_object (this_arg))
95119
{
@@ -104,8 +128,22 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
104128
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object"));
105129
}
106130

107-
return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number);
108-
} /* ecma_builtin_arraybuffer_prototype_object_slice */
131+
switch (builtin_routine_id)
132+
{
133+
case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER:
134+
{
135+
return ecma_builtin_arraybuffer_prototype_bytelength_getter (this_arg, object_p);
136+
}
137+
case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE:
138+
{
139+
return ecma_builtin_arraybuffer_prototype_object_slice (this_arg, arguments_list_p, arguments_number);
140+
}
141+
default:
142+
{
143+
JERRY_UNREACHABLE ();
144+
}
145+
}
146+
} /* ecma_builtin_arraybuffer_prototype_dispatch_routine */
109147

110148
/**
111149
* @}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, ECMA_BUILTIN_ID_ARRAYBUFFER, ECMA_PR
2828

2929
/* Readonly accessor properties */
3030
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
31-
ecma_builtin_arraybuffer_prototype_bytelength_getter,
31+
ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER,
3232
ECMA_PROPERTY_FLAG_CONFIGURABLE)
3333

3434
/* ECMA-262 v6, 24.1.4.4 */
3535
STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG, LIT_MAGIC_STRING_ARRAY_BUFFER_UL, ECMA_PROPERTY_FLAG_CONFIGURABLE)
3636

3737
/* Routine properties:
3838
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
39-
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, NON_FIXED, 2)
39+
ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE, NON_FIXED, 2)
4040

4141
#endif /* JERRY_BUILTIN_TYPEDARRAY */
4242

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

+43-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@
2929
#define ECMA_BUILTINS_INTERNAL
3030
#include "ecma-builtins-internal.h"
3131

32+
/**
33+
* This object has a custom dispatch function.
34+
*/
35+
#define BUILTIN_CUSTOM_DISPATCH
36+
37+
/**
38+
* List of built-in routine identifiers.
39+
*/
40+
enum
41+
{
42+
ECMA_BUILTIN_ARRAYBUFFER_ROUTINE_START = 0,
43+
ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW,
44+
ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET,
45+
};
46+
3247
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h"
3348
#define BUILTIN_UNDERSCORED_ID arraybuffer
3449
#include "ecma-builtin-internal-routines-template.inc.h"
@@ -53,11 +68,8 @@
5368
* Returned value must be freed with ecma_free_value.
5469
*/
5570
static ecma_value_t
56-
ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */
57-
ecma_value_t arg) /**< argument 1 */
71+
ecma_builtin_arraybuffer_object_is_view (ecma_value_t arg) /**< argument 1 */
5872
{
59-
JERRY_UNUSED (this_arg);
60-
6173
return ecma_make_boolean_value (ecma_is_typedarray (arg) || ecma_is_dataview (arg));
6274
} /* ecma_builtin_arraybuffer_object_is_view */
6375

@@ -94,16 +106,37 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_
94106
} /* ecma_builtin_arraybuffer_dispatch_construct */
95107

96108
/**
97-
* 24.1.3.3 get ArrayBuffer [ @@species ] accessor
109+
* Dispatcher of the built-in's routines
98110
*
99-
* @return ecma_value
100-
* returned value must be freed with ecma_free_value
111+
* @return ecma value
112+
* Returned value must be freed with ecma_free_value.
101113
*/
102114
ecma_value_t
103-
ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */
115+
ecma_builtin_arraybuffer_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */
116+
ecma_value_t this_arg, /**< 'this' argument value */
117+
const ecma_value_t arguments_list_p[], /**< list of arguments
118+
* passed to routine */
119+
uint32_t arguments_number) /**< length of arguments' list */
104120
{
105-
return ecma_copy_value (this_value);
106-
} /* ecma_builtin_arraybuffer_species_get */
121+
JERRY_UNUSED (arguments_number);
122+
123+
switch (builtin_routine_id)
124+
{
125+
case ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW:
126+
{
127+
ecma_value_t argument = arguments_number > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
128+
return ecma_builtin_arraybuffer_object_is_view (argument);
129+
}
130+
case ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET:
131+
{
132+
return ecma_copy_value (this_arg);
133+
}
134+
default:
135+
{
136+
JERRY_UNREACHABLE ();
137+
}
138+
}
139+
} /* ecma_builtin_arraybuffer_dispatch_routine */
107140

108141
/**
109142
* @}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME, LIT_MAGIC_STRING_ARRAY_BUFFER_UL, ECMA_PROP
3737
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
3838

3939
/* ES2015 24.1.3.1 */
40-
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
40+
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW, 1, 1)
4141

4242
/* ES2015 24.1.3.3 */
43-
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES, ecma_builtin_arraybuffer_species_get, ECMA_PROPERTY_FLAG_CONFIGURABLE)
43+
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
44+
ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET,
45+
ECMA_PROPERTY_FLAG_CONFIGURABLE)
4446

4547
#endif /* JERRY_BUILTIN_TYPEDARRAY */
4648

0 commit comments

Comments
 (0)
Please sign in to comment.