mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
[ES2015 profile]add TypedArray intrinsic object (#1507)
* add %TypedArray% intrinsic object * implement Int8Array * will implement other types and prototype functions in the following patches. JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
parent
177c30de78
commit
adfe61b4ed
@ -31,6 +31,10 @@
|
||||
#include "vm-defines.h"
|
||||
#include "vm-stack.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
|
||||
#include "ecma-typedarray-object.h"
|
||||
#endif
|
||||
|
||||
#define JERRY_INTERNAL
|
||||
#include "jerry-internal.h"
|
||||
|
||||
@ -259,14 +263,35 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
|
||||
switch (ecma_get_object_type (object_p))
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.arguments.lex_env_cp);
|
||||
switch (ext_object_p->u.pseudo_array.type)
|
||||
{
|
||||
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
|
||||
{
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.pseudo_array.u2.lex_env_cp);
|
||||
|
||||
ecma_gc_set_object_visited (lex_env_p, true);
|
||||
break;
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
|
||||
{
|
||||
ecma_gc_set_object_visited (ecma_typedarray_get_arraybuffer (object_p), true);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_gc_set_object_visited (lex_env_p, true);
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
@ -503,25 +528,52 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
|
||||
return;
|
||||
}
|
||||
|
||||
if (object_type == ECMA_OBJECT_TYPE_ARGUMENTS)
|
||||
if (object_type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
ecma_length_t formal_params_number = ext_object_p->u.arguments.length;
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
for (ecma_length_t i = 0; i < formal_params_number; i++)
|
||||
switch (ext_object_p->u.pseudo_array.type)
|
||||
{
|
||||
if (arg_Literal_p[i] != JMEM_CP_NULL)
|
||||
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
|
||||
{
|
||||
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
|
||||
ecma_deref_ecma_string (name_p);
|
||||
ecma_length_t formal_params_number = ext_object_p->u.pseudo_array.u1.length;
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
for (ecma_length_t i = 0; i < formal_params_number; i++)
|
||||
{
|
||||
if (arg_Literal_p[i] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
}
|
||||
|
||||
size_t formal_params_size = formal_params_number * sizeof (jmem_cpointer_t);
|
||||
ecma_dealloc_extended_object (ext_object_p, sizeof (ecma_extended_object_t) + formal_params_size);
|
||||
return;
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
|
||||
{
|
||||
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p,
|
||||
sizeof (ecma_extended_object_t));
|
||||
return;
|
||||
}
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
|
||||
{
|
||||
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p,
|
||||
sizeof (ecma_extended_typedarray_object_t));
|
||||
return;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size_t formal_params_size = formal_params_number * sizeof (jmem_cpointer_t);
|
||||
ecma_dealloc_extended_object (ext_object_p, sizeof (ecma_extended_object_t) + formal_params_size);
|
||||
return;
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
if (object_type == ECMA_OBJECT_TYPE_BOUND_FUNCTION)
|
||||
|
||||
@ -291,6 +291,11 @@ typedef enum
|
||||
*/
|
||||
#define ECMA_PROPERTY_TYPE_NOT_FOUND ECMA_PROPERTY_TYPE_DELETED
|
||||
|
||||
/**
|
||||
* Type of property not found and no more searching in the proto chain.
|
||||
*/
|
||||
#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_HASHMAP
|
||||
|
||||
/**
|
||||
* Property flag list (for ECMA_PROPERTY_TYPE_NAMEDDATA
|
||||
* and ECMA_PROPERTY_TYPE_NAMEDACCESSOR).
|
||||
@ -321,6 +326,12 @@ typedef enum
|
||||
#define ECMA_PROPERTY_CONFIGURABLE_WRITABLE \
|
||||
(ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
/**
|
||||
* Property flags enumerable, writable.
|
||||
*/
|
||||
#define ECMA_PROPERTY_ENUMERABLE_WRITABLE \
|
||||
(ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
/**
|
||||
* No attributes can be changed for this property.
|
||||
*/
|
||||
@ -488,7 +499,7 @@ typedef struct
|
||||
} ecma_extended_property_ref_t;
|
||||
|
||||
/**
|
||||
* Option flags for ecma_op_object_get_property
|
||||
* Option flags for ecma_op_object_get_property.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@ -498,7 +509,7 @@ typedef enum
|
||||
} ecma_property_get_option_bits_t;
|
||||
|
||||
/**
|
||||
* Internal object types
|
||||
* Internal object types.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@ -509,13 +520,25 @@ typedef enum
|
||||
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION = 3, /**< External (host) function object */
|
||||
ECMA_OBJECT_TYPE_ARRAY = 4, /**< Array object (15.4) */
|
||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 5, /**< Function objects (15.3), created through 15.3.4.5 routine */
|
||||
ECMA_OBJECT_TYPE_ARGUMENTS = 6, /**< Arguments object (10.6) */
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY = 6, /**< Array-like object, such as Arguments object (10.6) */
|
||||
|
||||
ECMA_OBJECT_TYPE__MAX = ECMA_OBJECT_TYPE_ARGUMENTS /**< maximum value */
|
||||
ECMA_OBJECT_TYPE__MAX = ECMA_OBJECT_TYPE_PSEUDO_ARRAY /**< maximum value */
|
||||
} ecma_object_type_t;
|
||||
|
||||
/**
|
||||
* Types of lexical environments
|
||||
* Types of objects with class property.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PSEUDO_ARRAY_ARGUMENTS = 0, /**< Arguments object (10.6) */
|
||||
ECMA_PSEUDO_ARRAY_TYPEDARRAY = 1, /**< TypedArray which does NOT need extra space to store length and offset */
|
||||
ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO = 2, /**< TypedArray which NEEDS extra space to store length and offset */
|
||||
|
||||
ECMA_PSEUDO_ARRAY__MAX = ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO /**< maximum value */
|
||||
} ecma_pseudo_array_type_t;
|
||||
|
||||
/**
|
||||
* Types of lexical environments.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@ -629,13 +652,14 @@ typedef struct
|
||||
struct
|
||||
{
|
||||
uint16_t class_id; /**< class id of the object */
|
||||
|
||||
/*
|
||||
* Description of extra fields. These extra fields depends on the class_id.
|
||||
*/
|
||||
union
|
||||
{
|
||||
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
|
||||
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
|
||||
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
|
||||
} u;
|
||||
} class_prop;
|
||||
|
||||
@ -658,13 +682,24 @@ typedef struct
|
||||
} array;
|
||||
|
||||
/*
|
||||
* Description of arguments objects.
|
||||
* Description of pseudo array objects.
|
||||
*/
|
||||
struct
|
||||
{
|
||||
ecma_value_t lex_env_cp; /**< lexical environment */
|
||||
uint32_t length; /**< length of names */
|
||||
} arguments;
|
||||
uint8_t type; /**< pseudo array type, e.g. Arguments, TypedArray*/
|
||||
uint8_t extra_info; /**< extra infomations about the object.
|
||||
* e.g. element_width_shift for typed arrays */
|
||||
union
|
||||
{
|
||||
uint16_t length; /**< for arguments: length of names */
|
||||
uint16_t class_id; /**< for typedarray: the specific class name */
|
||||
} u1;
|
||||
union
|
||||
{
|
||||
ecma_value_t lex_env_cp; /**< for arguments: lexical environment */
|
||||
ecma_value_t arraybuffer; /**< for typedarray: internal arraybuffer */
|
||||
} u2;
|
||||
} pseudo_array;
|
||||
|
||||
/*
|
||||
* Description of bound function object.
|
||||
@ -1121,6 +1156,21 @@ typedef struct
|
||||
|
||||
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
/**
|
||||
* Some internal properties of TypedArray object.
|
||||
* It is only used when the offset is not 0, and
|
||||
* the array-length is not buffer-length / element_size.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecma_extended_object_t extended_object; /**< extended object part */
|
||||
ecma_length_t byte_offset; /**< the byteoffset of the above arraybuffer */
|
||||
ecma_length_t array_length; /**< the array length */
|
||||
} ecma_extended_typedarray_object_t;
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -174,6 +174,11 @@ OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_INT8_ARRAY_UL,
|
||||
ECMA_BUILTIN_ID_INT8ARRAY,
|
||||
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) */
|
||||
|
||||
|
||||
@ -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-int8array-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID int8array_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup int8array prototype ECMA Int8Array.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
@ -0,0 +1,60 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Int8Array prototype description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#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 */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE)
|
||||
|
||||
/* ES2015 22.2.3.4 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_INT8ARRAY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* ES2015 22.2.6.1 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
#undef ACCESSOR_READ_WRITE
|
||||
#undef ACCESSOR_READ_ONLY
|
||||
86
jerry-core/ecma/builtin-objects/ecma-builtin-int8array.c
Normal file
86
jerry-core/ecma/builtin-objects/ecma-builtin-int8array.c
Normal file
@ -0,0 +1,86 @@
|
||||
/* 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"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-int8array.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID int8array
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup string ECMA Int8Array object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of Int8Array
|
||||
*
|
||||
* ES2015 22.2.4 The TypedArray constructors are not intended
|
||||
* to be called as a function and will throw an exception when called in that manner.
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_int8array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Int8Array cannot be directly called"));
|
||||
} /* ecma_builtin_int8array_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in %TypedArray% object
|
||||
*
|
||||
* ES2015 22.2.1 If %TypedArray% is directly called or
|
||||
* called as part of a new expression an exception is thrown
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_int8array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE);
|
||||
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
|
||||
arguments_list_len,
|
||||
prototype_obj_p,
|
||||
0,
|
||||
LIT_MAGIC_STRING_INT8_ARRAY_UL);
|
||||
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
return val;
|
||||
} /* ecma_builtin_int8array_dispatch_construct */
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
76
jerry-core/ecma/builtin-objects/ecma-builtin-int8array.inc.h
Normal file
76
jerry-core/ecma/builtin-objects/ecma-builtin-int8array.inc.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Int8Array description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#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 */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_INT8ARRAY)
|
||||
|
||||
|
||||
/* ES2015 22.2.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5.1 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_INT8_ARRAY_UL,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.5.2 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
#undef ACCESSOR_READ_WRITE
|
||||
#undef ACCESSOR_READ_ONLY
|
||||
@ -240,7 +240,7 @@ ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this_a
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
|
||||
/* 4. */
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
bool is_enumerable = ecma_is_property_enumerable (property);
|
||||
|
||||
|
||||
@ -0,0 +1,144 @@
|
||||
/* 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-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "ecma-gc.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typedarray-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID typedarray_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup typedarray prototype ECMA %TypedArray%.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The %TypedArray%.prototype.buffer accessor
|
||||
*
|
||||
* See also:
|
||||
* ES2015, 22.2.3.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_prototype_buffer_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_typedarray (this_arg))
|
||||
{
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_object_t *obj_p = ecma_typedarray_get_arraybuffer (typedarray_p);
|
||||
ecma_ref_object (obj_p);
|
||||
|
||||
return ecma_make_object_value (obj_p);
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
|
||||
} /* ecma_builtin_typedarray_prototype_buffer_getter */
|
||||
|
||||
/**
|
||||
* The %TypedArray%.prototype.byteLength accessor
|
||||
*
|
||||
* See also:
|
||||
* ES2015, 22.2.3.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_typedarray (this_arg))
|
||||
{
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
|
||||
return ecma_make_uint32_value (ecma_typedarray_get_length (typedarray_p) << shift);
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
|
||||
} /* ecma_builtin_typedarray_prototype_bytelength_getter */
|
||||
|
||||
/**
|
||||
* The %TypedArray%.prototype.byteOffset accessor
|
||||
*
|
||||
* See also:
|
||||
* ES2015, 22.2.3.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_prototype_byteoffset_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_typedarray (this_arg))
|
||||
{
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
return ecma_make_uint32_value (ecma_typedarray_get_offset (typedarray_p));
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
|
||||
} /* ecma_builtin_typedarray_prototype_byteoffset_getter */
|
||||
|
||||
/**
|
||||
* The %TypedArray%.prototype.length accessor
|
||||
*
|
||||
* See also:
|
||||
* ES2015, 22.2.3.17
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_prototype_length_getter (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_typedarray (this_arg))
|
||||
{
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
return ecma_make_uint32_value (ecma_typedarray_get_length (typedarray_p));
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a TypedArray."));
|
||||
} /* ecma_builtin_typedarray_prototype_length_getter */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
@ -0,0 +1,73 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %TypedArrayPrototype% description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#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 */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE)
|
||||
|
||||
/* ES2015 22.2.3.4 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Readonly accessor properties */
|
||||
/* ES2015 22.2.3.1 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BUFFER,
|
||||
ecma_builtin_typedarray_prototype_buffer_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
/* ES2015 22.2.3.2 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
|
||||
ecma_builtin_typedarray_prototype_bytelength_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
/* ES2015 22.2.3.3 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_OFFSET_UL,
|
||||
ecma_builtin_typedarray_prototype_byteoffset_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.3.17 */
|
||||
ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_LENGTH,
|
||||
ecma_builtin_typedarray_prototype_length_getter,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
#undef ACCESSOR_READ_WRITE
|
||||
#undef ACCESSOR_READ_ONLY
|
||||
124
jerry-core/ecma/builtin-objects/ecma-builtin-typedarray.c
Normal file
124
jerry-core/ecma/builtin-objects/ecma-builtin-typedarray.c
Normal file
@ -0,0 +1,124 @@
|
||||
/* 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"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typedarray.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID typedarray
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup string ECMA %TypedArray% object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The %TypedArray%.from routine
|
||||
*
|
||||
* See also:
|
||||
* ES2015 22.2.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_from (ecma_value_t this_arg, /**< 'this' argument */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
JERRY_UNUSED (arguments_list_p);
|
||||
JERRY_UNUSED (arguments_list_len);
|
||||
|
||||
/* TODO: inplement 'from' */
|
||||
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
} /* ecma_builtin_typedarray_from */
|
||||
|
||||
/**
|
||||
* The %TypedArray%.of routine
|
||||
*
|
||||
* See also:
|
||||
* ES2015 22.2.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_typedarray_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
JERRY_UNUSED (arguments_list_p);
|
||||
JERRY_UNUSED (arguments_list_len);
|
||||
|
||||
/* TODO: inplement 'of' */
|
||||
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
} /* ecma_builtin_typedarray_of */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in %TypedArray% object
|
||||
*
|
||||
* ES2015 22.2.1 If %TypedArray% is directly called or
|
||||
* called as part of a new expression an exception is thrown
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_typedarray_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("TypedArray intrinstic cannot be directly called"));
|
||||
} /* ecma_builtin_typedarray_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in %TypedArray% object
|
||||
*
|
||||
* ES2015 22.2.1 If %TypedArray% is directly called or
|
||||
* called as part of a new expression an exception is thrown
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_typedarray_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("TypedArray intrinstic cannot be called by a 'new' expression"));
|
||||
} /* ecma_builtin_typedarray_dispatch_construct */
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
@ -0,0 +1,75 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %TypedArray% description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#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 */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_TYPEDARRAY)
|
||||
|
||||
|
||||
/* ES2015 22.2.2 */
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
3,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.2 */
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_TYPED_ARRAY_UL,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* ES2015 22.2.2.3 */
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
/* ES2015 22.2.2.1 */
|
||||
ROUTINE (LIT_MAGIC_STRING_FROM, ecma_builtin_typedarray_from, NON_FIXED, 1)
|
||||
|
||||
/* ES2015 22.2.2.2 */
|
||||
ROUTINE (LIT_MAGIC_STRING_OF, ecma_builtin_typedarray_of, NON_FIXED, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
#undef ACCESSOR_READ_WRITE
|
||||
#undef ACCESSOR_READ_ONLY
|
||||
@ -317,6 +317,40 @@ BUILTIN (ECMA_BUILTIN_ID_ARRAYBUFFER,
|
||||
arraybuffer)
|
||||
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
/* The %TypedArrayPrototype% object (ES2015 24.2.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
typedarray_prototype)
|
||||
|
||||
/* The %TypedArray% intrinsic object (ES2015 22.2.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
typedarray)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
int8array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
true,
|
||||
int8array)
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
|
||||
/* The Global object (15.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_GLOBAL,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
|
||||
@ -81,8 +81,7 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li
|
||||
* extend_part
|
||||
* data buffer
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value
|
||||
* @return ecma_object_t *
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffer */
|
||||
@ -95,9 +94,60 @@ ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffe
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_ARRAY_BUFFER_UL;
|
||||
ext_object_p->u.class_prop.u.length = length;
|
||||
|
||||
lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);
|
||||
memset (buf, 0, length);
|
||||
|
||||
return object_p;
|
||||
} /* ecma_arraybuffer_new_object */
|
||||
|
||||
/**
|
||||
* Helper function: create arraybuffer object by cloning another arraybuffer
|
||||
*
|
||||
* See also: ES2015 24.1.1.4
|
||||
*
|
||||
* @return ecma_object_t *
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object_by_clone_arraybuffer (ecma_object_t *src_p, /**< the src arraybuffer */
|
||||
ecma_length_t offset) /**< the offset */
|
||||
{
|
||||
ecma_length_t length = ecma_arraybuffer_get_length (src_p);
|
||||
|
||||
JERRY_ASSERT (offset <= length);
|
||||
|
||||
ecma_length_t clone_length = length - offset;
|
||||
ecma_object_t *dst_p = ecma_arraybuffer_new_object (clone_length);
|
||||
lit_utf8_byte_t *src_buf = ecma_arraybuffer_get_buffer (src_p);
|
||||
lit_utf8_byte_t *dst_buf = ecma_arraybuffer_get_buffer (dst_p);
|
||||
memcpy (dst_buf, src_buf + offset, clone_length);
|
||||
|
||||
return dst_p;
|
||||
} /* ecma_arraybuffer_new_object_by_clone_arraybuffer */
|
||||
|
||||
/**
|
||||
* Helper function: check if the target is ArrayBuffer
|
||||
*
|
||||
*
|
||||
* See also: ES2015 24.1.1.4
|
||||
*
|
||||
* @return bool True if it is ArrayBuffer
|
||||
* Flase if it is not Object or it is not ArrayBuffer
|
||||
*/
|
||||
bool
|
||||
ecma_is_arraybuffer (ecma_value_t target) /**< the target value */
|
||||
{
|
||||
if (!ecma_is_value_object (target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (target);
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (obj_p);
|
||||
|
||||
return class_id == LIT_MAGIC_STRING_ARRAY_BUFFER_UL;
|
||||
} /* ecma_is_arraybuffer */
|
||||
|
||||
/**
|
||||
* Helper function: return the length of the buffer inside the arraybuffer object
|
||||
*
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#ifndef ECMA_ARRAYBUFFER_OBJECT_H
|
||||
#define ECMA_ARRAYBUFFER_OBJECT_H
|
||||
|
||||
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
@ -32,15 +33,20 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *, ecma_length_t);
|
||||
* Helper functions for arraybuffer.
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object (ecma_length_t);
|
||||
ecma_arraybuffer_new_object (ecma_length_t lengh);
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object_by_clone_arraybuffer (ecma_object_t *src_p, ecma_length_t offset);
|
||||
lit_utf8_byte_t *
|
||||
ecma_arraybuffer_get_buffer (ecma_object_t *) __attr_pure___;
|
||||
ecma_arraybuffer_get_buffer (ecma_object_t *obj_p) __attr_pure___;
|
||||
ecma_length_t
|
||||
ecma_arraybuffer_get_length (ecma_object_t *) __attr_pure___;
|
||||
ecma_arraybuffer_get_length (ecma_object_t *obj_p) __attr_pure___;
|
||||
bool
|
||||
ecma_is_arraybuffer (ecma_value_t val);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */
|
||||
#endif /* !ECMA_ARRAYBUFFER_OBJECT_H */
|
||||
|
||||
@ -80,13 +80,15 @@ ecma_op_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function
|
||||
|
||||
obj_p = ecma_create_object (prototype_p,
|
||||
sizeof (ecma_extended_object_t) + formal_params_size,
|
||||
ECMA_OBJECT_TYPE_ARGUMENTS);
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.arguments.lex_env_cp, lex_env_p);
|
||||
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_ARGUMENTS;
|
||||
|
||||
ext_object_p->u.arguments.length = formal_params_number;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.pseudo_array.u2.lex_env_cp, lex_env_p);
|
||||
|
||||
ext_object_p->u.pseudo_array.u1.length = (uint16_t) formal_params_number;
|
||||
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
@ -263,7 +265,7 @@ ecma_op_arguments_object_define_own_property (ecma_object_t *object_p, /**< the
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (index >= ext_object_p->u.arguments.length)
|
||||
if (index >= ext_object_p->u.pseudo_array.u1.length)
|
||||
{
|
||||
return ret_value;
|
||||
}
|
||||
@ -289,7 +291,7 @@ ecma_op_arguments_object_define_own_property (ecma_object_t *object_p, /**< the
|
||||
{
|
||||
/* emulating execution of function described by MakeArgSetter */
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.arguments.lex_env_cp);
|
||||
ext_object_p->u.pseudo_array.u2.lex_env_cp);
|
||||
|
||||
ecma_value_t completion = ecma_op_set_mutable_binding (lex_env_p,
|
||||
name_p,
|
||||
@ -343,7 +345,7 @@ ecma_op_arguments_object_delete (ecma_object_t *object_p, /**< the object */
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (index < ext_object_p->u.arguments.length)
|
||||
if (index < ext_object_p->u.pseudo_array.u1.length)
|
||||
{
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
|
||||
@ -155,7 +155,7 @@ ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
|
||||
/* 2. */
|
||||
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
@ -321,7 +321,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
|
||||
&ext_property_ref.property_ref,
|
||||
ECMA_PROPERTY_GET_VALUE | ECMA_PROPERTY_GET_EXT_REFERENCE);
|
||||
|
||||
if (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
if (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND || current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
/* 3. */
|
||||
if (!ecma_get_object_extensible (object_p))
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-objects.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
#include "ecma-typedarray-object.h"
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@ -52,7 +56,7 @@
|
||||
|| type == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION \
|
||||
|| type == ECMA_OBJECT_TYPE_ARRAY \
|
||||
|| type == ECMA_OBJECT_TYPE_BOUND_FUNCTION \
|
||||
|| type == ECMA_OBJECT_TYPE_ARGUMENTS);
|
||||
|| type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
#else /* JERRY_NDEBUG */
|
||||
#define JERRY_ASSERT_OBJECT_TYPE_IS_VALID(type)
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
@ -138,6 +142,41 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
/* ES2015 9.4.5.1 */
|
||||
if (ecma_is_typedarray (ecma_make_object_value (object_p)))
|
||||
{
|
||||
if (ECMA_STRING_GET_CONTAINER (property_name_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
ecma_value_t value = ecma_op_typedarray_get_index_prop (object_p, property_name_p->u.uint32_number);
|
||||
if (!ecma_is_value_undefined (value))
|
||||
{
|
||||
property_ref_p->virtual_value = value;
|
||||
|
||||
return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_TYPE_VIRTUAL;
|
||||
}
|
||||
|
||||
return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
|
||||
}
|
||||
|
||||
ecma_number_t num = ecma_string_to_number (property_name_p);
|
||||
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num);
|
||||
|
||||
if (ecma_compare_ecma_strings (property_name_p, num_to_str))
|
||||
{
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
|
||||
return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
default:
|
||||
{
|
||||
break;
|
||||
@ -192,36 +231,39 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
|
||||
return ECMA_PROPERTY_TYPE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else if (type == ECMA_OBJECT_TYPE_ARGUMENTS
|
||||
else if (type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY
|
||||
&& property_ref_p != NULL)
|
||||
{
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
|
||||
if (index < ext_object_p->u.arguments.length)
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
if (index < ext_object_p->u.pseudo_array.u1.length)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.arguments.lex_env_cp);
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.pseudo_array.u2.lex_env_cp);
|
||||
|
||||
ecma_value_t binding_value = ecma_op_get_binding_value (lex_env_p, arg_name_p, true);
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
ecma_named_data_property_assign_value (object_p,
|
||||
ECMA_PROPERTY_VALUE_PTR (property_p),
|
||||
binding_value);
|
||||
ecma_free_value (binding_value);
|
||||
ecma_value_t binding_value = ecma_op_get_binding_value (lex_env_p, arg_name_p, true);
|
||||
|
||||
ecma_named_data_property_assign_value (object_p,
|
||||
ECMA_PROPERTY_VALUE_PTR (property_p),
|
||||
binding_value);
|
||||
ecma_free_value (binding_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -265,12 +307,12 @@ ecma_op_object_get_property (ecma_object_t *object_p, /**< the object */
|
||||
property_ref_p,
|
||||
options);
|
||||
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
return property;
|
||||
}
|
||||
|
||||
if (--max_depth == 0)
|
||||
if (--max_depth == 0 || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -296,7 +338,8 @@ ecma_op_object_has_own_property (ecma_object_t *object_p, /**< the object */
|
||||
property_name_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
return property != ECMA_PROPERTY_TYPE_NOT_FOUND;
|
||||
|
||||
return property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP;
|
||||
} /* ecma_op_object_has_own_property */
|
||||
|
||||
/**
|
||||
@ -369,6 +412,7 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
@ -381,33 +425,59 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
|
||||
if (index < ext_object_p->u.arguments.length)
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
if (index < ext_object_p->u.pseudo_array.u1.length)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.arguments.lex_env_cp);
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.pseudo_array.u2.lex_env_cp);
|
||||
|
||||
return ecma_op_get_binding_value (lex_env_p, arg_name_p, true);
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
return ecma_op_get_binding_value (lex_env_p, arg_name_p, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
/* ES2015 9.4.5.4 */
|
||||
if (ecma_is_typedarray (ecma_make_object_value (object_p)))
|
||||
{
|
||||
if (ECMA_STRING_GET_CONTAINER (property_name_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
return ecma_op_typedarray_get_index_prop (object_p, property_name_p->u.uint32_number);
|
||||
}
|
||||
|
||||
ecma_number_t num = ecma_string_to_number (property_name_p);
|
||||
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num);
|
||||
|
||||
if (ecma_compare_ecma_strings (property_name_p, num_to_str))
|
||||
{
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -633,34 +703,66 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
|
||||
if (index < ext_object_p->u.arguments.length)
|
||||
if (index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
if (index < ext_object_p->u.pseudo_array.u1.length)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
|
||||
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.arguments.lex_env_cp);
|
||||
if (arg_Literal_p[index] != JMEM_CP_NULL)
|
||||
{
|
||||
ecma_string_t *arg_name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
arg_Literal_p[index]);
|
||||
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
|
||||
ext_object_p->u.pseudo_array.u2.lex_env_cp);
|
||||
|
||||
ecma_op_set_mutable_binding (lex_env_p, arg_name_p, value, true);
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
JERRY_ASSERT (lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
ecma_op_set_mutable_binding (lex_env_p, arg_name_p, value, true);
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
/* ES2015 9.4.5.5 */
|
||||
if (ecma_is_typedarray (ecma_make_object_value (object_p)))
|
||||
{
|
||||
if (ECMA_STRING_GET_CONTAINER (property_name_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
bool set_status = ecma_op_typedarray_set_index_prop (object_p, property_name_p->u.uint32_number, value);
|
||||
|
||||
if (set_status)
|
||||
{
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_number_t num = ecma_string_to_number (property_name_p);
|
||||
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num);
|
||||
|
||||
if (ecma_compare_ecma_strings (property_name_p, num_to_str))
|
||||
{
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -764,15 +866,20 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */
|
||||
{
|
||||
const ecma_object_type_t type = ecma_get_object_type (object_p);
|
||||
|
||||
if (type == ECMA_OBJECT_TYPE_ARGUMENTS)
|
||||
if (type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
|
||||
{
|
||||
return ecma_builtin_helper_def_prop (object_p,
|
||||
property_name_p,
|
||||
value,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
is_throw); /* Failure handling */
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
return ecma_builtin_helper_def_prop (object_p,
|
||||
property_name_p,
|
||||
value,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
is_throw); /* Failure handling */
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t index = ecma_string_get_array_index (property_name_p);
|
||||
@ -862,11 +969,24 @@ ecma_op_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
return ecma_op_arguments_object_delete (obj_p,
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
return ecma_op_arguments_object_delete (obj_p,
|
||||
property_name_p,
|
||||
is_throw);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_general_object_delete (obj_p,
|
||||
property_name_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
@ -905,7 +1025,7 @@ ecma_op_object_default_value (ecma_object_t *obj_p, /**< the object */
|
||||
* [ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_ARGUMENTS] = &ecma_op_general_object_default_value
|
||||
* [ECMA_OBJECT_TYPE_PSEUDO_ARRAY] = &ecma_op_general_object_default_value
|
||||
* };
|
||||
*
|
||||
* return default_value[type] (obj_p, property_name_p);
|
||||
@ -958,20 +1078,65 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
return ecma_op_arguments_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_ARGUMENTS)
|
||||
{
|
||||
return ecma_op_arguments_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
/* ES2015 9.4.5.3 */
|
||||
if (ecma_is_typedarray (ecma_make_object_value (obj_p)))
|
||||
{
|
||||
if (ECMA_STRING_GET_CONTAINER (property_name_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
bool define_status = ecma_op_typedarray_define_index_prop (obj_p,
|
||||
property_name_p->u.uint32_number,
|
||||
property_desc_p);
|
||||
|
||||
if (define_status)
|
||||
{
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_number_t num = ecma_string_to_number (property_name_p);
|
||||
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num);
|
||||
|
||||
if (ecma_compare_ecma_strings (property_name_p, num_to_str))
|
||||
{
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (num_to_str);
|
||||
}
|
||||
|
||||
return ecma_op_general_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
|
||||
return ecma_reject (is_throw);
|
||||
} /* ecma_op_object_define_own_property */
|
||||
|
||||
/**
|
||||
@ -999,7 +1164,7 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
|
||||
&property_ref,
|
||||
ECMA_PROPERTY_GET_VALUE);
|
||||
|
||||
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1071,7 +1236,7 @@ ecma_op_object_has_instance (ecma_object_t *obj_p, /**< the object */
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_CLASS:
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Expected a function object."));
|
||||
}
|
||||
@ -1178,10 +1343,19 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
if (ecma_is_typedarray (ecma_make_object_value (obj_p)))
|
||||
{
|
||||
ecma_op_typedarray_list_lazy_property_names (obj_p, prop_names_p);
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
{
|
||||
ecma_op_function_list_lazy_property_names (is_enumerable_only,
|
||||
@ -1200,6 +1374,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
|
||||
prop_names_p,
|
||||
skipped_non_enumerable_p);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
@ -1505,9 +1680,31 @@ ecma_object_get_class_name (ecma_object_t *obj_p) /**< object */
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
return ext_object_p->u.class_prop.class_id;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
|
||||
{
|
||||
return LIT_MAGIC_STRING_ARGUMENTS_UL;
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
switch (ext_obj_p->u.pseudo_array.type)
|
||||
{
|
||||
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
|
||||
{
|
||||
return LIT_MAGIC_STRING_ARGUMENTS_UL;
|
||||
}
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
|
||||
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
|
||||
{
|
||||
return ext_obj_p->u.pseudo_array.u1.class_id;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION:
|
||||
|
||||
700
jerry-core/ecma/operations/ecma-typedarray-object.c
Normal file
700
jerry-core/ecma/operations/ecma-typedarray-object.c
Normal file
@ -0,0 +1,700 @@
|
||||
/* 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-typedarray-object.h"
|
||||
#include "ecma-arraybuffer-object.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmatypedarrayobject ECMA %TypedArray% object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a TypedArray object by given array_length
|
||||
*
|
||||
* See also: ES2015 22.2.1.2.1
|
||||
*
|
||||
* @return pointer to the new typedarray object
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_typedarray_create_object_with_length (ecma_length_t array_length, /**< length of the typedarray */
|
||||
ecma_object_t *proto_p, /**< prototype object */
|
||||
uint8_t element_size_shift, /**< the size shift of the element length */
|
||||
lit_magic_string_id_t class_id) /**< class name of the typedarray */
|
||||
{
|
||||
ecma_length_t byte_length = array_length << element_size_shift;
|
||||
ecma_object_t *object_p = ecma_create_object (proto_p,
|
||||
sizeof (ecma_extended_object_t),
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_p->u.pseudo_array.u1.class_id = class_id;
|
||||
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_TYPEDARRAY;
|
||||
ext_object_p->u.pseudo_array.extra_info = element_size_shift;
|
||||
ext_object_p->u.pseudo_array.u2.arraybuffer = ecma_make_object_value (ecma_arraybuffer_new_object (byte_length));
|
||||
ecma_free_value (ext_object_p->u.pseudo_array.u2.arraybuffer);
|
||||
|
||||
return object_p;
|
||||
} /* !ecma_typedarray_create_object_with_length */
|
||||
|
||||
/**
|
||||
* Create a TypedArray object by given buffer, offset, and array_length
|
||||
*
|
||||
* See also: ES2015 22.2.1.5
|
||||
*
|
||||
* @return pointer to the new typedarray object
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_typedarray_create_object_with_buffer (ecma_object_t *arraybuffer_p,
|
||||
ecma_length_t byte_offset,
|
||||
ecma_length_t array_length, /**< length of the typedarray */
|
||||
ecma_object_t *proto_p, /**< prototype object */
|
||||
uint8_t element_size_shift, /**< the size shift of the element length */
|
||||
lit_magic_string_id_t class_id) /**< class name of the typedarray */
|
||||
{
|
||||
ecma_object_t *object_p;
|
||||
if (byte_offset == 0 && array_length == ecma_arraybuffer_get_length (arraybuffer_p) >> element_size_shift)
|
||||
{
|
||||
object_p = ecma_create_object (proto_p,
|
||||
sizeof (ecma_extended_object_t),
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_p->u.pseudo_array.u1.class_id = class_id;
|
||||
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_TYPEDARRAY;
|
||||
ext_object_p->u.pseudo_array.extra_info = element_size_shift;
|
||||
ext_object_p->u.pseudo_array.u2.arraybuffer = ecma_make_object_value (arraybuffer_p);
|
||||
|
||||
return object_p;
|
||||
}
|
||||
|
||||
object_p = ecma_create_object (proto_p,
|
||||
sizeof (ecma_extended_typedarray_object_t),
|
||||
ECMA_OBJECT_TYPE_PSEUDO_ARRAY);
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_p->u.pseudo_array.u1.class_id = class_id;
|
||||
ext_object_p->u.pseudo_array.type = ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO;
|
||||
ext_object_p->u.pseudo_array.extra_info = element_size_shift;
|
||||
ext_object_p->u.pseudo_array.u2.arraybuffer = ecma_make_object_value (arraybuffer_p);
|
||||
|
||||
ecma_extended_typedarray_object_t *typedarray_info_p = (ecma_extended_typedarray_object_t *) ext_object_p;
|
||||
typedarray_info_p->array_length = array_length;
|
||||
typedarray_info_p->byte_offset = byte_offset;
|
||||
|
||||
return object_p;
|
||||
} /* ecma_typedarray_create_object_with_buffer */
|
||||
|
||||
/**
|
||||
* Create a TypedArray object by given another TypedArray object
|
||||
*
|
||||
* See also: ES2015 22.2.1.3
|
||||
*
|
||||
* @return pointer to the new typedarray object
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_typedarray_create_object_with_typedarray (ecma_object_t *typedarray_p, /**< a typedarray object */
|
||||
ecma_object_t *proto_p, /**< prototype object */
|
||||
uint8_t element_size_shift, /**< the size shift of the element length */
|
||||
lit_magic_string_id_t class_id) /**< class name of the typedarray */
|
||||
{
|
||||
ecma_length_t array_length = ecma_typedarray_get_length (typedarray_p);
|
||||
ecma_length_t byte_offset = ecma_typedarray_get_offset (typedarray_p);
|
||||
ecma_object_t *src_arraybuffer_p = ecma_typedarray_get_arraybuffer (typedarray_p);
|
||||
lit_magic_string_id_t src_class_id = ecma_object_get_class_name (typedarray_p);
|
||||
ecma_object_t *arraybuffer_p = NULL;
|
||||
|
||||
if (src_class_id == class_id)
|
||||
{
|
||||
arraybuffer_p = ecma_arraybuffer_new_object_by_clone_arraybuffer (src_arraybuffer_p,
|
||||
byte_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** TODO: add other typed */
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_typedarray_create_object_with_buffer (arraybuffer_p,
|
||||
0,
|
||||
array_length,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id);
|
||||
|
||||
ecma_deref_object (arraybuffer_p);
|
||||
|
||||
return object_p;
|
||||
} /* ecma_typedarray_create_object_with_typedarray */
|
||||
|
||||
/**
|
||||
* Create a TypedArray object by transforming from an array-like object
|
||||
*
|
||||
* See also: ES2015 22.2.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_typedarray_from (ecma_value_t items_val, /**< the source array-like object */
|
||||
ecma_value_t map_fn_val, /**< map function */
|
||||
ecma_value_t this_val, /** this_arg for the above map function */
|
||||
ecma_object_t *proto_p, /**< prototype object */
|
||||
uint8_t element_size_shift, /**< the size shift of the element length */
|
||||
lit_magic_string_id_t class_id) /**< class name of the typedarray */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 3 */
|
||||
JERRY_ASSERT (ecma_op_is_callable (map_fn_val) || ecma_is_value_undefined (map_fn_val));
|
||||
|
||||
ecma_object_t *func_object_p = NULL;
|
||||
if (!ecma_is_value_undefined (map_fn_val))
|
||||
{
|
||||
func_object_p = ecma_get_object_from_value (map_fn_val);
|
||||
}
|
||||
|
||||
/* 10 */
|
||||
ECMA_TRY_CATCH (arraylike_val,
|
||||
ecma_op_to_object (items_val),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *arraylike_p = ecma_get_object_from_value (arraylike_val);
|
||||
|
||||
/* 12 */
|
||||
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
|
||||
ECMA_TRY_CATCH (len_value,
|
||||
ecma_op_object_get (arraylike_p, magic_string_length_p),
|
||||
ret_value);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (len_number, len_value, ret_value);
|
||||
|
||||
uint32_t len = ecma_number_to_uint32 (len_number);
|
||||
|
||||
/* 14 */
|
||||
ecma_object_t *new_typedarray_p = ecma_typedarray_create_object_with_length (len,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id);
|
||||
|
||||
/* 17 */
|
||||
ecma_value_t current_index;
|
||||
|
||||
for (uint32_t index = 0; index < len && ecma_is_value_empty (ret_value); index++)
|
||||
{
|
||||
/* 17.a */
|
||||
ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
/* 17.b */
|
||||
ECMA_TRY_CATCH (current_value, ecma_op_object_find (arraylike_p, index_str_p), ret_value);
|
||||
|
||||
if (ecma_is_value_found (current_value))
|
||||
{
|
||||
if (func_object_p != NULL)
|
||||
{
|
||||
/* 17.d 17.f*/
|
||||
current_index = ecma_make_uint32_value (index);
|
||||
ecma_value_t call_args[] = { current_value, current_index};
|
||||
|
||||
ECMA_TRY_CATCH (mapped_value, ecma_op_function_call (func_object_p, this_val, call_args, 2), ret_value);
|
||||
|
||||
bool set_status = ecma_op_typedarray_set_index_prop (new_typedarray_p, index, mapped_value);
|
||||
|
||||
if (!set_status)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (mapped_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 17.e 17.f */
|
||||
bool set_status = ecma_op_typedarray_set_index_prop (new_typedarray_p, index, current_value);
|
||||
|
||||
if (!set_status)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (current_value);
|
||||
|
||||
ecma_deref_ecma_string (index_str_p);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_object_value (new_typedarray_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_deref_object (new_typedarray_p);
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (len_number);
|
||||
ECMA_FINALIZE (len_value);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
ECMA_FINALIZE (arraylike_val);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_typedarray_from */
|
||||
|
||||
/**
|
||||
* Get the array length of the typedarray object
|
||||
*
|
||||
* @return the pointer to the internal arraybuffer
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_typedarray_get_arraybuffer (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (typedarray_p)));
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p;
|
||||
|
||||
return ecma_get_object_from_value (ext_object_p->u.pseudo_array.u2.arraybuffer);
|
||||
} /* ecma_typedarray_get_arraybuffer */
|
||||
|
||||
/**
|
||||
* Get the element size shift in the typedarray object
|
||||
*
|
||||
* @return the size shift of the element, size is 1 << shift
|
||||
*/
|
||||
uint8_t
|
||||
ecma_typedarray_get_element_size_shift (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (typedarray_p)));
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p;
|
||||
|
||||
return ext_object_p->u.pseudo_array.extra_info;
|
||||
} /* ecma_typedarray_get_element_size_shift */
|
||||
|
||||
|
||||
/**
|
||||
* Get the array length of the typedarray object
|
||||
*
|
||||
* @return the array length
|
||||
*/
|
||||
ecma_length_t
|
||||
ecma_typedarray_get_length (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (typedarray_p)));
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p;
|
||||
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_TYPEDARRAY)
|
||||
{
|
||||
ecma_object_t *arraybuffer_p = ecma_get_object_from_value (ext_object_p->u.pseudo_array.u2.arraybuffer);
|
||||
ecma_length_t buffer_length = ecma_arraybuffer_get_length (arraybuffer_p);
|
||||
uint8_t shift = ext_object_p->u.pseudo_array.extra_info;
|
||||
|
||||
return buffer_length >> shift;
|
||||
}
|
||||
|
||||
ecma_extended_typedarray_object_t *info_p = (ecma_extended_typedarray_object_t *) ext_object_p;
|
||||
|
||||
return info_p->array_length;
|
||||
} /* ecma_typedarray_get_length */
|
||||
|
||||
/**
|
||||
* Get the offset of the internal arraybuffer
|
||||
*
|
||||
* @return the offset
|
||||
*/
|
||||
ecma_length_t
|
||||
ecma_typedarray_get_offset (ecma_object_t *typedarray_p) /**< the pointer to the typedarray object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (typedarray_p)));
|
||||
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) typedarray_p;
|
||||
|
||||
if (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_TYPEDARRAY)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ecma_extended_typedarray_object_t *info_p = (ecma_extended_typedarray_object_t *) ext_object_p;
|
||||
|
||||
return info_p->byte_offset;
|
||||
} /* ecma_typedarray_get_offset */
|
||||
|
||||
|
||||
/**
|
||||
* Create a new typedarray object.
|
||||
*
|
||||
* The struct of the typedarray object
|
||||
* ecma_object_t
|
||||
* extend_part
|
||||
* typedarray_info
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg list passed to typedarray construct */
|
||||
ecma_length_t arguments_list_len, /**< the length of the arguments_list_p */
|
||||
ecma_object_t *proto_p, /**< prototype object */
|
||||
uint8_t element_size_shift, /**< the size shift of the element length */
|
||||
lit_magic_string_id_t class_id) /**< class name of the typedarray */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
/* 22.2.1.1 */
|
||||
ret = ecma_make_object_value (ecma_typedarray_create_object_with_length (0, proto_p, element_size_shift, class_id));
|
||||
}
|
||||
else if (!ecma_is_value_object (arguments_list_p[0]))
|
||||
{
|
||||
/* 22.2.1.2 */
|
||||
if (ecma_is_value_undefined (arguments_list_p[0]))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("length argument is undefined"));
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (num, arguments_list_p[0], ret);
|
||||
|
||||
uint32_t length = ecma_number_to_uint32 (num);
|
||||
|
||||
if (num != ((ecma_number_t) length))
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid typedarray length."));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ecma_make_object_value (ecma_typedarray_create_object_with_length (length,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id));
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (num);
|
||||
}
|
||||
else if (ecma_is_value_object (arguments_list_p[0]))
|
||||
{
|
||||
if (ecma_is_typedarray (arguments_list_p[0]))
|
||||
{
|
||||
/* 22.2.1.3 */
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (arguments_list_p[0]);
|
||||
ret = ecma_make_object_value (ecma_typedarray_create_object_with_typedarray (typedarray_p,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id));
|
||||
}
|
||||
else if (ecma_is_arraybuffer (arguments_list_p[0]))
|
||||
{
|
||||
/* 22.2.1.5 */
|
||||
ecma_object_t *arraybuffer_p = ecma_get_object_from_value (arguments_list_p[0]);
|
||||
ecma_value_t arg2 = ((arguments_list_len > 1) ? arguments_list_p[1]
|
||||
: ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
|
||||
|
||||
ecma_value_t arg3 = ((arguments_list_len > 2) ? arguments_list_p[2]
|
||||
: ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (num2, arg2, ret);
|
||||
|
||||
uint32_t offset = ecma_number_to_uint32 (num2);
|
||||
|
||||
if (ecma_number_is_negative (ecma_number_to_int32 (num2)) || (offset % (uint32_t) (1 << element_size_shift) != 0))
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid offset."));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_length_t buf_byte_length = ecma_arraybuffer_get_length (arraybuffer_p);
|
||||
ecma_length_t new_byte_length = 0;
|
||||
|
||||
if (ecma_is_value_undefined (arg3))
|
||||
{
|
||||
if (buf_byte_length % (uint32_t) (1 << element_size_shift) != 0)
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid length."));
|
||||
}
|
||||
else if (buf_byte_length < offset)
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid length."));
|
||||
}
|
||||
else
|
||||
{
|
||||
new_byte_length = (ecma_length_t) (buf_byte_length - offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (num3, arg3, ret);
|
||||
int32_t new_length = ecma_number_to_int32 (num3);
|
||||
new_length = (new_length > 0) ? new_length : 0;
|
||||
new_byte_length = (ecma_length_t) new_length << element_size_shift;
|
||||
|
||||
if (new_byte_length + offset > buf_byte_length)
|
||||
{
|
||||
ret = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid length."));
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (num3);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret))
|
||||
{
|
||||
ecma_length_t array_length = new_byte_length >> element_size_shift;
|
||||
ret = ecma_make_object_value (ecma_typedarray_create_object_with_buffer (arraybuffer_p,
|
||||
offset,
|
||||
array_length,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id));
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (num2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 22.2.1.4 */
|
||||
ecma_value_t undef_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ret = ecma_op_typedarray_from (arguments_list_p[0],
|
||||
undef_val,
|
||||
undef_val,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
} /* ecma_op_create_typedarray */
|
||||
|
||||
/**
|
||||
* Check if the value is typedarray
|
||||
*
|
||||
* @return True: it is a typedarray object
|
||||
* False: it is not object or it is not a typedarray
|
||||
*/
|
||||
bool
|
||||
ecma_is_typedarray (ecma_value_t target) /**< the target need to be checked */
|
||||
{
|
||||
if (!ecma_is_value_object (target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (target);
|
||||
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
return ((ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_TYPEDARRAY)
|
||||
|| (ext_object_p->u.pseudo_array.type == ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO));
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_is_typedarray */
|
||||
|
||||
/**
|
||||
* List names of a TypedArray object's integer indexed properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void
|
||||
ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedArray object */
|
||||
ecma_collection_header_t *main_collection_p) /**< 'main'
|
||||
* collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (obj_p)));
|
||||
|
||||
ecma_length_t array_length = ecma_typedarray_get_length (obj_p);
|
||||
|
||||
for (ecma_length_t i = 0; i < array_length; i++)
|
||||
{
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_uint32 (i);
|
||||
|
||||
ecma_append_to_values_collection (main_collection_p, ecma_make_string_value (name_p), true);
|
||||
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
} /* ecma_op_typedarray_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
* Get the integer number property value of the typedarray
|
||||
*
|
||||
* See also: ES2015 9.4.5.8
|
||||
*
|
||||
* @return ecma value
|
||||
* if failed, return undefined value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_typedarray_get_index_prop (ecma_object_t *obj_p, /**< a TypedArray object */
|
||||
uint32_t index) /**< the index number */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (obj_p)));
|
||||
|
||||
ecma_length_t array_length = ecma_typedarray_get_length (obj_p);
|
||||
|
||||
if (index >= array_length)
|
||||
{
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (obj_p);
|
||||
ecma_length_t offset = ecma_typedarray_get_offset (obj_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (obj_p);
|
||||
ecma_length_t byte_pos = (index << shift) + offset;
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (obj_p);
|
||||
lit_utf8_byte_t *target_p = ecma_arraybuffer_get_buffer (arraybuffer_p) + byte_pos;
|
||||
ecma_value_t value;
|
||||
|
||||
switch (class_id)
|
||||
{
|
||||
case LIT_MAGIC_STRING_INT8_ARRAY_UL:
|
||||
{
|
||||
int8_t v = *((int8_t *) target_p);
|
||||
value = ecma_make_number_value ((ecma_number_t) v);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
/** TODO: implement other types */
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
} /* ecma_op_typedarray_get_index_prop */
|
||||
|
||||
/**
|
||||
* Define the integer number property value of the typedarray
|
||||
*
|
||||
* See also: ES2015 9.4.5.3: 3.c
|
||||
*
|
||||
* @return boolean, false if failed
|
||||
*/
|
||||
bool
|
||||
ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p, /**< a TypedArray object */
|
||||
uint32_t index, /**< the index number */
|
||||
const ecma_property_descriptor_t *property_desc_p) /**< the description of
|
||||
the prop */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (obj_p)));
|
||||
|
||||
ecma_length_t array_length = ecma_typedarray_get_length (obj_p);
|
||||
|
||||
if (index >= array_length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (property_desc_p->is_get_defined
|
||||
|| property_desc_p->is_set_defined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((property_desc_p->is_configurable_defined && property_desc_p->is_configurable)
|
||||
|| (property_desc_p->is_enumerable_defined && !property_desc_p->is_enumerable)
|
||||
|| (property_desc_p->is_writable_defined && !property_desc_p->is_writable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (property_desc_p->is_value_defined)
|
||||
{
|
||||
return ecma_op_typedarray_set_index_prop (obj_p, index, property_desc_p->value);
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* ecma_op_typedarray_define_index_prop */
|
||||
|
||||
/**
|
||||
* Set the integer number property value of the typedarray
|
||||
*
|
||||
* See also: ES2015 9.4.5.9
|
||||
*
|
||||
* @return boolean, false if failed
|
||||
*/
|
||||
bool
|
||||
ecma_op_typedarray_set_index_prop (ecma_object_t *obj_p,/**< a TypedArray object */
|
||||
uint32_t index, /**< the index number */
|
||||
ecma_value_t value) /**< value of the property */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_typedarray (ecma_make_object_value (obj_p)));
|
||||
|
||||
ecma_value_t error_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (value_num, value, error_val);
|
||||
|
||||
ecma_length_t array_length = ecma_typedarray_get_length (obj_p);
|
||||
|
||||
if (index >= array_length)
|
||||
{
|
||||
error_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *arraybuffer_p = ecma_typedarray_get_arraybuffer (obj_p);
|
||||
ecma_length_t offset = ecma_typedarray_get_offset (obj_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (obj_p);
|
||||
ecma_length_t byte_pos = (index << shift) + offset;
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (obj_p);
|
||||
lit_utf8_byte_t *target_p = ecma_arraybuffer_get_buffer (arraybuffer_p) + byte_pos;
|
||||
|
||||
switch (class_id)
|
||||
{
|
||||
case LIT_MAGIC_STRING_INT8_ARRAY_UL:
|
||||
{
|
||||
*((int8_t *) target_p) = (int8_t) value_num;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
/** TODO: implement other types */
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (value_num);
|
||||
|
||||
if (ecma_is_value_empty (error_val))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_op_typedarray_set_index_prop */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
60
jerry-core/ecma/operations/ecma-typedarray-object.h
Normal file
60
jerry-core/ecma/operations/ecma-typedarray-object.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_TYPEDARRAY_OBJECT_H
|
||||
#define ECMA_TYPEDARRAY_OBJECT_H
|
||||
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmatypedarrayobject ECMA typedArray object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
ecma_value_t ecma_op_typedarray_from (ecma_value_t items_val,
|
||||
ecma_value_t map_fn_val,
|
||||
ecma_value_t this_val,
|
||||
ecma_object_t *proto_p,
|
||||
uint8_t element_size_shift,
|
||||
lit_magic_string_id_t class_id);
|
||||
ecma_length_t ecma_typedarray_get_length (ecma_object_t *typedarray_p);
|
||||
ecma_length_t ecma_typedarray_get_offset (ecma_object_t *typedarray_p);
|
||||
uint8_t ecma_typedarray_get_element_size_shift (ecma_object_t *typedarray_p);
|
||||
ecma_object_t *ecma_typedarray_get_arraybuffer (ecma_object_t *typedarray_p);
|
||||
ecma_value_t ecma_op_create_typedarray (const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len,
|
||||
ecma_object_t *proto_p,
|
||||
uint8_t element_size_shift,
|
||||
lit_magic_string_id_t class_id);
|
||||
bool ecma_is_typedarray (ecma_value_t target);
|
||||
void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p,
|
||||
ecma_collection_header_t *main_collection_p);
|
||||
ecma_value_t ecma_op_typedarray_get_index_prop (ecma_object_t *obj_p, uint32_t index);
|
||||
bool ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p,
|
||||
uint32_t index,
|
||||
const ecma_property_descriptor_t *property_desc_p);
|
||||
bool ecma_op_typedarray_set_index_prop (ecma_object_t *obj_p, uint32_t index, ecma_value_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
|
||||
#endif /* !ECMA_TYPEDARRAY_OBJECT_H */
|
||||
@ -47,6 +47,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LEFT_BRACE_CHAR, "{")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RIGHT_BRACE_CHAR, "}")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (2, LIT_MAGIC_STRING_PI_U)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PI_U, "PI")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OF, "of")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (3, LIT_MAGIC_STRING_LN2_U)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LN2_U, "LN2")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NAN, "NaN")
|
||||
@ -80,6 +81,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALL, "call")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CEIL, "ceil")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EVAL, "eval")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EXEC, "exec")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROM, "from")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_JOIN, "join")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_KEYS, "keys")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NAME, "name")
|
||||
@ -121,6 +123,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT_UL, "Object")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REGEXP_UL, "RegExp")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_REGEXP_SOURCE_UL, "Source")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRING_UL, "String")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BUFFER, "buffer")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALLEE, "callee")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CALLER, "caller")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CHAR_AT_UL, "charAt")
|
||||
@ -183,6 +186,7 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (9, LIT_MAGIC_STRING_NEGATIVE_INFINITY_U
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEGATIVE_INFINITY_UL, "-Infinity")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARGUMENTS_UL, "Arguments")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_EVAL_ERROR_UL, "EvalError")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT8_ARRAY_UL, "Int8Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MAX_VALUE_U, "MAX_VALUE")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_MIN_VALUE_U, "MIN_VALUE")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TYPE_ERROR_UL, "TypeError")
|
||||
@ -197,9 +201,14 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PROTOTYPE, "prototype")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STRINGIFY, "stringify")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBSTRING, "substring")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNDEFINED, "undefined")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_RANGE_ERROR_UL)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_INT16_ARRAY_UL)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT16_ARRAY_UL, "Int16Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INT32_ARRAY_UL, "Int32Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RANGE_ERROR_UL, "RangeError")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT8_ARRAY_UL, "Uint8Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TYPED_ARRAY_UL, "TypedArray")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTE_LENGTH_UL, "byteLength")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTE_OFFSET_UL, "byteOffset")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CHAR_CODE_AT_UL, "charCodeAt")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENUMERABLE, "enumerable")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MINUTES_UL, "getMinutes")
|
||||
@ -213,6 +222,8 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_ARRAY_BUFFER_UL)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, "ArrayBuffer")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYNTAX_ERROR_UL, "SyntaxError")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT16_ARRAY_UL, "Uint16Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT32_ARRAY_UL, "Uint32Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONSTRUCTOR, "constructor")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, "getFullYear")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, "getUTCHours")
|
||||
@ -228,7 +239,9 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOWER_CASE_UL, "toLowerCase")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_PRECISION_UL, "toPrecision")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_UTC_STRING_UL, "toUTCString")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_UPPER_CASE_UL, "toUpperCase")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_INVALID_DATE_UL)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (12, LIT_MAGIC_STRING_FLOAT32_ARRAY_UL)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL, "Float32Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL, "Float64Array")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_INVALID_DATE_UL, "Invalid Date")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONFIGURABLE, "configurable")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, "fromCharCode")
|
||||
@ -256,9 +269,11 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, "getMilliseconds")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, "setMilliseconds")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (16, LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, "defineProperties")
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_NEGATIVE_INFINITY_U)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U, "BYTES_PER_ELEMENT")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U, "NEGATIVE_INFINITY")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_POSITIVE_INFINITY_U, "POSITIVE_INFINITY")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, "Uint8ClampedArray")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, "getTimezoneOffset")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, "preventExtensions")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, "toLocaleLowerCase")
|
||||
|
||||
@ -1 +1,3 @@
|
||||
CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
|
||||
CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
|
||||
@ -9,3 +9,5 @@ CONFIG_DISABLE_MATH_BUILTIN
|
||||
CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
CONFIG_DISABLE_STRING_BUILTIN
|
||||
CONFIG_DISABLE_TYPEDARRAY_BUILTIN
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array();
|
||||
assert(a instanceof Int8Array);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a instanceof Int8Array);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array('5');
|
||||
assert(a instanceof Int8Array);
|
||||
@ -0,0 +1,18 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
var b = new Int8Array(a);
|
||||
assert(a instanceof Int8Array);
|
||||
@ -0,0 +1,18 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new ArrayBuffer(5);
|
||||
var b = new Int8Array(a);
|
||||
assert(b instanceof Int8Array);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array([1,2,3]);
|
||||
assert(a instanceof Int8Array);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a[2] === 0);
|
||||
@ -0,0 +1,18 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array([1.5,1000,-9]);
|
||||
a[2] = a[1] * a[0]; //a[0] = 1; a[1] = -24 (because 1000 is 0x3e8, convert to int8 is 0xe8)
|
||||
assert(a[2] === -24);
|
||||
@ -0,0 +1,18 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
Int8Array.prototype[10] = 10;
|
||||
var a = new Int8Array(5);
|
||||
assert(a[10] === undefined); //Indexed properties will never look at prototype
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = Object.getPrototypeOf(Int8Array);
|
||||
assert(a.name === "TypedArray");
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = Object.getPrototypeOf(Int8Array);
|
||||
assert(a.length === 3);
|
||||
@ -0,0 +1,19 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = Object.getPrototypeOf(Int8Array);
|
||||
var b = new Int8Array();
|
||||
var c = Object.getPrototypeOf(Object.getPrototypeOf(b));
|
||||
assert(c === a.prototype);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a.length === 5);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a.byteOffset === 0);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a.byteLength === 5);
|
||||
@ -0,0 +1,17 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array(5);
|
||||
assert(a.buffer instanceof ArrayBuffer);
|
||||
@ -0,0 +1,22 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array([1,2,3,4,5]);
|
||||
var b = new Int8Array(a.buffer, 2, 3);
|
||||
|
||||
assert(a.buffer === b.buffer);
|
||||
assert(b.length === 3);
|
||||
assert(b.byteOffset === 2);
|
||||
assert(b.byteLength === 3);
|
||||
@ -0,0 +1,20 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
var a = new Int8Array([1,2,3,4,5]);
|
||||
var b = new Int8Array(a.buffer, 2, 3);
|
||||
|
||||
b[0] = 5.6;
|
||||
assert(a[2] === 5);
|
||||
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
assert(Int8Array.BYTES_PER_ELEMENT === 1);
|
||||
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
assert(Int8Array.prototype.BYTES_PER_ELEMENT === 1);
|
||||
Loading…
x
Reference in New Issue
Block a user