Skip to content

Commit a317755

Browse files
committed
[ES2015][TypedArray] add other 8 types
add Uint8Array, Int16Array Uint16Array, ... JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang [email protected]
1 parent ec14622 commit a317755

File tree

58 files changed

+2646
-29
lines changed

Some content is hidden

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

58 files changed

+2646
-29
lines changed

jerry-core/CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(INCLUDE_CORE
5151
"${CMAKE_CURRENT_SOURCE_DIR}"
5252
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/base"
5353
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects"
54+
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects/typedarray"
5455
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/operations"
5556
"${CMAKE_CURRENT_SOURCE_DIR}/jcontext"
5657
"${CMAKE_CURRENT_SOURCE_DIR}/jmem"
@@ -62,22 +63,24 @@ set(INCLUDE_CORE
6263

6364
# Sources
6465
# Jerry core
65-
file(GLOB SOURCE_CORE_API *.c)
66-
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
67-
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
68-
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.c)
69-
file(GLOB SOURCE_CORE_JCONTEXT jcontext/*.c)
70-
file(GLOB SOURCE_CORE_JMEM jmem/*.c)
71-
file(GLOB SOURCE_CORE_JRT jrt/*.c)
72-
file(GLOB SOURCE_CORE_LIT lit/*.c)
73-
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.c)
74-
file(GLOB SOURCE_CORE_PARSER_REGEXP parser/regexp/*.c)
75-
file(GLOB SOURCE_CORE_VM vm/*.c)
66+
file(GLOB SOURCE_CORE_API *.c)
67+
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
68+
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
69+
file(GLOB SOURCE_CORE_ECMA_BUILTINS_TYPEDARRAY ecma/builtin-objects/typedarray/*.c)
70+
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.c)
71+
file(GLOB SOURCE_CORE_JCONTEXT jcontext/*.c)
72+
file(GLOB SOURCE_CORE_JMEM jmem/*.c)
73+
file(GLOB SOURCE_CORE_JRT jrt/*.c)
74+
file(GLOB SOURCE_CORE_LIT lit/*.c)
75+
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.c)
76+
file(GLOB SOURCE_CORE_PARSER_REGEXP parser/regexp/*.c)
77+
file(GLOB SOURCE_CORE_VM vm/*.c)
7678

7779
set(SOURCE_CORE_FILES
7880
${SOURCE_CORE_API}
7981
${SOURCE_CORE_ECMA_BASE}
8082
${SOURCE_CORE_ECMA_BUILTINS}
83+
${SOURCE_CORE_ECMA_BUILTINS_TYPEDARRAY}
8184
${SOURCE_CORE_ECMA_OPERATIONS}
8285
${SOURCE_CORE_JCONTEXT}
8386
${SOURCE_CORE_JMEM}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,39 @@ OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
170170
OBJECT_VALUE (LIT_MAGIC_STRING_INT8_ARRAY_UL,
171171
ECMA_BUILTIN_ID_INT8ARRAY,
172172
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
173+
174+
OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_ARRAY_UL,
175+
ECMA_BUILTIN_ID_UINT8ARRAY,
176+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
177+
178+
OBJECT_VALUE (LIT_MAGIC_STRING_INT16_ARRAY_UL,
179+
ECMA_BUILTIN_ID_INT16ARRAY,
180+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
181+
182+
OBJECT_VALUE (LIT_MAGIC_STRING_UINT16_ARRAY_UL,
183+
ECMA_BUILTIN_ID_UINT16ARRAY,
184+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
185+
186+
OBJECT_VALUE (LIT_MAGIC_STRING_INT32_ARRAY_UL,
187+
ECMA_BUILTIN_ID_INT32ARRAY,
188+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
189+
190+
OBJECT_VALUE (LIT_MAGIC_STRING_UINT32_ARRAY_UL,
191+
ECMA_BUILTIN_ID_UINT32ARRAY,
192+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
193+
194+
OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL,
195+
ECMA_BUILTIN_ID_FLOAT32ARRAY,
196+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
197+
198+
OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL,
199+
ECMA_BUILTIN_ID_FLOAT64ARRAY,
200+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
201+
202+
OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL,
203+
ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
204+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
205+
173206
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
174207
/* Routine properties:
175208
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
8282

8383
/* Building string "[object #type#]" where type is 'Undefined',
8484
'Null' or one of possible object's classes.
85-
The string with null character is maximum 19 characters long. */
86-
const lit_utf8_size_t buffer_size = 19;
85+
The string with null character is maximum 27 characters long. */
86+
const lit_utf8_size_t buffer_size = 27;
8787
JMEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t);
8888

8989
lit_utf8_byte_t *buffer_ptr = str_buffer;

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,118 @@ BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY,
349349
true,
350350
int8array)
351351

