Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 67 additions & 15 deletions jerry-core/ecma/base/ecma-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 ();
Copy link
Member

Choose a reason for hiding this comment

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

I think we add breaks to unreachable cases as well.

break;
}
}

ecma_gc_set_object_visited (lex_env_p, true);
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
Expand Down Expand Up @@ -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_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_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
ecma_deref_ecma_string (name_p);
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)
Expand Down
70 changes: 60 additions & 10 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
{
Expand All @@ -498,7 +509,7 @@ typedef enum
} ecma_property_get_option_bits_t;

/**
* Internal object types
* Internal object types.
*/
typedef enum
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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 */
/**
* @}
* @}
Expand Down
5 changes: 5 additions & 0 deletions jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */

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

#include "ecma-builtins.h"

#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN

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

#define BUILTIN_INC_HEADER_NAME "ecma-builtin-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 */
Original file line number Diff line number Diff line change
@@ -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
Loading