Skip to content

Commit 2f4fba5

Browse files
committed
Add custom dispatcher to Arraybuffer & Arraybuffer_prototype
JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag [email protected]
1 parent ef35c03 commit 2f4fba5

File tree

4 files changed

+91
-10
lines changed

4 files changed

+91
-10
lines changed

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

+45
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"
@@ -227,6 +242,36 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
227242
return ret_value;
228243
} /* ecma_builtin_arraybuffer_prototype_object_slice */
229244

245+
/**
246+
* Dispatcher of the built-in's routines
247+
*
248+
* @return ecma value
249+
* Returned value must be freed with ecma_free_value.
250+
*/
251+
ecma_value_t
252+
ecma_builtin_arraybuffer_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in routine identifier */
253+
ecma_value_t this_arg, /**< 'this' argument value */
254+
const ecma_value_t arguments_list_p[], /**< list of arguments
255+
* passed to routine */
256+
uint32_t arguments_number) /**< length of arguments' list */
257+
{
258+
switch (builtin_routine_id)
259+
{
260+
case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_BYTELENGTH_GETTER:
261+
{
262+
return ecma_builtin_arraybuffer_prototype_bytelength_getter (this_arg);
263+
}
264+
case ECMA_BUILTIN_ARRAYBUFFER_PROTOTYPE_OBJECT_SLICE:
265+
{
266+
return ecma_builtin_arraybuffer_prototype_object_slice (this_arg, arguments_list_p, arguments_number);
267+
}
268+
default:
269+
{
270+
JERRY_UNREACHABLE ();
271+
}
272+
}
273+
} /* ecma_builtin_arraybuffer_prototype_dispatch_routine */
274+
230275
/**
231276
* @}
232277
* @}

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

+42-6
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"
@@ -93,16 +108,37 @@ ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_
93108
} /* ecma_builtin_arraybuffer_dispatch_construct */
94109

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

107143
/**
108144
* @}

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)