352+
BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE,
353+
ECMA_OBJECT_TYPE_GENERAL,
354+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
355+
true,
356+
true,
357+
uint8array_prototype)
358+
359+
BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY,
360+
ECMA_OBJECT_TYPE_FUNCTION,
361+
ECMA_BUILTIN_ID_TYPEDARRAY,
362+
true,
363+
true,
364+
uint8array)
365+
366+
BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE,
367+
ECMA_OBJECT_TYPE_GENERAL,
368+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
369+
true,
370+
true,
371+
int16array_prototype)
372+
373+
BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY,
374+
ECMA_OBJECT_TYPE_FUNCTION,
375+
ECMA_BUILTIN_ID_TYPEDARRAY,
376+
true,
377+
true,
378+
int16array)
379+
380+
BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE,
381+
ECMA_OBJECT_TYPE_GENERAL,
382+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
383+
true,
384+
true,
385+
uint16array_prototype)
386+
387+
BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY,
388+
ECMA_OBJECT_TYPE_FUNCTION,
389+
ECMA_BUILTIN_ID_TYPEDARRAY,
390+
true,
391+
true,
392+
uint16array)
393+
394+
BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE,
395+
ECMA_OBJECT_TYPE_GENERAL,
396+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
397+
true,
398+
true,
399+
int32array_prototype)
400+
401+
BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY,
402+
ECMA_OBJECT_TYPE_FUNCTION,
403+
ECMA_BUILTIN_ID_TYPEDARRAY,
404+
true,
405+
true,
406+
int32array)
407+
408+
BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE,
409+
ECMA_OBJECT_TYPE_GENERAL,
410+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
411+
true,
412+
true,
413+
uint32array_prototype)
414+
415+
BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY,
416+
ECMA_OBJECT_TYPE_FUNCTION,
417+
ECMA_BUILTIN_ID_TYPEDARRAY,
418+
true,
419+
true,
420+
uint32array)
421+
422+
BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE,
423+
ECMA_OBJECT_TYPE_GENERAL,
424+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
425+
true,
426+
true,
427+
float32array_prototype)
428+
429+
BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY,
430+
ECMA_OBJECT_TYPE_FUNCTION,
431+
ECMA_BUILTIN_ID_TYPEDARRAY,
432+
true,
433+
true,
434+
float32array)
435+
436+
BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE,
437+
ECMA_OBJECT_TYPE_GENERAL,
438+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
439+
true,
440+
true,
441+
float64array_prototype)
442+
443+
BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY,
444+
ECMA_OBJECT_TYPE_FUNCTION,
445+
ECMA_BUILTIN_ID_TYPEDARRAY,
446+
true,
447+
true,
448+
float64array)
449+
450+
BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE,
451+
ECMA_OBJECT_TYPE_GENERAL,
452+
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
453+
true,
454+
true,
455+
uint8clampedarray_prototype)
456+
457+
BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
458+
ECMA_OBJECT_TYPE_FUNCTION,
459+
ECMA_BUILTIN_ID_TYPEDARRAY,
460+
true,
461+
true,
462+
uint8clampedarray)
463+
352464
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
353465

