Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ada526

Browse files
committedOct 27, 2021
Add custom dispatcher to Arraybuffer & Arraybuffer_prototype
JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag [email protected]
1 parent 499cdea commit 0ada526

4 files changed

+102
-31
lines changed
 

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

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

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

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

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

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

109147
/**
110148
* @}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
3030

3131
/* Readonly accessor properties */
3232
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
33-
ecma_builtin_arraybuffer_prototype_bytelength_getter,
33+
ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER,
3434
ECMA_PROPERTY_FLAG_CONFIGURABLE)
3535

3636
/* ECMA-262 v6, 24.1.4.4 */
@@ -40,7 +40,7 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
4040

4141
/* Routine properties:
4242
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
43-
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, NON_FIXED, 2)
43+
ROUTINE (LIT_MAGIC_STRING_SLICE, ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE, NON_FIXED, 2)
4444

4545
#endif /* JERRY_BUILTIN_TYPEDARRAY */
4646

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

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

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

@@ -93,16 +105,37 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_
93105
} /* ecma_builtin_arraybuffer_dispatch_construct */
94106

95107
/**
96-
* 24.1.3.3 get ArrayBuffer [ @@species ] accessor
108+
* Dispatcher of the built-in's routines
97109
*
98-
* @return ecma_value
99-
* returned value must be freed with ecma_free_value
110+
* @return ecma value
111+
* Returned value must be freed with ecma_free_value.
100112
*/
101113
ecma_value_t
102-
ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */
114+
ecma_builtin_arraybuffer_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine identifier */
115+
ecma_value_t this_arg, /**< 'this' argument value */
116+
const ecma_value_t arguments_list_p[], /**< list of arguments
117+
* passed to routine */
118+
uint32_t arguments_number) /**< length of arguments' list */
103119
{
104-
return ecma_copy_value (this_value);
105-
} /* ecma_builtin_arraybuffer_species_get */
120+
JERRY_UNUSED (arguments_number);
121+
122+
switch (builtin_routine_id)
123+
{
124+
case ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW:
125+
{
126+
ecma_value_t argument = arguments_number > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
127+
return ecma_builtin_arraybuffer_object_is_view (argument);
128+
}
129+
case ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET:
130+
{
131+
return ecma_copy_value (this_arg);
132+
}
133+
default:
134+
{
135+
JERRY_UNREACHABLE ();
136+
}
137+
}
138+
} /* ecma_builtin_arraybuffer_dispatch_routine */
106139

107140
/**
108141
* @}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ STRING_VALUE (LIT_MAGIC_STRING_NAME,
4343
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
4444

4545
/* ES2015 24.1.3.1 */
46-
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
46+
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ECMA_BUILTIN_ARRAYBUFFER_OBJECT_IS_VIEW, 1, 1)
4747

4848
/* ES2015 24.1.3.3 */
4949
ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
50-
ecma_builtin_arraybuffer_species_get,
50+
ECMA_BUILTIN_ARRAYBUFFER_SPECIES_GET,
5151
ECMA_PROPERTY_FLAG_CONFIGURABLE)
5252

5353
#endif /* JERRY_BUILTIN_TYPEDARRAY */

0 commit comments

Comments
 (0)
Please sign in to comment.