Skip to content

[ES2015][TypedArray] Add other 8 types #1532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions jerry-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(INCLUDE_CORE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/base"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects/typedarray"
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/operations"
"${CMAKE_CURRENT_SOURCE_DIR}/jcontext"
"${CMAKE_CURRENT_SOURCE_DIR}/jmem"
Expand All @@ -62,22 +63,24 @@ set(INCLUDE_CORE

# Sources
# Jerry core
file(GLOB SOURCE_CORE_API *.c)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.c)
file(GLOB SOURCE_CORE_JCONTEXT jcontext/*.c)
file(GLOB SOURCE_CORE_JMEM jmem/*.c)
file(GLOB SOURCE_CORE_JRT jrt/*.c)
file(GLOB SOURCE_CORE_LIT lit/*.c)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.c)
file(GLOB SOURCE_CORE_PARSER_REGEXP parser/regexp/*.c)
file(GLOB SOURCE_CORE_VM vm/*.c)
file(GLOB SOURCE_CORE_API *.c)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
file(GLOB SOURCE_CORE_ECMA_BUILTINS_TYPEDARRAY ecma/builtin-objects/typedarray/*.c)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.c)
file(GLOB SOURCE_CORE_JCONTEXT jcontext/*.c)
file(GLOB SOURCE_CORE_JMEM jmem/*.c)
file(GLOB SOURCE_CORE_JRT jrt/*.c)
file(GLOB SOURCE_CORE_LIT lit/*.c)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.c)
file(GLOB SOURCE_CORE_PARSER_REGEXP parser/regexp/*.c)
file(GLOB SOURCE_CORE_VM vm/*.c)

set(SOURCE_CORE_FILES
${SOURCE_CORE_API}
${SOURCE_CORE_ECMA_BASE}
${SOURCE_CORE_ECMA_BUILTINS}
${SOURCE_CORE_ECMA_BUILTINS_TYPEDARRAY}
${SOURCE_CORE_ECMA_OPERATIONS}
${SOURCE_CORE_JCONTEXT}
${SOURCE_CORE_JMEM}
Expand Down
35 changes: 35 additions & 0 deletions jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,41 @@ OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
OBJECT_VALUE (LIT_MAGIC_STRING_INT8_ARRAY_UL,
ECMA_BUILTIN_ID_INT8ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_ARRAY_UL,
ECMA_BUILTIN_ID_UINT8ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_INT16_ARRAY_UL,
ECMA_BUILTIN_ID_INT16ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_UINT16_ARRAY_UL,
ECMA_BUILTIN_ID_UINT16ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_INT32_ARRAY_UL,
ECMA_BUILTIN_ID_INT32ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_UINT32_ARRAY_UL,
ECMA_BUILTIN_ID_UINT32ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL,
ECMA_BUILTIN_ID_FLOAT32ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
OBJECT_VALUE (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL,
ECMA_BUILTIN_ID_FLOAT64ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */

OBJECT_VALUE (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL,
ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
Expand Down
8 changes: 3 additions & 5 deletions jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg

/* Building string "[object #type#]" where type is 'Undefined',
'Null' or one of possible object's classes.
The string with null character is maximum 19 characters long. */
const lit_utf8_size_t buffer_size = 19;
JMEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t);
The string with null character is maximum 27 characters long. */
const lit_utf8_size_t buffer_size = 27;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because now the longest class name is Uint8ClampedArray, and 19 is not enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the comment.

lit_utf8_byte_t str_buffer[buffer_size];

lit_utf8_byte_t *buffer_ptr = str_buffer;

Expand All @@ -106,8 +106,6 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg

ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_ptr - str_buffer));

JMEM_FINALIZE_LOCAL_ARRAY (str_buffer);

return ecma_make_string_value (ret_string_p);
} /* ecma_builtin_helper_object_to_string */

Expand Down
114 changes: 114 additions & 0 deletions jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,120 @@ BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY,
true,
int8array)

BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
uint8array_prototype)

BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
uint8array)

BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
int16array_prototype)

BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
int16array)

BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
uint16array_prototype)

BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
uint16array)

BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
int32array_prototype)

BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
int32array)

BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
uint32array_prototype)

BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
uint32array)

BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
float32array_prototype)

BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
float32array)

#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a newline before this # if

BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
float64array_prototype)

BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
float64array)
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */

BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
true,
true,
uint8clampedarray_prototype)

BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_BUILTIN_ID_TYPEDARRAY,
true,
true,
uint8clampedarray)

#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */

/* The Global object (15.1) */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ecma-builtins.h"

#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN

#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"

#define BUILTIN_INC_HEADER_NAME "ecma-builtin-float32array-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID float32array_prototype
#include "ecma-builtin-internal-routines-template.inc.h"

/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup float32arrayprototype ECMA Float32Array.prototype object built-in
* @{
*/

/**
* @}
* @}
* @}
*/

#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Float32Array prototype description
*/
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_attributes)
#endif /* !NUMBER_VALUE */

#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_attributes)
#endif /* !STRING_VALUE */

#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
#endif /* !OBJECT_VALUE */

#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */

/* ES2015 22.2.3.4 */
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
ECMA_BUILTIN_ID_FLOAT32ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)

/* ES2015 22.2.6.1 */
NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U,
4,
ECMA_PROPERTY_FIXED)

#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef ROUTINE
#undef ACCESSOR_READ_WRITE
#undef ACCESSOR_READ_ONLY
Loading