354466
/* The Global object (15.1) */
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "ecma-builtins.h"
17+
18+
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
19+
20+
#define ECMA_BUILTINS_INTERNAL
21+
#include "ecma-builtins-internal.h"
22+
23+
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float32array-prototype.inc.h"
24+
#define BUILTIN_UNDERSCORED_ID float32array_prototype
25+
#include "ecma-builtin-internal-routines-template.inc.h"
26+
27+
/** \addtogroup ecma ECMA
28+
* @{
29+
*
30+
* \addtogroup ecmabuiltins
31+
* @{
32+
*
33+
* \addtogroup float32array prototype ECMA Float32Array.prototype object built-in
34+
* @{
35+
*/
36+
37+
/**
38+
* @}
39+
* @}
40+
* @}
41+
*/
42+
43+
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/*
17+
* Float32Array prototype description
18+
*/
19+
#ifndef NUMBER_VALUE
20+
# define NUMBER_VALUE(name, number_value, prop_attributes)
21+
#endif /* !NUMBER_VALUE */
22+
23+
#ifndef STRING_VALUE
24+
# define STRING_VALUE(name, magic_string_id, prop_attributes)
25+
#endif /* !STRING_VALUE */
26+
27+
#ifndef OBJECT_VALUE
28+
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
29+
#endif /* !OBJECT_VALUE */
30+
31+
#ifndef ROUTINE
32+
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
33+
#endif /* !ROUTINE */
34+
35+
/* ES2015 22.2.3.4 */
36+
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
37+
ECMA_BUILTIN_ID_FLOAT32ARRAY,
38+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
39+
40+
/* ES2015 22.2.6.1 */
41+
NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U,
42+
4,
43+
ECMA_PROPERTY_FIXED)
44+
45+
#undef SIMPLE_VALUE
46+
#undef NUMBER_VALUE
47+
#undef STRING_VALUE
48+
#undef OBJECT_VALUE
49+
#undef ROUTINE
50+
#undef ACCESSOR_READ_WRITE
51+
#undef ACCESSOR_READ_ONLY
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* Copyright JS Foundation and other contributors, http://js.foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "ecma-builtins.h"
17+
#include "ecma-exceptions.h"
18+
#include "ecma-gc.h"
19+
#include "ecma-globals.h"
20+
#include "ecma-helpers.h"
21+
#include "ecma-typedarray-object.h"
22+
#include "jrt.h"
23+
24+
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
25+
26+
#define ECMA_BUILTINS_INTERNAL
27+
#include "ecma-builtins-internal.h"
28+
29+
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float32array.inc.h"
30+
#define BUILTIN_UNDERSCORED_ID float32array
31+
#include "ecma-builtin-internal-routines-template.inc.h"
32+
33+
/** \addtogroup ecma ECMA
34+
* @{
35+
*
36+
* \addtogroup ecmabuiltins
37+
* @{
38+
*
39+
* \addtogroup string ECMA Float32Array object built-in
40+
* @{
41+
*/
42+
43+
/**
44+
* Handle calling [[Call]] of Float32Array
45+
*
46+
* @return ecma value
47+
*/
48+
ecma_value_t
49+
ecma_builtin_float32array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
50+
ecma_length_t arguments_list_len) /**< number of arguments */
51+
{
52+
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
53+
54+
return ecma_raise_type_error (ECMA_ERR_MSG ("Float32Array cannot be directly called"));
55+
} /* ecma_builtin_float32array_dispatch_call */
56+
57+
/**
58+
* Handle calling [[Construct]] of Float32Array
59+
*
60+
* @return ecma value
61+
*/
62+
ecma_value_t
63+
ecma_builtin_float32array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
64+
ecma_length_t arguments_list_len) /**< number of arguments */
65+
{
66+
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
67+
68+
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE);
69+
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
70+
arguments_list_len,
71+
prototype_obj_p,
72+
2,
73+
LIT_MAGIC_STRING_FLOAT32_ARRAY_UL);
74+
75+
ecma_deref_object (prototype_obj_p);
76+
77+
return val;
78+
} /* ecma_builtin_float32array_dispatch_construct */
79+
80+
/**
81+
* @}
82+
* @}
83+
* @}
84+
*/
85+
86+
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */

0 commit comments

Comments
 (0)